Commit b56b0f5b authored by Thomas Vincent's avatar Thomas Vincent
Browse files

Add selection of coordinate system in QSpace dialog

parent b3a444e6
...@@ -41,6 +41,7 @@ from ..widgets.AcqParamsWidget import AcqParamsWidget ...@@ -41,6 +41,7 @@ from ..widgets.AcqParamsWidget import AcqParamsWidget
from ..widgets.Containers import GroupBox, SubGroupBox from ..widgets.Containers import GroupBox, SubGroupBox
from ..widgets.Input import StyledLineEdit from ..widgets.Input import StyledLineEdit
from ...process.qspace import QSpaceConverter, qspace_conversion from ...process.qspace import QSpaceConverter, qspace_conversion
from ...process.qspace import QSpaceCoordinates
_ETA_LOWER = u'\u03B7' _ETA_LOWER = u'\u03B7'
...@@ -178,33 +179,44 @@ class ConversionParamsWidget(Qt.QWidget): ...@@ -178,33 +179,44 @@ class ConversionParamsWidget(Qt.QWidget):
layout.addWidget(imageGbox) layout.addWidget(imageGbox)
# =========== # ===========
# Image pre processing # QSpace histogram settings
# =========== # ===========
qspaceGbox = SubGroupBox('QSpace grid dimensions.') qspaceGbox = SubGroupBox('QSpace')
qspaceLayout = Qt.QHBoxLayout(qspaceGbox) qspaceLayout = Qt.QFormLayout(qspaceGbox)
qspaceLayout.addRow(Qt.QLabel("Grid dimensions:"))
self.__qDimEdits = {} # Store line edits for each coordinate system
self.__qDimWidgets = {} # Store widget containing labels and line edit
qDimLayout = Qt.QVBoxLayout()
qDimLayout.setContentsMargins(0, 0, 0, 0)
qDimLayout.setSpacing(0)
qspaceLayout.addRow(qDimLayout)
for coordinates in QSpaceCoordinates.ALLOWED:
self.__qDimWidgets[coordinates] = Qt.QWidget()
qspaceDimLayout = Qt.QHBoxLayout(self.__qDimWidgets[coordinates])
self.__qDimEdits[coordinates] = (StyledLineEdit(nChar=5),
StyledLineEdit(nChar=5),
StyledLineEdit(nChar=5))
self.__qDimsXEdit = StyledLineEdit(nChar=5) for axis, edit in zip(QSpaceCoordinates.axesNames(coordinates),
self.__qDimsYEdit = StyledLineEdit(nChar=5) self.__qDimEdits[coordinates]):
self.__qDimsZEdit = StyledLineEdit(nChar=5) qspaceDimLayout.addWidget(Qt.QLabel(axis + ':'))
qspaceDimLayout.addWidget(edit)
qspaceDimLayout.addStretch(1)
dimLayout = Qt.QHBoxLayout() qDimLayout.addWidget(self.__qDimWidgets[coordinates])
qspaceLayout.addLayout(dimLayout)
dimLayout.addWidget(Qt.QLabel('qx:'))
dimLayout.addWidget(self.__qDimsXEdit)
dimLayout.addStretch(1)
dimLayout = Qt.QHBoxLayout() self.__coordinatesComboBox = Qt.QComboBox()
qspaceLayout.addLayout(dimLayout) self.__coordinatesComboBox.currentIndexChanged[int].connect(
dimLayout.addWidget(Qt.QLabel('qy:')) self.__coordinatesChanged)
dimLayout.addWidget(self.__qDimsYEdit)
dimLayout.addStretch(1)
dimLayout = Qt.QHBoxLayout() for coordinates in QSpaceCoordinates.ALLOWED:
qspaceLayout.addLayout(dimLayout) self.__coordinatesComboBox.addItem(coordinates)
dimLayout.addWidget(Qt.QLabel('qz:')) qspaceLayout.addRow("Coordinates:", self.__coordinatesComboBox)
dimLayout.addWidget(self.__qDimsZEdit)
dimLayout.addStretch(1)
layout.addWidget(qspaceGbox) layout.addWidget(qspaceGbox)
...@@ -216,6 +228,12 @@ class ConversionParamsWidget(Qt.QWidget): ...@@ -216,6 +228,12 @@ class ConversionParamsWidget(Qt.QWidget):
# self.setSizePolicy(Qt.QSizePolicy(Qt.QSizePolicy.Fixed, # self.setSizePolicy(Qt.QSizePolicy(Qt.QSizePolicy.Fixed,
# Qt.QSizePolicy.Fixed)) # Qt.QSizePolicy.Fixed))
def __coordinatesChanged(self, index=None):
"""Handle change of QSpace coordinate change"""
coordinates = self.__coordinatesComboBox.currentText()
for coord, widget in self.__qDimWidgets.items():
widget.setVisible(coordinates == coord)
def __checkboxToggled(self, checked): def __checkboxToggled(self, checked):
"""Update image processing check box icons""" """Update image processing check box icons"""
style = Qt.QApplication.instance().style() style = Qt.QApplication.instance().style()
...@@ -316,38 +334,34 @@ class ConversionParamsWidget(Qt.QWidget): ...@@ -316,38 +334,34 @@ class ConversionParamsWidget(Qt.QWidget):
self.__medfiltVEdit.setText(str(medfiltDims[1])) self.__medfiltVEdit.setText(str(medfiltDims[1]))
self.__medfiltCBox.setChecked(not equal) self.__medfiltCBox.setChecked(not equal)
def getQspaceDims(self): def getQspaceDims(self, coordinates=None):
""" """Returns the qspace dimensions, a 3 integers (> 1) array if set,
Returns the qspace dimensions, a 3 integers (> 1) array if set,
or [None, None, None]. or [None, None, None].
:return:
:param Union[None,QSpaceCoordinates] coordinates:
Either the coordinates system for which to get the value or None
to get information for the current coordinates system
:rtype: List[Union[int,None]]
""" """
qsize_x = self.__qDimsXEdit.text() if coordinates is None:
if len(qsize_x) == 0: coordinates = self.__coordinatesComboBox.currentText()
qsize_x = None
else: sizes = []
qsize_x = int(qsize_x) for edit in self.__qDimEdits[coordinates]:
qsize_y = self.__qDimsYEdit.text() qsize = edit.text()
if len(qsize_y) == 0: qsize = None if len(qsize) == 0 else int(qsize)
qsize_y = None sizes.append(qsize)
else: return sizes
qsize_y = int(qsize_y)
qsize_z = self.__qDimsZEdit.text()
if len(qsize_z) == 0:
qsize_z = None
else:
qsize_z = int(qsize_z)
return [qsize_x, qsize_y, qsize_z]
def setQSpaceDims(self, qspaceDims): def setQSpaceDims(self, coordinates, qspaceDims):
"""Sets the qspace dimensions. """Sets the qspace dimensions.
:param QSpaceCoordinates coordinates:
:param qspaceDims: A three integers array. :param qspaceDims: A three integers array.
:return: :return:
""" """
self.__qDimsXEdit.setText(str(int(qspaceDims[0]))) for edit, size in zip(self.__qDimEdits[coordinates], qspaceDims):
self.__qDimsYEdit.setText(str(int(qspaceDims[1]))) edit.setText(str(int(size)))
self.__qDimsZEdit.setText(str(int(qspaceDims[2])))
def getBeamEnergy(self): def getBeamEnergy(self):
"""Returns beam energy in eV or None if no input""" """Returns beam energy in eV or None if no input"""
...@@ -371,6 +385,13 @@ class ConversionParamsWidget(Qt.QWidget): ...@@ -371,6 +385,13 @@ class ConversionParamsWidget(Qt.QWidget):
self.__acqParamWid.chperdeg_h) self.__acqParamWid.chperdeg_h)
return None if None in channelsPerDegree else channelsPerDegree return None if None in channelsPerDegree else channelsPerDegree
def getCoordinates(self):
"""Returns the coordinates system to use.
:rtype: QSpaceCoordinates
"""
return self.__coordinatesComboBox.currentText()
class QSpaceWidget(Qt.QDialog): class QSpaceWidget(Qt.QDialog):
sigProcessDone = Qt.Signal(object) sigProcessDone = Qt.Signal(object)
...@@ -600,6 +621,7 @@ class QSpaceWidget(Qt.QDialog): ...@@ -600,6 +621,7 @@ class QSpaceWidget(Qt.QDialog):
# Set default qspace bin size # Set default qspace bin size
if entries: if entries:
# Get angles from all entries # Get angles from all entries
phi = [] phi = []
eta = [] eta = []
...@@ -613,28 +635,38 @@ class QSpaceWidget(Qt.QDialog): ...@@ -613,28 +635,38 @@ class QSpaceWidget(Qt.QDialog):
entry = entries[0] # Get default config from first entry entry = entries[0] # Get default config from first entry
# Compute Qspace conversion for coordinates in QSpaceCoordinates.ALLOWED:
q_array = qspace_conversion( # Compute Qspace conversion
img_size=xsocsH5.image_size(entry), q_array = qspace_conversion(
center_chan=xsocsH5.direct_beam(entry), img_size=xsocsH5.image_size(entry),
chan_per_deg=xsocsH5.chan_per_deg(entry), center_chan=xsocsH5.direct_beam(entry),
beam_energy=xsocsH5.beam_energy(entry), chan_per_deg=xsocsH5.chan_per_deg(entry),
phi=phi, beam_energy=xsocsH5.beam_energy(entry),
eta=eta, phi=phi,
nu=nu, eta=eta,
delta=delta) nu=nu,
delta=delta,
# Estimate bin numbers based on smallest distance between q vectors coordinates=coordinates)
maxbins = []
for dim in (q_array[:, :, :, 0], q_array[:, :, :, 1], q_array[:, :, :, 2]): if coordinates == QSpaceCoordinates.CARTESIAN:
maxbin = np.inf # Estimate bin numbers based on smallest distance between q vectors
for j in range(dim.ndim): maxbins = []
step = abs(np.diff(dim, axis=j)).max(j) for dim in (q_array[..., 0], q_array[..., 1], q_array[..., 2]):
bins = np.nanmin(((abs(dim).max() - abs(dim).min()) / step)) maxbin = np.inf
maxbin = min(maxbin, bins) for j in range(dim.ndim):
maxbins.append(int(maxbin) + 1) step = abs(np.diff(dim, axis=j)).max()
bins = (abs(dim).max() - abs(dim).min()) / step
self.__paramsWid.setQSpaceDims(maxbins) maxbin = min(maxbin, bins)
maxbins.append(int(maxbin) + 1)
else:
# TODO estimate bins for spherical coordinates
maxbins = [0, 0, 0]
self.__paramsWid.setQSpaceDims(coordinates, maxbins)
else: # Set to 0 by default
for coordinates in QSpaceCoordinates.ALLOWED:
self.__paramsWid.setQSpaceDims(coordinates, [0, 0, 0])
def __slotConvertBnClicked(self): def __slotConvertBnClicked(self):
""" """
...@@ -669,6 +701,7 @@ class QSpaceWidget(Qt.QDialog): ...@@ -669,6 +701,7 @@ class QSpaceWidget(Qt.QDialog):
channelsPerDegree = self.__paramsWid.getChannelsPerDegree() channelsPerDegree = self.__paramsWid.getChannelsPerDegree()
mask = self.__paramsWid.getMask() mask = self.__paramsWid.getMask()
maxipixCorrection = self.__paramsWid.isMaxipixCorrectionEnabled() maxipixCorrection = self.__paramsWid.isMaxipixCorrectionEnabled()
coordinates = self.__paramsWid.getCoordinates()
try: try:
converter.normalizer = normalizer converter.normalizer = normalizer
...@@ -679,6 +712,7 @@ class QSpaceWidget(Qt.QDialog): ...@@ -679,6 +712,7 @@ class QSpaceWidget(Qt.QDialog):
converter.channels_per_degree = channelsPerDegree converter.channels_per_degree = channelsPerDegree
converter.mask = mask converter.mask = mask
converter.maxipix_correction = maxipixCorrection converter.maxipix_correction = maxipixCorrection
converter.coordinates = coordinates
except ValueError as ex: except ValueError as ex:
Qt.QMessageBox.critical(self, 'Error', Qt.QMessageBox.critical(self, 'Error',
str(ex)) str(ex))
......
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