Commit 3c2b9ff0 authored by Carsten Richter's avatar Carsten Richter

fixed the fit plots for the ROI projections.

parent 68f8a73d
Pipeline #6777 failed with stages
in 3 minutes and 48 seconds
......@@ -246,6 +246,7 @@ class FitView(Qt.QMainWindow):
backgroundMode = self.__fitH5.get_background_mode(entry)
xFitQX, xFitQY, xFitQZ = self.__fitH5.get_qspace_dimension_values(entry)
roi_indices = self.__fitH5.get_roi_indices(entry)
qxPeakParams = OrderedDict()
qyPeakParams = OrderedDict()
......@@ -268,12 +269,21 @@ class FitView(Qt.QMainWindow):
# Get QSpace data and project to axes
with self.__qspaceH5:
xAcqQX, xAcqQY, xAcqQZ = self.__qspaceH5.qspace_dimension_values
cube = self.__qspaceH5.qspace_slice(xIdx)
histo = self.__qspaceH5.histo
xAcqQX, xAcqQY, xAcqQZ = self.__qspaceH5.qspace_dimension_values
yAcqQX, yAcqQY, yAcqQZ = project(cube, histo)
if roi_indices is None:
qslice = np.s_[:,:,:]
else:
qslice = np.s_[roi_indices[0][0]:roi_indices[0][1],
roi_indices[1][0]:roi_indices[1][1],
roi_indices[2][0]:roi_indices[2][1]]
yAcqQroi = project(cube[qslice], histo[qslice])
# Get plotter
if entry == 'Gaussian':
plotterKlass = GaussianPlotter
......@@ -285,6 +295,7 @@ class FitView(Qt.QMainWindow):
title = plotter.getPlotTitle()
# Update plot with gathered information
idim = 0
for plot, name, xAcq, yAcq, xFit, peakParams in zip(
self.__fitPlots,
self.__axis_names,
......@@ -302,33 +313,30 @@ class FitView(Qt.QMainWindow):
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],
yAcqroi = yAcq #default
xAcqroi = xAcq
if roi_indices is not None:
xAcqroi = xAcq[qslice[idim]]
yAcqroi = yAcqQroi[idim]
plot.addCurve(xAcqroi, yAcqroi,
legend='measured (ROI)',
color='blue',
linestyle='-')
background = None
if backgroundMode != BackgroundTypes.NONE: # Display background
if roiIndices is None:
_logger.error(
"Cannot retrieve ROI: cannot display background")
else:
background = background_estimation(backgroundMode,
yAcq[roiIndices])
yAcqroi)
plot.addCurve(
xFit,
xAcqroi,
background,
legend='background',
linestyle='--',
color='black')
plotter.plotFit(plot, xFit, peakParams, background)
idim += 1
def _initGaussian(plots, fitH5Name, entry, process):
......
......@@ -66,6 +66,7 @@ class FitH5(XsocsH5Base):
"""
_QSPACE_AXIS_PATH = '{entry}/qspace_axis'
_QSPACE_ROI_PATH = '{entry}/qspace_rois'
_STATUS_PATH = '{entry}/status/{axis}'
_RESULT_GRP_PATH = '{entry}/{process}/results'
_RESULT_PATH = '{entry}/{process}/results/{result}/{axis}'
......@@ -151,6 +152,19 @@ class FitH5(XsocsH5Base):
return [self._get_array_data('/'.join((base_path, name)))
for name in self.get_qspace_dimension_names(entry)]
def get_roi_indices(self, entry):
"""Returns the axis rois.
:param str entry:
:rtype: List[numpy.ndarray]
"""
base_path = self._QSPACE_ROI_PATH.format(entry=entry)
if not self._path_exists(base_path):
return None
return [self._get_array_data('/'.join((base_path, name)))
for name in self.get_qspace_dimension_names(entry)]
def get_axis_result(self, entry, process, result, axis):
"""Returns the results for the given entry/process/result name/axis.
......@@ -356,3 +370,19 @@ class FitH5Writer(FitH5):
for index, values in enumerate((dim0, dim1, dim2)):
self._set_array_data(
'/'.join((base_path, self.__axis_name(index))), values)
def set_roi_indices(self, roi0, roi1, roi2):
"""Write qspace axes coordinates for each dimension
:param tuple roi0:
:param tuple roi1:
:param tuple roi2:
"""
base_path = self._QSPACE_ROI_PATH.format(entry=self.__entry)
for index, values in enumerate((roi0, roi1, roi2)):
values = numpy.array(values)
self._set_array_data(
'/'.join((base_path, self.__axis_name(index))), values)
......@@ -79,6 +79,7 @@ class FitResult(object):
Values along each axis of the QSpace
:param List[str] q_dim_names:
Name of axes for each dimension of the QSpace
:param Union[List[List[int]],None] roi_indices: QSpace ROI to process
:param FitTypes fit_mode: Kind of fit
:param BackgroundTypes background_mode: Kind of background subtraction
:param numpy.ndarray fit_results:
......@@ -92,6 +93,7 @@ class FitResult(object):
sample_x, sample_y,
q_dim_values,
q_dim_names,
roi_indices,
fit_mode, background_mode,
fit_results):
......@@ -109,6 +111,9 @@ class FitResult(object):
self.qspace_dimension_names = q_dim_names
"""QSpace axis names (List[str])"""
self.roi_indices = roi_indices
"""Roi indices (List[List[str]])"""
self.fit_mode = fit_mode
"""Fit type (FitTypes)"""
......@@ -163,6 +168,8 @@ class FitResult(object):
fitH5.create_process(result_name)
fitH5.set_sample_positions(self.sample_x, self.sample_y)
fitH5.set_qspace_dimension_values(*self.qspace_dimension_values)
if self.roi_indices is not None:
fitH5.set_roi_indices(*self.roi_indices)
for dimension, array in enumerate(self._fit_results):
for name in self.available_result_names:
......@@ -322,6 +329,7 @@ class PeakFitter(object):
sample_y=y_pos,
q_dim_values=(q_dim0, q_dim1, q_dim2),
q_dim_names=q_dim_names,
roi_indices=self.__roi_indices,
fit_mode=self.__fit_type,
background_mode=self.__background,
fit_results=numpy.array(fit_results, dtype=result_dtype))
......@@ -367,18 +375,18 @@ def _fit_process(index,
qspace_h5, axes, hits = _per_process_cache
# Load qspace
qspace = qspace_h5.qspace_slice(index)
# apply Qspace ROI
if roi_indices is not None:
dim0_slice = slice(roi_indices[0][0], roi_indices[0][1], 1)
dim1_slice = slice(roi_indices[1][0], roi_indices[1][1], 1)
dim2_slice = slice(roi_indices[2][0], roi_indices[2][1], 1)
axes = [axis[roi] for axis, roi in
zip(axes, (dim0_slice, dim1_slice, dim2_slice))]
hits = hits[dim0_slice, dim1_slice, dim2_slice]
qspace = qspace[dim0_slice, dim1_slice, dim2_slice]
qslice = numpy.s_[roi_indices[0][0]:roi_indices[0][1],
roi_indices[1][0]:roi_indices[1][1],
roi_indices[2][0]:roi_indices[2][1],
]
axes = [axis[roi] for axis, roi in zip(axes, qslice)]
qspace = qspace_h5.qspace_slice((index,) + qslice)
hits = hits[qslice]
else:
qspace = qspace_h5.qspace_slice(index)
# Normalize with hits and project to axes
projections = project(qspace, hits)
......
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