Commit c6a7dcc7 authored by Damien Naudet's avatar Damien Naudet

Preparing the multiple gaussians fit.

parent edce4b3e
...@@ -33,7 +33,7 @@ from collections import OrderedDict ...@@ -33,7 +33,7 @@ from collections import OrderedDict
from silx.gui import qt as Qt from silx.gui import qt as Qt
from ...io.QSpaceH5 import QSpaceH5 from ...io.QSpaceH5 import QSpaceH5
from ...io.FitH5 import FitH5Writer from ...io.FitH5 import FitH5Writer, FitH5QAxis
from ..widgets.Containers import GroupBox from ..widgets.Containers import GroupBox
from ..widgets.Input import StyledLineEdit from ..widgets.Input import StyledLineEdit
from ..widgets.FileChooser import FileChooser from ..widgets.FileChooser import FileChooser
...@@ -181,34 +181,88 @@ class FitWidget(Qt.QDialog): ...@@ -181,34 +181,88 @@ class FitWidget(Qt.QDialog):
results = peak_fit(self.__qspaceFile, results = peak_fit(self.__qspaceFile,
fit_type=self.__fitType, fit_type=self.__fitType,
roiIndices=self.__roiIndices) roiIndices=self.__roiIndices)
with FitH5Writer(self.__selectedFile, mode='w') as fitH5: with FitH5Writer(self.__selectedFile, mode='w') as fitH5:
entry = results.fit_name entry = results.entry
process = results.fit_name
fitH5.create_entry(entry) fitH5.create_entry(entry)
fitH5.create_process(entry, process)
fitH5.set_scan_x(entry, results.sample_x) fitH5.set_scan_x(entry, results.sample_x)
fitH5.set_scan_y(entry, results.sample_y) fitH5.set_scan_y(entry, results.sample_y)
fitH5.set_status(entry, process, results.status)
fitH5.set_qx(entry, results.q_x) fitH5.set_qx(entry, results.q_x)
fitH5.set_qy(entry, results.q_y) fitH5.set_qy(entry, results.q_y)
fitH5.set_qz(entry, results.q_z) fitH5.set_qz(entry, results.q_z)
for resName, data in results.q_x_results.items(): processes = results.processes()
fitH5.set_qx_result(entry,
process, for process in processes:
resName, fitH5.create_process(entry, process)
data)
for resName, data in results.q_y_results.items(): for param in results.params(process):
fitH5.set_qy_result(entry, xresult = results.results(process, param, results.QX_AXIS)
process, yresult = results.results(process, param, results.QY_AXIS)
resName, zresult = results.results(process, param, results.QZ_AXIS)
data)
for resName, data in results.q_z_results.items(): xstatus = results.qx_status(process)
fitH5.set_qz_result(entry, ystatus = results.qy_status(process)
process, zstatus = results.qz_status(process)
resName,
data) fitH5.set_qx_result(entry,
process,
param,
xresult)
fitH5.set_qy_result(entry,
process,
param,
yresult)
fitH5.set_qz_result(entry,
process,
param,
zresult)
fitH5.set_status(entry,
process,
FitH5QAxis.qx_axis,
xstatus)
fitH5.set_status(entry,
process,
FitH5QAxis.qy_axis,
ystatus)
fitH5.set_status(entry,
process,
FitH5QAxis.qz_axis,
zstatus)
# with FitH5Writer(self.__selectedFile, mode='w') as fitH5:
# entry = results.fit_name
# process = results.fit_name
# fitH5.create_entry(entry)
# fitH5.create_process(entry, process)
#
# fitH5.set_scan_x(entry, results.sample_x)
# fitH5.set_scan_y(entry, results.sample_y)
# fitH5.set_status(entry, process, results.status)
# fitH5.set_qx(entry, results.q_x)
# fitH5.set_qy(entry, results.q_y)
# fitH5.set_qz(entry, results.q_z)
#
# for resName, data in results.q_x_results.items():
# fitH5.set_qx_result(entry,
# process,
# resName,
# data)
# for resName, data in results.q_y_results.items():
# fitH5.set_qy_result(entry,
# process,
# resName,
# data)
# for resName, data in results.q_z_results.items():
# fitH5.set_qz_result(entry,
# process,
# resName,
# data)
self.__fitFile = self.__selectedFile self.__fitFile = self.__selectedFile
self._setStatus(FitWidget.StatusCompleted) self._setStatus(FitWidget.StatusCompleted)
......
...@@ -153,7 +153,7 @@ class FitButton(EditorMixin, Qt.QWidget): ...@@ -153,7 +153,7 @@ class FitButton(EditorMixin, Qt.QWidget):
dialog.selectFile(os.path.join(workdir, itemBasename)) dialog.selectFile(os.path.join(workdir, itemBasename))
if dialog.exec_(): if dialog.exec_():
csvPath = dialog.selectedFiles()[0] csvPath = dialog.selectedFiles()[0]
fitItem.fitH5.export_txt(csvPath) fitItem.fitH5.export_csv(fitItem.fitH5.entries()[0], csvPath)
@H5NodeClassDef('FitGroup', @H5NodeClassDef('FitGroup',
......
...@@ -36,7 +36,7 @@ from silx.gui import qt as Qt ...@@ -36,7 +36,7 @@ from silx.gui import qt as Qt
from kmap.gui.project.XsocsH5Factory import h5NodeToProjectItem from kmap.gui.project.XsocsH5Factory import h5NodeToProjectItem
from kmap.gui.widgets.Containers import GroupBox from kmap.gui.widgets.Containers import GroupBox
from kmap.io.FitH5 import FitH5 from kmap.io.FitH5 import FitH5, FitH5QAxis
from ..widgets.XsocsPlot2D import XsocsPlot2D from ..widgets.XsocsPlot2D import XsocsPlot2D
from kmap.gui.model.TreeView import TreeView from kmap.gui.model.TreeView import TreeView
...@@ -218,7 +218,7 @@ class FitView(Qt.QMainWindow): ...@@ -218,7 +218,7 @@ class FitView(Qt.QMainWindow):
if processes: if processes:
process = processes[0] process = processes[0]
if process == 'LeastSq': 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)
...@@ -269,7 +269,7 @@ class FitView(Qt.QMainWindow): ...@@ -269,7 +269,7 @@ class FitView(Qt.QMainWindow):
# TODO : refactor # TODO : refactor
process = self.__process process = self.__process
if process == 'LeastSq': if process == 'gaussian':
_plotLeastSq(self.__fitPlots, xIdx, _plotLeastSq(self.__fitPlots, xIdx,
fitH5, fitH5,
entry, process, entry, process,
...@@ -319,7 +319,7 @@ def _plotLeastSq(plots, index, fitH5, ...@@ -319,7 +319,7 @@ def _plotLeastSq(plots, index, fitH5,
xFitQY = fitH5.get_qy(entry) xFitQY = fitH5.get_qy(entry)
xFitQZ = fitH5.get_qz(entry) xFitQZ = fitH5.get_qz(entry)
heights = fitH5.get_result(entry, process, 'height') heights = fitH5.get_result(entry, process, 'intensity')
positions = fitH5.get_result(entry, process, 'position') positions = fitH5.get_result(entry, process, 'position')
widths = fitH5.get_result(entry, process, 'width') widths = fitH5.get_result(entry, process, 'width')
...@@ -408,17 +408,17 @@ def _initLeastSq(plots, fitH5Name, entry, process): ...@@ -408,17 +408,17 @@ def _initLeastSq(plots, fitH5Name, entry, process):
qApp.processEvents() qApp.processEvents()
plots[0].plotFitResult(fitH5Name, entry, process, plots[0].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qx_axis) 'position', FitH5QAxis.qx_axis)
qApp.processEvents() qApp.processEvents()
plots[1].plotFitResult(fitH5Name, entry, process, plots[1].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qy_axis) 'position', FitH5QAxis.qy_axis)
qApp.processEvents() qApp.processEvents()
plots[2].plotFitResult(fitH5Name, entry, process, plots[2].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qz_axis) 'position', FitH5QAxis.qz_axis)
def _initCentroid(plots, fitH5Name, entry, process): def _initCentroid(plots, fitH5Name, entry, process):
...@@ -435,13 +435,13 @@ def _initCentroid(plots, fitH5Name, entry, process): ...@@ -435,13 +435,13 @@ def _initCentroid(plots, fitH5Name, entry, process):
qApp = Qt.qApp qApp = Qt.qApp
# plots[0].setVisible(True) # plots[0].setVisible(True)
qApp.processEvents() qApp.processEvents()
plots[0].plotFitResult(fitH5Name, entry, process, 'position', FitH5.qx_axis) plots[0].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qx_axis)
# plots[1].setVisible(True) # plots[1].setVisible(True)
qApp.processEvents() qApp.processEvents()
plots[1].plotFitResult(fitH5Name, entry, process, 'position', FitH5.qy_axis) plots[1].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qy_axis)
# plots[2].setVisible(True) # plots[2].setVisible(True)
qApp.processEvents() qApp.processEvents()
plots[2].plotFitResult(fitH5Name, entry, process, 'position', FitH5.qz_axis) plots[2].plotFitResult(fitH5Name, entry, process, 'position', FitH5QAxis.qz_axis)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -31,7 +31,7 @@ __date__ = "15/09/2016" ...@@ -31,7 +31,7 @@ __date__ = "15/09/2016"
from silx.gui import qt as Qt from silx.gui import qt as Qt
from kmap.io.FitH5 import FitH5 from kmap.io.FitH5 import FitH5, FitH5QAxis
from ...widgets.XsocsPlot2D import XsocsPlot2D from ...widgets.XsocsPlot2D import XsocsPlot2D
...@@ -81,7 +81,7 @@ class DropPlotWidget(XsocsPlot2D): ...@@ -81,7 +81,7 @@ class DropPlotWidget(XsocsPlot2D):
scan_y = h5f.scan_y(entry) scan_y = h5f.scan_y(entry)
self.__legend = self.setPlotData(scan_x, scan_y, data) self.__legend = self.setPlotData(scan_x, scan_y, data)
self.setGraphTitle(result + '/' + FitH5.axis_names[q_axis]) self.setGraphTitle(result + '/' + FitH5QAxis.axis_names[q_axis])
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -29,7 +29,6 @@ __authors__ = ["D. Naudet"] ...@@ -29,7 +29,6 @@ __authors__ = ["D. Naudet"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "01/01/2017" __date__ = "01/01/2017"
import numpy as np import numpy as np
from silx.gui import qt as Qt from silx.gui import qt as Qt
...@@ -38,7 +37,7 @@ from kmap.gui.model.Model import Model, RootNode ...@@ -38,7 +37,7 @@ from kmap.gui.model.Model import Model, RootNode
from kmap.gui.project.Hdf5Nodes import H5File from kmap.gui.project.Hdf5Nodes import H5File
from kmap.gui.model.ModelDef import ModelRoles from kmap.gui.model.ModelDef import ModelRoles
from kmap.io.FitH5 import FitH5 from kmap.io.FitH5 import FitH5, FitH5QAxis
from ...widgets.XsocsPlot2D import XsocsPlot2D from ...widgets.XsocsPlot2D import XsocsPlot2D
from ...project.Hdf5Nodes import H5Base, H5NodeClassDef from ...project.Hdf5Nodes import H5Base, H5NodeClassDef
...@@ -111,16 +110,16 @@ class FitProcessNode(FitEntryNode): ...@@ -111,16 +110,16 @@ class FitProcessNode(FitEntryNode):
""" """
Node linked to a process group in a FitH5 file. Node linked to a process group in a FitH5 file.
""" """
process = property(lambda self: self.h5Path.split('/')[1]) process = property(lambda self: self.h5Path.lstrip('/').split('/')[1])
def _loadChildren(self): def _loadChildren(self):
base = self.h5Path.rstrip('/') base = self.h5Path.rstrip('/')
entry = self.entry entry = self.entry
process = self.process process = self.process
children = [] children = []
print 'PATH', self.h5Path, self.entry, self.process
with FitH5(self.h5File, mode='r') as h5f: with FitH5(self.h5File, mode='r') as h5f:
results = h5f.results(entry, process) results = h5f.get_result_names(entry, process)
for result in results: for result in results:
child = FitResultNode(self.h5File, base + '/' + result) child = FitResultNode(self.h5File, base + '/' + result)
children.append(child) children.append(child)
...@@ -203,11 +202,11 @@ class FitModel(Model): ...@@ -203,11 +202,11 @@ class FitModel(Model):
return super(Model, self).mimeData(indexes) return super(Model, self).mimeData(indexes)
if index.column() == 1: if index.column() == 1:
q_axis = FitH5.qx_axis q_axis = FitH5QAxis.qx_axis
elif index.column() == 2: elif index.column() == 2:
q_axis = FitH5.qy_axis q_axis = FitH5QAxis.qy_axis
elif index.column() == 3: elif index.column() == 3:
q_axis = FitH5.qz_axis q_axis = FitH5QAxis.qz_axis
else: else:
raise ValueError('Unexpected column.') raise ValueError('Unexpected column.')
......
This diff is collapsed.
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