Commit d5dd3a11 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

Merge branch 'ask_for_rsm' into 'master'

Ask kind of transformation

See merge request !133
parents 1b0d6401 f74c53c5
Pipeline #52641 passed with stage
in 2 minutes and 10 seconds
...@@ -120,6 +120,7 @@ if __name__ == '__main__': ...@@ -120,6 +120,7 @@ if __name__ == '__main__':
filenames=filenames, filenames=filenames,
copy_files=True, in_memory=not options.in_disk) copy_files=True, in_memory=not options.in_disk)
else: else:
_dir = _dir if _dir != None else os.path.dirname(options.first_filename)
dataset = Dataset(_dir=_dir, dataset = Dataset(_dir=_dir,
first_filename=options.first_filename, first_filename=options.first_filename,
copy_files=True, in_memory=not options.in_disk) copy_files=True, in_memory=not options.in_disk)
......
...@@ -1298,11 +1298,11 @@ class Dataset(): ...@@ -1298,11 +1298,11 @@ class Dataset():
data = Data(new_urls.reshape(self.data.urls.shape), self.data.metadata, in_memory=True) # to modify data = Data(new_urls.reshape(self.data.urls.shape), self.data.metadata, in_memory=True) # to modify
return Dataset(_dir=_dir, data=data, dims=self.__dims, transformation=self.transformation, in_memory=True) return Dataset(_dir=_dir, data=data, dims=self.__dims, transformation=self.transformation, in_memory=True)
def compute_transformation(self, d, rotate=False): def compute_transformation(self, d, kind="magnification", rotate=False):
H, W = self.get_data(0).shape H, W = self.get_data(0).shape
if self.dims.ndim == 1: if self.dims.ndim == 1 and kind == "rsm":
ffz = self.get_metadata_values(POSITIONER_METADATA, "ffz")[0] ffz = self.get_metadata_values(POSITIONER_METADATA, "ffz")[0]
mainx = -self.get_metadata_values(POSITIONER_METADATA, "mainx")[0] mainx = -self.get_metadata_values(POSITIONER_METADATA, "mainx")[0]
self.transformation = compute_rsm(H, W, d, ffz, mainx) self.transformation = compute_rsm(H, W, d, ffz, mainx)
......
...@@ -282,11 +282,13 @@ class _Transformation: ...@@ -282,11 +282,13 @@ class _Transformation:
dataset, indices, li_indices, bg_dataset = dataset dataset, indices, li_indices, bg_dataset = dataset
magnification = self._properties['magnification'] if 'magnification' in self._properties else None magnification = self._properties['magnification'] if 'magnification' in self._properties else None
pixelSize = self._properties['pixelSize'] if 'pixelSize' in self._properties else None pixelSize = self._properties['pixelSize'] if 'pixelSize' in self._properties else None
kind = self._properties['kind'] if 'kind' in self._properties else True
rotate = self._properties['rotate'] if 'rotate' in self._properties else None rotate = self._properties['rotate'] if 'rotate' in self._properties else None
if dataset and dataset.dims.ndim: if dataset and dataset.dims.ndim:
if dataset.dims.ndim == 1: if dataset.dims.ndim == 1 and kind:
dataset.compute_transformation(PixelSize[pixelSize].value, dataset.compute_transformation(PixelSize[pixelSize].value,
rotate) kind="rsm",
rotate=rotate)
else: else:
dataset.compute_transformation(magnification) dataset.compute_transformation(magnification)
return dataset, indices, li_indices, bg_dataset return dataset, indices, li_indices, bg_dataset
......
...@@ -109,5 +109,6 @@ class RSMWidget(qt.QMainWindow): ...@@ -109,5 +109,6 @@ class RSMWidget(qt.QMainWindow):
self._pixelSize = self._pixelSizeCB.currentText() self._pixelSize = self._pixelSizeCB.currentText()
self._rotate = self._rotateCB.isChecked() self._rotate = self._rotateCB.isChecked()
self.dataset.compute_transformation(PixelSize[self._pixelSize].value, self.dataset.compute_transformation(PixelSize[self._pixelSize].value,
self._rotate) kind="rsm",
rotate=self._rotate)
self.sigComputed.emit() self.sigComputed.emit()
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"] __authors__ = ["J. Garriga"]
__license__ = "MIT" __license__ = "MIT"
__date__ = "16/07/2021" __date__ = "10/08/2021"
from Orange.widgets.settings import Setting from Orange.widgets.settings import Setting
...@@ -55,12 +55,19 @@ class TransformationWidgetOW(OWWidget): ...@@ -55,12 +55,19 @@ class TransformationWidgetOW(OWWidget):
magnification = Setting(float(), schema_only=True) magnification = Setting(float(), schema_only=True)
pixelSize = Setting(str(), schema_only=True) pixelSize = Setting(str(), schema_only=True)
kind = Setting(bool(), schema_only=True)
rotate = Setting(bool(), schema_only=True) rotate = Setting(bool(), schema_only=True)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
qt.QLocale.setDefault(qt.QLocale("en_US")) qt.QLocale.setDefault(qt.QLocale("en_US"))
self._widget = None self._widget = None
# Add combobox to choose between RSM and magnification (in one dimension case)
self._methodCB = qt.QComboBox(self)
self._methodCB.addItems(["RSM", "Magnification"])
self._methodCB.hide()
self.controlArea.layout().addWidget(self._methodCB)
self._methodCB.currentTextChanged.connect(self._changeWidget)
@Inputs.dataset @Inputs.dataset
def setDataset(self, dataset): def setDataset(self, dataset):
...@@ -68,6 +75,7 @@ class TransformationWidgetOW(OWWidget): ...@@ -68,6 +75,7 @@ class TransformationWidgetOW(OWWidget):
self.controlArea.layout().removeWidget(self._widget) self.controlArea.layout().removeWidget(self._widget)
self._widget.hide() self._widget.hide()
if dataset: if dataset:
self._dataset = dataset
if not dataset[0].dims.ndim: if not dataset[0].dims.ndim:
msg = qt.QMessageBox() msg = qt.QMessageBox()
msg.setIcon(qt.QMessageBox.Warning) msg.setIcon(qt.QMessageBox.Warning)
...@@ -76,31 +84,52 @@ class TransformationWidgetOW(OWWidget): ...@@ -76,31 +84,52 @@ class TransformationWidgetOW(OWWidget):
msg.exec_() msg.exec_()
else: else:
if dataset[0].dims.ndim == 1: if dataset[0].dims.ndim == 1:
self._widget = RSMWidget(parent=self) self._methodCB.show()
if self.pixelSize: self._changeWidget("RSM")
self._widget.pixelSize = self.pixelSize
self._widget.rotate = self.rotate
else: else:
self._methodCB.hide()
self._widget = MagnificationWidget(parent=self) self._widget = MagnificationWidget(parent=self)
if self.magnification: if self.magnification:
self._widget.magnification = self.magnification self._widget.magnification = self.magnification
self._widget.sigComputed.connect(self._sendSignal) self._widget.sigComputed.connect(self._sendSignal)
self.controlArea.layout().addWidget(self._widget) self.controlArea.layout().addWidget(self._widget)
self._widget.setDataset(*dataset) self._widget.setDataset(*dataset)
else: else:
# Emit None # Emit None
self.Outputs.dataset.send(dataset) self.Outputs.dataset.send(dataset)
self.open() self.open()
def _changeWidget(self, method):
"""
Change the widget displayed on the window
"""
if self._widget:
self.controlArea.layout().removeWidget(self._widget)
self._widget.hide()
if method == "RSM":
self._widget = RSMWidget(parent=self)
if self.pixelSize:
self._widget.pixelSize = self.pixelSize
self._widget.rotate = self.rotate
else:
self._widget = MagnificationWidget(parent=self)
if self.magnification:
self._widget.magnification = self.magnification
self._widget.sigComputed.connect(self._sendSignal)
self.controlArea.layout().addWidget(self._widget)
self._widget.setDataset(*self._dataset)
def _sendSignal(self): def _sendSignal(self):
""" """
Emits the signal with the new dataset. Emits the signal with the new dataset.
""" """
if hasattr(self._widget, 'magnification'): if hasattr(self._widget, 'magnification'):
self.magnification = self._widget.magnification self.magnification = self._widget.magnification
self.kind = False
elif hasattr(self._widget, 'pixelSize'): elif hasattr(self._widget, 'pixelSize'):
self.pixelSize = self._widget.pixelSize self.pixelSize = self._widget.pixelSize
self.rotate = self._widget.rotate self.rotate = self._widget.rotate
self.kind = True
self.close() self.close()
self.Outputs.dataset.send(self._widget.getDataset()) self.Outputs.dataset.send(self._widget.getDataset())
Supports Markdown
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