Commit 50060d23 authored by Carsten Richter's avatar Carsten Richter
Browse files

Merge branch 'improve-fit-plot' into 'master'

Improve fit plot

Closes #61 and #60

See merge request !92
parents 140b717a 9a6d7209
Pipeline #6535 passed with stages
in 4 minutes and 57 seconds
...@@ -297,22 +297,38 @@ class FitView(Qt.QMainWindow): ...@@ -297,22 +297,38 @@ class FitView(Qt.QMainWindow):
plot.clearMarkers() plot.clearMarkers()
plot.setGraphTitle('{0} ({1})'.format(title, name)) plot.setGraphTitle('{0} ({1})'.format(title, name))
plot.addCurve(xAcq, yAcq, legend='measured', color='blue') plot.addCurve(xAcq, yAcq,
legend='measured',
color='blue',
linestyle=':')
roiIndices = np.nonzero(np.in1d(xAcq, xFit, assume_unique=True))[0]
if len(roiIndices) != len(xFit):
roiIndices = None
_logger.error(
"Cannot retrieve ROI: cannot display ROI information")
else:
plot.addCurve(xAcq[roiIndices], yAcq[roiIndices],
legend='measured (ROI)',
color='blue',
linestyle='-')
background = None
if backgroundMode != BackgroundTypes.NONE: # Display background if backgroundMode != BackgroundTypes.NONE: # Display background
indices = np.nonzero(np.in1d(xAcq, xFit, assume_unique=True))[0] if roiIndices is None:
if len(indices) != len(xFit):
_logger.error( _logger.error(
"Cannot retrieve ROI: cannot display background") "Cannot retrieve ROI: cannot display background")
else: else:
background = background_estimation(backgroundMode,
yAcq[roiIndices])
plot.addCurve( plot.addCurve(
xFit, xFit,
background_estimation(backgroundMode, yAcq[indices]), background,
legend='background', legend='background',
linestyle=':', linestyle='--',
color='black') color='black')
plotter.plotFit(plot, xFit, peakParams) plotter.plotFit(plot, xFit, peakParams, background)
def _initGaussian(plots, fitH5Name, entry, process): def _initGaussian(plots, fitH5Name, entry, process):
......
...@@ -39,12 +39,14 @@ from ....util import gaussian ...@@ -39,12 +39,14 @@ from ....util import gaussian
class Plotter(object): class Plotter(object):
"""Base class for fit result plotting""" """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 """Update a plot to display fit/COM results
:param plot: PlotWidget to update :param plot: PlotWidget to update
:param numpy.ndarray x: X values :param numpy.ndarray x: X values
:param List[float] params: Parameters of the fit/COM :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') raise NotImplementedError('Not implemented')
...@@ -59,16 +61,18 @@ class Plotter(object): ...@@ -59,16 +61,18 @@ class Plotter(object):
class GaussianPlotter(Plotter): class GaussianPlotter(Plotter):
"""Plot gaussian fit results""" """Plot gaussian fit results"""
def plotFit(self, plot, x, peakParams): def plotFit(self, plot, x, params, background):
for peakName, peak in peakParams.items(): for peakName, peak in params.items():
height = peak.get('Area') height = peak.get('Area')
position = peak.get('Center') position = peak.get('Center')
width = peak.get('Sigma') width = peak.get('Sigma')
params = [height, position, width] gaussian_params = [height, position, width]
if numpy.all(numpy.isfinite(params)): if numpy.all(numpy.isfinite(gaussian_params)):
fitted = gaussian(x, *params) fitted = gaussian(x, *gaussian_params)
if background is not None:
fitted += background
plot.addCurve(x, plot.addCurve(x,
fitted, fitted,
legend='{0}'.format(peakName), legend='{0}'.format(peakName),
...@@ -81,14 +85,15 @@ class GaussianPlotter(Plotter): ...@@ -81,14 +85,15 @@ class GaussianPlotter(Plotter):
class CentroidPlotter(Plotter): class CentroidPlotter(Plotter):
"""Plot center-of-mass/Max results""" """Plot center-of-mass/Max results"""
def plotFit(self, plot, x, peakParams): def plotFit(self, plot, x, params, background):
for peakName, peak in peakParams.items(): for peakName, peak in params.items():
center = peak.get('COM') center = peak.get('COM')
xmax = peak.get('Pos_max') xmax = peak.get('Pos_max')
if numpy.isfinite(center): if numpy.isfinite(center):
plot.addXMarker(center, legend='center of mass', text="com") plot.addXMarker(center, legend='center of mass', text="com")
plot.addXMarker(xmax, legend='maximum position', plot.addXMarker(xmax,
legend='maximum position',
text="max", text="max",
color="gray") color="gray")
......
Supports Markdown
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