Commit a876a057 authored by Thomas Vincent's avatar Thomas Vincent

add/update docstring

parent 39a14251
......@@ -22,6 +22,10 @@
# THE SOFTWARE.
#
# ###########################################################################*/
"""Fit/Center-of-Mass QSpace reduction processing
The class :class:`PeakFit` implements it with multiprocessing
"""
__authors__ = ["D. Naudet"]
__license__ = "MIT"
......
......@@ -48,44 +48,21 @@ from ...util import gaussian, project
_logger = logging.getLogger(__name__)
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 numpy.ones_like(data) * numpy.nanmin(data)
elif mode == BackgroundTypes.LINEAR:
# Simple linear background
return numpy.linspace(data[0], data[-1], num=len(data), endpoint=True)
elif mode == BackgroundTypes.SNIP:
# Using snip background
return snip1d(data, snip_width=len(data))
elif mode == BackgroundTypes.NONE:
return numpy.zeros_like(data)
class FitTypes(object):
"""Kind of fit available"""
else:
raise ValueError("Unsupported background mode")
GAUSSIAN = 0
"""1 gaussian fit"""
CENTROID = 1
"""Center of mass and max"""
class FitTypes(object):
"""Kind of fit available"""
ALLOWED = range(2)
GAUSSIAN, CENTROID = ALLOWED
ALLOWED = GAUSSIAN, CENTROID
class FitStatus(object):
"""
Enum for the fit status
"""Enum for the fit status
Starting at 1 for compatibility reasons.
"""
UNKNOWN, OK, FAILED = range(0, 3)
......@@ -94,7 +71,7 @@ class FitStatus(object):
class FitResult(object):
"""Object storing fit/com results
It also allows to save as hdf5.
It also allows to save as hdf5 with :meth:`to_fit_h5`.
:param numpy.ndarray sample_x: N X sample position of the results
:param numpy.ndarray sample_y: N Y sample position of the results
......@@ -219,6 +196,7 @@ class PeakFitter(object):
:param BackgroundTypes background: The background subtraction to perform
"""
# Different status values
READY, RUNNING, DONE, ERROR, CANCELED = __STATUSES = range(5)
def __init__(self,
......@@ -267,17 +245,25 @@ class PeakFitter(object):
self.__indices = numpy.array(indices, copy=True)
def __set_status(self, status):
"""Set the status of the processing
:param int status:
"""
assert status in self.__STATUSES
self.__status = status
status = property(lambda self: self.__status)
status = property(lambda self: self.__status,
doc="Status of the fit/COM process (int)")
results = property(lambda self: self.__results)
results = property(lambda self: self.__results,
doc="The result of the fit/COM (FitResult or None)")
def peak_fit(self):
"""Blocking execution of fit/com processing.
It returns the fit/com result
:rtype: FitResult
"""
for _ in self.__peak_fit():
pass
......@@ -292,6 +278,7 @@ class PeakFitter(object):
yield progress / len(self.__indices)
def __peak_fit(self):
"""Run the fit/COM processing and set result and status"""
self.__results = None
self.__set_status(self.RUNNING)
......@@ -350,6 +337,8 @@ class PeakFitter(object):
self.__set_status(self.DONE)
# Fit/COM function run through multiprocessing
# Per process cache for fit process
_per_process_cache = None
......@@ -486,3 +475,34 @@ def gaussian_fit(axis, signal):
else:
area, center, sigma = result[0]
return float(area), float(center), float(sigma), True
# background
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 numpy.ones_like(data) * numpy.nanmin(data)
elif mode == BackgroundTypes.LINEAR:
# Simple linear background
return numpy.linspace(data[0], data[-1], num=len(data), endpoint=True)
elif mode == BackgroundTypes.SNIP:
# Using snip background
return snip1d(data, snip_width=len(data))
elif mode == BackgroundTypes.NONE:
return numpy.zeros_like(data)
else:
raise ValueError("Unsupported background mode")
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