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
from silx.gui import qt as Qt
from ...io.QSpaceH5 import QSpaceH5
from ...io.FitH5 import FitH5Writer
from ...io.FitH5 import FitH5Writer, FitH5QAxis
from ..widgets.Containers import GroupBox
from ..widgets.Input import StyledLineEdit
from ..widgets.FileChooser import FileChooser
......@@ -181,34 +181,88 @@ class FitWidget(Qt.QDialog):
results = peak_fit(self.__qspaceFile,
fit_type=self.__fitType,
roiIndices=self.__roiIndices)
with FitH5Writer(self.__selectedFile, mode='w') as fitH5:
entry = results.fit_name
process = results.fit_name
entry = results.entry
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():
processes = results.processes()
for process in processes:
fitH5.create_process(entry, process)
for param in results.params(process):
xresult = results.results(process, param, results.QX_AXIS)
yresult = results.results(process, param, results.QY_AXIS)
zresult = results.results(process, param, results.QZ_AXIS)
xstatus = results.qx_status(process)
ystatus = results.qy_status(process)
zstatus = results.qz_status(process)
fitH5.set_qx_result(entry,
process,
resName,
data)
for resName, data in results.q_y_results.items():
param,
xresult)
fitH5.set_qy_result(entry,
process,
resName,
data)
for resName, data in results.q_z_results.items():
param,
yresult)
fitH5.set_qz_result(entry,
process,
resName,
data)
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._setStatus(FitWidget.StatusCompleted)
......
......@@ -153,7 +153,7 @@ class FitButton(EditorMixin, Qt.QWidget):
dialog.selectFile(os.path.join(workdir, itemBasename))
if dialog.exec_():
csvPath = dialog.selectedFiles()[0]
fitItem.fitH5.export_txt(csvPath)
fitItem.fitH5.export_csv(fitItem.fitH5.entries()[0], csvPath)
@H5NodeClassDef('FitGroup',
......
......@@ -36,7 +36,7 @@ from silx.gui import qt as Qt
from kmap.gui.project.XsocsH5Factory import h5NodeToProjectItem
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 kmap.gui.model.TreeView import TreeView
......@@ -218,7 +218,7 @@ class FitView(Qt.QMainWindow):
if processes:
process = processes[0]
if process == 'LeastSq':
if process == 'gaussian':
_initLeastSq(self.__plots, fitH5.filename, entry, process)
elif process == 'Centroid':
_initCentroid(self.__plots, fitH5.filename, entry, process)
......@@ -269,7 +269,7 @@ class FitView(Qt.QMainWindow):
# TODO : refactor
process = self.__process
if process == 'LeastSq':
if process == 'gaussian':
_plotLeastSq(self.__fitPlots, xIdx,
fitH5,
entry, process,
......@@ -319,7 +319,7 @@ def _plotLeastSq(plots, index, fitH5,
xFitQY = fitH5.get_qy(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')
widths = fitH5.get_result(entry, process, 'width')
......@@ -408,17 +408,17 @@ def _initLeastSq(plots, fitH5Name, entry, process):
qApp.processEvents()
plots[0].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qx_axis)
'position', FitH5QAxis.qx_axis)
qApp.processEvents()
plots[1].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qy_axis)
'position', FitH5QAxis.qy_axis)
qApp.processEvents()
plots[2].plotFitResult(fitH5Name, entry, process,
'position', FitH5.qz_axis)
'position', FitH5QAxis.qz_axis)
def _initCentroid(plots, fitH5Name, entry, process):
......@@ -435,13 +435,13 @@ def _initCentroid(plots, fitH5Name, entry, process):
qApp = Qt.qApp
# plots[0].setVisible(True)
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)
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)
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__':
......
......@@ -31,7 +31,7 @@ __date__ = "15/09/2016"
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
......@@ -81,7 +81,7 @@ class DropPlotWidget(XsocsPlot2D):
scan_y = h5f.scan_y(entry)
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__':
......
......@@ -29,7 +29,6 @@ __authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "01/01/2017"
import numpy as np
from silx.gui import qt as Qt
......@@ -38,7 +37,7 @@ from kmap.gui.model.Model import Model, RootNode
from kmap.gui.project.Hdf5Nodes import H5File
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 ...project.Hdf5Nodes import H5Base, H5NodeClassDef
......@@ -111,16 +110,16 @@ class FitProcessNode(FitEntryNode):
"""
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):
base = self.h5Path.rstrip('/')
entry = self.entry
process = self.process
children = []
print 'PATH', self.h5Path, self.entry, self.process
with FitH5(self.h5File, mode='r') as h5f:
results = h5f.results(entry, process)
results = h5f.get_result_names(entry, process)
for result in results:
child = FitResultNode(self.h5File, base + '/' + result)
children.append(child)
......@@ -203,11 +202,11 @@ class FitModel(Model):
return super(Model, self).mimeData(indexes)
if index.column() == 1:
q_axis = FitH5.qx_axis
q_axis = FitH5QAxis.qx_axis
elif index.column() == 2:
q_axis = FitH5.qy_axis
q_axis = FitH5QAxis.qy_axis
elif index.column() == 3:
q_axis = FitH5.qz_axis
q_axis = FitH5QAxis.qz_axis
else:
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