Commit c91f472c authored by Thomas Vincent's avatar Thomas Vincent

fallback backgrouhd when opening older files +

move BackgroundTypes to io.FitH5
parent 41f63f6e
......@@ -40,7 +40,8 @@ from ..widgets.Containers import GroupBox
from ..widgets.RoiAxisWidget import RoiAxisWidget
from ..widgets.Input import StyledLineEdit
from ...process.fit.peak_fit import PeakFitter, FitTypes, BackgroundTypes
from ...process.fit.peak_fit import PeakFitter, FitTypes
from ...io.FitH5 import BackgroundTypes
_logger = logging.getLogger(__name__)
......
......@@ -40,6 +40,21 @@ from ..util import text_type
FitResult = namedtuple('FitResult', ['name', 'qx', 'qy', 'qz'])
class BackgroundTypes(object):
"""Enum of background subtraction types:
- NONE: No background
- CONSTANT: Remove constant (= min of the data) background
- LINEAR: Remove linear background using line from first to last data
- SNIP: Statistics-sensitive Non-linear Iterative Peak-clipping algorithm
"""
NONE = "None"
CONSTANT = "Constant"
LINEAR = "Linear"
SNIP = "Snip"
ALLOWED = NONE, CONSTANT, LINEAR, SNIP
class FitH5QAxis(object):
axis_values = range(3)
qx_axis, qy_axis, qz_axis = axis_values
......@@ -301,8 +316,9 @@ class FitH5(XsocsH5Base):
:param str entry: HDF5 entry name for which to retrieve information
:rtype: str
"""
return self._get_array_data(
mode = self._get_array_data(
self._BACKGROUND_MODE_PATH.format(entry=entry))
return mode if mode is not None else BackgroundTypes.NONE
def export_csv(self, entry, filename):
"""
......@@ -448,6 +464,7 @@ class FitH5Writer(FitH5):
:param str entry: HDF5 entry name for which to retrieve information
:param str mode: Background mode description
"""
assert mode in BackgroundTypes.ALLOWED
self._create_dataset(
self._BACKGROUND_MODE_PATH.format(entry=entry),
data=text_type(mode))
......@@ -41,6 +41,7 @@ import numpy as np
# from silx.math import curve_fit
from ... import config
from ...io import QSpaceH5
from ...io.FitH5 import BackgroundTypes
from ...fit import (GaussianFitter, GaussianResults,
CentroidFitter, CentroidResults,
SilxFitter, SilxResults)
......@@ -49,19 +50,6 @@ from .sharedresults import FitTypes
disp_times = False
class BackgroundTypes(object):
"""Enum of background subtraction types:
- NONE: No background
- CONSTANT: Remove constant (= min of the data) background
- LINEAR: Remove linear background using line from first to last data
"""
NONE = "None"
CONSTANT = "Constant"
LINEAR = "Linear"
ALLOWED = NONE, CONSTANT, LINEAR
def background_estimation(mode, data):
"""Estimates a background of mode kind for data
......@@ -480,9 +468,10 @@ def _fit_process(th_idx, roiIndices=None):
y_sum = cube_sum_z.sum(axis=0)
x_sum = cube_sum_z.sum(axis=1)
# Background subtraction
for array in (z_sum, y_sum, x_sum):
array -= background_estimation(fit_background, array)
if fit_background != BackgroundTypes.None:
# 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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment