Commit af50e6c2 authored by Damien Naudet's avatar Damien Naudet

Restored the centroid process.

parent f69ce547
...@@ -220,7 +220,7 @@ class FitView(Qt.QMainWindow): ...@@ -220,7 +220,7 @@ class FitView(Qt.QMainWindow):
if process == 'gaussian': if process == 'gaussian':
_initLeastSq(self.__plots, fitH5.filename, entry, process) _initLeastSq(self.__plots, fitH5.filename, entry, process)
elif process == 'Centroid': elif process == 'centroid':
_initCentroid(self.__plots, fitH5.filename, entry, process) _initCentroid(self.__plots, fitH5.filename, entry, process)
def __slotPointSelected(self, point): def __slotPointSelected(self, point):
...@@ -276,7 +276,7 @@ class FitView(Qt.QMainWindow): ...@@ -276,7 +276,7 @@ class FitView(Qt.QMainWindow):
xAcqQX, xAcqQY, xAcqQZ, xAcqQX, xAcqQY, xAcqQZ,
yAcqQX, yAcqQY, yAcqQZ) yAcqQX, yAcqQY, yAcqQZ)
elif process == 'Centroid': elif process == 'centroid':
_plotCentroid(self.__fitPlots, xIdx, _plotCentroid(self.__fitPlots, xIdx,
fitH5, fitH5,
entry, process, entry, process,
...@@ -377,7 +377,7 @@ def _plotCentroid(plots, index, fitH5, ...@@ -377,7 +377,7 @@ def _plotCentroid(plots, index, fitH5,
# TODO : put all this in a toolbox, so it can be shared between # TODO : put all this in a toolbox, so it can be shared between
# the plot and the fit functions # the plot and the fit functions
positions = fitH5.get_result(entry, process, 'position') positions = fitH5.get_result(entry, process, 'C. of Mass')
plots[0].addCurve(xAcqQX, yAcqQX, legend='measured') plots[0].addCurve(xAcqQX, yAcqQX, legend='measured')
plots[0].addXMarker(positions.qx[index], legend='center of mass') plots[0].addXMarker(positions.qx[index], legend='center of mass')
...@@ -433,15 +433,18 @@ def _initCentroid(plots, fitH5Name, entry, process): ...@@ -433,15 +433,18 @@ def _initCentroid(plots, fitH5Name, entry, process):
# hard coded result name, this isn't satisfactory but I can't think # hard coded result name, this isn't satisfactory but I can't think
# of any other way right now. # of any other way right now.
qApp = Qt.qApp qApp = Qt.qApp
# plots[0].setVisible(True)
qApp.processEvents() qApp.processEvents()
plots[0].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qx_axis) plots[0].plotFitResult(fitH5Name, entry,
# plots[1].setVisible(True) process, 'C. of Mass', FitH5QAxis.qx_axis)
qApp.processEvents() qApp.processEvents()
plots[1].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qy_axis) plots[1].plotFitResult(fitH5Name, entry,
# plots[2].setVisible(True) process, 'C. of Mass', FitH5QAxis.qy_axis)
qApp.processEvents() qApp.processEvents()
plots[2].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qz_axis) plots[2].plotFitResult(fitH5Name, entry,
process, 'C. of Mass', FitH5QAxis.qz_axis)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -101,4 +101,5 @@ def centroid(x, y, p): ...@@ -101,4 +101,5 @@ def centroid(x, y, p):
# TODO : throw exception if fit failed # TODO : throw exception if fit failed
com = x.dot(y) / y.sum() com = x.dot(y) / y.sum()
idx = np.abs(x - com).argmin() idx = np.abs(x - com).argmin()
return [y[idx], com, np.nan] i_max = y.max()
return [y[idx], com, i_max]
...@@ -376,34 +376,52 @@ class GaussianResults(FitSharedResults): ...@@ -376,34 +376,52 @@ class GaussianResults(FitSharedResults):
return results return results
# class CentroidResults(FitSharedResults): class CentroidResults(FitSharedResults):
# def __init__(self, def __init__(self,
# n_points=None, n_points=None,
# shared_results=None, shared_results=None,
# shared_status=None): shared_status=None):
# super(CentroidResults, self).__init__(n_points=n_points, super(CentroidResults, self).__init__(n_points=n_points,
# n_params=2, n_params=3,
# shared_results=shared_results, shared_results=shared_results,
# shared_status=shared_status) shared_status=shared_status)
#
# def fit_results(self): def fit_results(self, *args, **kwargs):
# qx_results = self._npy_qx_results qx_results = self._npy_qx_results
# qy_results = self._npy_qy_results qy_results = self._npy_qy_results
# qz_results = self._npy_qz_results qz_results = self._npy_qz_results
#
# qx_status = self._npy_qx_status qx_status = self._npy_qx_status
# qy_status = self._npy_qy_status qy_status = self._npy_qy_status
# qz_status = self._npy_qz_status qz_status = self._npy_qz_status
#
# fit_name = 'Centroid' fit_name = 'Centroid'
# q_x_results = {'height': qx_results[:, 0].ravel(), results = FitResult(fit_name, *args, **kwargs)
# 'position': qx_results[:, 1].ravel()}
# q_y_results = {'height': qy_results[:, 0].ravel(), results.add_qx_result('centroid', 'I(COM)', qx_results[:, 0].ravel())
# 'position': qy_results[:, 1].ravel()} results.add_qx_result('centroid', 'C. of Mass',
# q_z_results = {'height': qz_results[:, 0].ravel(), qx_results[:, 1].ravel())
# 'position': qz_results[:, 1].ravel()} results.add_qx_result('centroid', 'maximum',
# qx_results[:, 2].ravel())
# return [(fit_name, q_x_results, q_y_results, q_z_results)] results.set_qx_status('centroid', qx_status)
results.add_qy_result('centroid', 'I(COM)', qy_results[:, 0].ravel())
results.add_qy_result('centroid',
'C. of Mass',
qy_results[:, 1].ravel())
results.add_qy_result('centroid', 'maximum',
qy_results[:, 2].ravel())
results.set_qy_status('centroid', qy_status)
results.add_qz_result('centroid', 'I(COM)', qz_results[:, 0].ravel())
results.add_qz_result('centroid',
'C. of Mass',
qz_results[:, 1].ravel())
results.add_qz_result('centroid', 'maximum',
qz_results[:, 2].ravel())
results.set_qz_status('centroid', qz_status)
return results
def peak_fit(qspace_f, def peak_fit(qspace_f,
...@@ -433,13 +451,6 @@ def peak_fit(qspace_f, ...@@ -433,13 +451,6 @@ def peak_fit(qspace_f,
if fit_type not in FitTypes.ALLOWED: if fit_type not in FitTypes.ALLOWED:
raise ValueError('Unknown fit type : {0}'.format(fit_type)) raise ValueError('Unknown fit type : {0}'.format(fit_type))
if fit_type == FitTypes.LEASTSQ:
fit_fn = gaussian_fit
n_params = 9
if fit_type == FitTypes.CENTROID:
fit_fn = centroid
n_params = 9
with QSpaceH5.QSpaceH5(qspace_f) as qspace_h5: with QSpaceH5.QSpaceH5(qspace_f) as qspace_h5:
with qspace_h5.qspace_dset_ctx() as dset: with qspace_h5.qspace_dset_ctx() as dset:
qdata_shape = dset.shape qdata_shape = dset.shape
...@@ -460,7 +471,13 @@ def peak_fit(qspace_f, ...@@ -460,7 +471,13 @@ def peak_fit(qspace_f,
# # success = np.ndarray((n_indices,), dtype=np.bool) # # success = np.ndarray((n_indices,), dtype=np.bool)
# # success[:] = True # # success[:] = True
shared_results = GaussianResults(n_points=n_indices) if fit_type == FitTypes.LEASTSQ:
fit_fn = gaussian_fit
shared_results = GaussianResults(n_points=n_indices)
if fit_type == FitTypes.CENTROID:
fit_fn = centroid
shared_results = CentroidResults(n_points=n_indices)
# with h5py.File(qspace_f, 'r') as qspace_h5: # with h5py.File(qspace_f, 'r') as qspace_h5:
# #
......
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