Commit 5dfeeea0 authored by Thomas Vincent's avatar Thomas Vincent

display fitted gaussian + background

parent e037f994
......@@ -299,20 +299,23 @@ class FitView(Qt.QMainWindow):
plot.setGraphTitle('{0} ({1})'.format(title, name))
plot.addCurve(xAcq, yAcq, legend='measured', color='blue')
background = None
if backgroundMode != BackgroundTypes.NONE: # Display background
indices = np.nonzero(np.in1d(xAcq, xFit, assume_unique=True))[0]
if len(indices) != len(xFit):
_logger.error(
"Cannot retrieve ROI: cannot display background")
else:
background = background_estimation(backgroundMode,
yAcq[indices])
plot.addCurve(
xFit,
background_estimation(backgroundMode, yAcq[indices]),
background,
legend='background',
linestyle=':',
color='black')
plotter.plotFit(plot, xFit, peakParams)
plotter.plotFit(plot, xFit, peakParams, background)
def _initGaussian(plots, fitH5Name, entry, process):
......
......@@ -39,12 +39,14 @@ from ....util import gaussian
class Plotter(object):
"""Base class for fit result plotting"""
def plotFit(self, plot, x, params):
def plotFit(self, plot, x, params, background):
"""Update a plot to display fit/COM results
:param plot: PlotWidget to update
:param numpy.ndarray x: X values
:param List[float] params: Parameters of the fit/COM
:param Union[None,numpy.ndarray] background:
The background estimation or None if no background
"""
raise NotImplementedError('Not implemented')
......@@ -59,16 +61,18 @@ class Plotter(object):
class GaussianPlotter(Plotter):
"""Plot gaussian fit results"""
def plotFit(self, plot, x, peakParams):
for peakName, peak in peakParams.items():
def plotFit(self, plot, x, params, background):
for peakName, peak in params.items():
height = peak.get('Area')
position = peak.get('Center')
width = peak.get('Sigma')
params = [height, position, width]
gaussian_params = [height, position, width]
if numpy.all(numpy.isfinite(params)):
fitted = gaussian(x, *params)
if numpy.all(numpy.isfinite(gaussian_params)):
fitted = gaussian(x, *gaussian_params)
if background is not None:
fitted += background
plot.addCurve(x,
fitted,
legend='{0}'.format(peakName),
......@@ -81,16 +85,17 @@ class GaussianPlotter(Plotter):
class CentroidPlotter(Plotter):
"""Plot center-of-mass/Max results"""
def plotFit(self, plot, x, peakParams):
for peakName, peak in peakParams.items():
def plotFit(self, plot, x, params, background):
for peakName, peak in params.items():
center = peak.get('COM')
xmax = peak.get('Pos_max')
if numpy.isfinite(center):
plot.addXMarker(center, legend='center of mass', text="com")
plot.addXMarker(xmax, legend='maximum position',
text="max",
color="gray")
plot.addXMarker(xmax,
legend='maximum position',
text="max",
color="gray")
def getPlotTitle(self):
return 'Center Of Mass'
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