Commit adfd926e authored by Damien Naudet's avatar Damien Naudet

Allows selection of entries to convert to qspace.

parent 70836d74
......@@ -195,7 +195,8 @@ class XsocsGui(Qt.QMainWindow):
outQSpaceH5=output_f,
qspaceDims=None,
imageBinning=None,
roi=event,
roi=event.roi,
entries=event.entries,
parent=self.sender())
widget.exec_()
if widget.status == QSpaceWidget.StatusCompleted:
......
......@@ -31,6 +31,8 @@ __date__ = "15/09/2016"
from silx.gui import qt as Qt
from ...io.XsocsH5 import XsocsH5
from ..widgets.Containers import GroupBox
from ..widgets.Input import StyledLineEdit
from ...process.qspace.QSpaceConverter import QSpaceConverter
......@@ -190,21 +192,39 @@ class QSpaceWidget(Qt.QDialog):
qspaceDims=None,
imageBinning=None,
roi=None,
entries=None,
**kwargs):
"""
Widgets displaying informations about data to be converted to QSpace,
and allowing the user to input some parameters.
:param xsocH5File:
:param outQSpaceH5:
:param qspaceDims:
:param imageBinning:
:param roi:
:param xsocH5File: name of the input XsocsH5 file.
:param outQSpaceH5: name of the output hdf5 file
:param qspaceDims: dimensions of the qspace volume
:param imageBinning: binning to apply to the images before conversion.
Default : (1, 1)
:param roi: Roi in sample coordinates (xMin, xMax, yMin, yMax)
:param entries: a list of entry names to convert to qspace. If None,
all entries found in the xsocsH5File will be used.
:param kwargs:
"""
super(QSpaceWidget, self).__init__(**kwargs)
self.__status = QSpaceWidget.StatusInit
xsocsH5 = XsocsH5(xsocH5File)
# checking entries
if entries is None:
entries = xsocsH5.entries()
elif len(entries) == 0:
raise ValueError('At least one entry must be selected.')
else:
diff = set(entries) - set(xsocsH5.entries())
if len(diff) > 0:
raise ValueError('The following entries were not found in '
'the input file :\n - {0}'
''.format('\n -'.join(diff)))
self.__params = {'roi': roi,
'xsocsH5_f': xsocH5File,
'qspaceH5_f': outQSpaceH5}
......@@ -332,7 +352,8 @@ class QSpaceWidget(Qt.QDialog):
output_f=outQSpaceH5,
qspace_dims=qspaceDims,
img_binning=imageBinning,
roi=roi)
roi=roi,
entries=entries)
cancelBn.clicked.connect(self.close)
convertBn.clicked.connect(self.__slotConvertBnClicked)
......@@ -485,12 +506,14 @@ class QSpaceWidget(Qt.QDialog):
self.__roiXMaxEdit.setText(str(xMax))
self.__roiYMinEdit.setText(str(yMin))
self.__roiYMaxEdit.setText(str(yMax))
indices = converter.sample_indices
nImgTxt = '{0} / {1}'.format(len(indices),
params['n_images'])
self.__nImgLabel.setText(nImgTxt)
self.__nAnglesLabel.setText(str(len(scans)))
nEntries = len(XsocsH5(self.__params['xsocsH5_f']).entries())
self.__nAnglesLabel.setText('{0} / {1}'.format(len(scans), nEntries))
class _ConversionProcessDialog(Qt.QDialog):
......
......@@ -43,7 +43,8 @@ from .Hdf5Nodes import H5GroupNode, H5NodeClassDef, H5DatasetNode
from ..view.FitView import FitView
from ..view.QspaceView import QSpaceView
from ..view.IntensityView import IntensityView
from ..view.intensity.IntensityView import IntensityView
from ..project.IntensityGroup import IntensityGroup
class ScatterPlotButton(EditorMixin, Qt.QWidget):
......@@ -112,9 +113,8 @@ class IntensityGroupNode(H5GroupNode):
view = self.__viewWidget
if view is None or view() is None:
view = weakref.ref(IntensityView(parent,
self.model,
self))
iGroup = IntensityGroup(self.h5File, nodePath=self.h5Path)
view = weakref.ref(IntensityView(iGroup, parent))
self.__viewWidget = view
return view()
......
......@@ -29,6 +29,8 @@ __authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
from collections import namedtuple
import numpy as np
from silx.gui import qt as Qt
......@@ -36,15 +38,16 @@ from silx.gui import qt as Qt
from .PlotModel import PlotTree
from ...model.TreeView import TreeView
from ...model.Model import Model, RootNode, Node
from ...model.ModelDef import ModelRoles
from ...project.XsocsH5Factory import h5NodeToProjectItem
from ...model.Model import Model, RootNode, Node
from ...project.Hdf5Nodes import H5GroupNode
from ...project.IntensityGroup import IntensityGroup
from ...widgets.XsocsPlot2D import XsocsPlot2D
from ...widgets.Containers import GroupBox
from ...widgets.Input import StyledLineEdit
from ...widgets.XsocsPlot2D import XsocsPlot2D
from ...widgets.Buttons import FixedSizePushButon
from ...widgets.Containers import GroupBox
try:
from silx.gui.plot.ImageRois import ImageRoiManager
......@@ -53,6 +56,9 @@ except ImportError:
from ...silx_imports.ImageRois import ImageRoiManager
IntensityViewEvent = namedtuple('IntensityViewEvent', ['roi', 'entries'])
class RectRoiWidget(Qt.QWidget):
sigRoiApplied = Qt.Signal(object)
......@@ -62,7 +68,7 @@ class RectRoiWidget(Qt.QWidget):
super(RectRoiWidget, self).__init__(parent)
self.__roiToolBar = roiToolBar = roiManager.toolBar(rois=['rectangle'],
options=['show'])
options=['show'])
roiToolBar.setMovable(False)
topLayout = Qt.QVBoxLayout(self)
......@@ -403,13 +409,13 @@ class IntensityView(Qt.QMainWindow):
plot = property(lambda self: self.__plotWindow)
def __init__(self,
parent,
model,
node,
intensityGroup,
parent=None,
**kwargs):
super(IntensityView, self).__init__(parent=parent)
super(IntensityView, self).__init__(parent, **kwargs)
self.setWindowTitle('[XSOCS] {0}'.format(node.h5Path))
self.setWindowTitle('[XSOCS] {0}:{1}'.format(intensityGroup.filename,
intensityGroup.path))
self.__displayedNode = None
self.__selectedPoint = None
......@@ -423,7 +429,7 @@ class IntensityView(Qt.QMainWindow):
layout = Qt.QVBoxLayout(selector)
# TODO : check item type
self.__iGroup = intensityGroup = h5NodeToProjectItem(node)
self.__iGroup = intensityGroup
self.__tree = tree = IntensityTree(intensityGroup, parent=self)
tree.model().dataChanged.connect(self.__slotModelDataChanged)
tree.sigCurrentChanged.connect(self.__slotItemSelected)
......@@ -535,7 +541,8 @@ class IntensityView(Qt.QMainWindow):
return
iGroup = self.__iGroup
entries, selected, unselected = self.__tree.model().getSelectedEntries()
entries, selected, unselected =\
self.__tree.model().getSelectedEntries()
nEntries = len(entries)
xsocsH5 = iGroup.projectRoot().xsocsH5
......@@ -572,7 +579,14 @@ class IntensityView(Qt.QMainWindow):
:param roi:
:return:
"""
self.sigProcessApplied.emit(roi)
entries, selected, _ =\
self.__tree.model().getSelectedEntries()
selEntries = [entries[idx] for idx in selected]
event = IntensityViewEvent(roi=roi, entries=selEntries)
self.sigProcessApplied.emit(event)
if __name__ == '__main__':
......
......@@ -90,13 +90,20 @@ class QSpaceConverter(object):
img_binning=None,
output_f=None,
roi=None,
entries=None,
callback=None):
"""
Merger for the Kmap SPEC and EDF files. This loads a spech5 file,
converts it to HDF5 and then tries to match scans and edf image
files.
:param xsocsH5_f: path to the input XsocsH5 file.
:param qspace_dims: dimensions of the qspace volume
:param img_binning: binning to apply to the images before conversion.
Default : (1, 1)
:param output_f: path to the output file that will be created.
:param roi: Roi in sample coordinates (xMin, xMax, yMin, yMax)
:param entries: a list of entry names to convert to qspace. If None,
all entries found in the xsocsH5File will be used.
:param callback: callback to call when the parsing is done.
"""
super(QSpaceConverter, self).__init__()
......@@ -108,10 +115,22 @@ class QSpaceConverter(object):
self.__xsocsH5_f = xsocsH5_f
self.__output_f = output_f
xsocsH5 = XsocsH5.XsocsH5(xsocsH5_f)
# checking entries
if entries is None:
entries = xsocsH5.entries()
else:
diff = set(entries) - set(xsocsH5.entries())
if len(diff) > 0:
raise ValueError('The following entries were not found in '
'the input file :\n - {0}'
''.format('\n -'.join(diff)))
self.__params = {'qspace_dims': None,
'image_binning': None,
'sample_indices': None,
'roi': None}
'roi': None,
'entries': sorted(entries)}
self.__callback = callback
self.__n_proc = None
......@@ -132,10 +151,9 @@ class QSpaceConverter(object):
def __get_scans(self):
"""
Returns the scans found in the input file.
Returns the entries that will be converted.
"""
params = _get_all_params(self.__xsocsH5_f)
return sorted(params.keys())
return self.__params['entries']
scans = property(__get_scans)
""" Returns the scans found in the input file. """
......@@ -431,11 +449,6 @@ class QSpaceConverter(object):
params = _get_all_params(self.__xsocsH5_f)
return params[scan]
def __get_scans(self):
""" Returns the scan names. """
params = _get_all_params(self.__xsocsH5_f)
return sorted(params.keys())
def __run_convert(self):
"""
Performs the conversion.
......@@ -454,7 +467,7 @@ class QSpaceConverter(object):
params = _get_all_params(xsocsH5_f)
entries = sorted(params.keys())
entries = self.__get_scans()
n_entries = len(entries)
first_param = params[entries[0]]
......
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