GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit b56b0f5b authored by Thomas Vincent's avatar Thomas Vincent

Add selection of coordinate system in QSpace dialog

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