Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xsocs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kmap
xsocs
Commits
653674b2
Commit
653674b2
authored
Nov 12, 2018
by
Thomas Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make a background_estimation method
parent
9138f3a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
13 deletions
+27
-13
xsocs/process/fit/peak_fit.py
xsocs/process/fit/peak_fit.py
+27
-13
No files found.
xsocs/process/fit/peak_fit.py
View file @
653674b2
...
...
@@ -62,6 +62,31 @@ class BackgroundTypes(object):
ALLOWED
=
NONE
,
CONSTANT
,
LINEAR
def
background_estimation
(
mode
,
data
):
"""Estimates a background of mode kind for data
:param BackgroundTypes mode: The kind of background to compute
:param numpy.ndarray data: The data array to process
:return: The estimated background as an array with same shape as input
:rtype: numpy.ndarray
:raises ValueError: In case mode is not known
"""
# Background subtraction
if
mode
==
BackgroundTypes
.
CONSTANT
:
# Shift data so that smallest value is 0
return
np
.
ones_like
(
data
)
*
np
.
nanmin
(
data
)
elif
mode
==
BackgroundTypes
.
LINEAR
:
# Simple linear background
return
np
.
linspace
(
data
[
0
],
data
[
-
1
],
num
=
len
(
data
),
endpoint
=
True
)
elif
mode
==
BackgroundTypes
.
NONE
:
return
np
.
zeros_like
(
data
)
else
:
raise
ValueError
(
"Unsupported background mode"
)
class
PeakFitter
(
Thread
):
"""
:param str qspace_f: path to the HDF5 file containing the qspace cubes
...
...
@@ -456,19 +481,8 @@ def _fit_process(th_idx, roiIndices=None):
x_sum
=
cube_sum_z
.
sum
(
axis
=
1
)
# Background subtraction
if
fit_background
==
BackgroundTypes
.
CONSTANT
:
# Shift data so that smallest value is 0
for
array
in
(
z_sum
,
y_sum
,
x_sum
):
array
-=
np
.
nanmin
(
array
)
elif
fit_background
==
BackgroundTypes
.
LINEAR
:
# Simple linear background
for
array
in
(
z_sum
,
y_sum
,
x_sum
):
array
-=
np
.
linspace
(
array
[
0
],
array
[
-
1
],
num
=
len
(
array
),
endpoint
=
True
)
elif
fit_background
!=
BackgroundTypes
.
NONE
:
raise
RuntimeError
(
"Unsupported background subtraction"
)
for
array
in
(
z_sum
,
y_sum
,
x_sum
):
array
-=
background_estimation
(
fit_background
,
array
)
fitter
.
fit
(
i_fit
,
i_cube
,
x_sum
,
y_sum
,
z_sum
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment