Commit 5075e98e authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

Merge branch 'ppf_zsum' into 'master'

Ppf zsum

See merge request !131
parents c5f96919 c9f59694
Pipeline #51479 passed with stage
in 2 minutes and 8 seconds
......@@ -66,6 +66,7 @@ if __name__ == '__main__':
import argparse
import sys
import os
import glob
from darfix.core.dataset import Dataset
from silx.gui import qt
......@@ -83,9 +84,9 @@ if __name__ == '__main__':
type=str,
default=None)
parser.add_argument(
'-fs',
'--filenames',
help='List of filenames to read',
'-tr',
'--treated_data',
help='Directory to save treated data',
type=str,
default=None)
parser.add_argument(
......@@ -97,18 +98,32 @@ if __name__ == '__main__':
options = parser.parse_args(sys.argv[1:])
if not (options.file_directory or options.first_filename or options.filenames):
parser.error('Please enter the file directory, first filename or list of filenames')
if not (options.file_directory or options.first_filename):
parser.error('Please enter the file directory or first filename')
else:
_dir = options.file_directory
if options.first_filename:
_dir = _dir if _dir != None else os.path.dirname(options.first_filename)
if options.treated_data:
if not options.first_filename:
filenames = sorted([x for x in glob.glob(_dir + "/*") if os.path.isfile(x)])
_dir = options.treated_data
dataset = Dataset(_dir=_dir,
filenames=filenames,
copy_files=True, in_memory=not options.in_disk)
else:
dataset = Dataset(_dir=options.treated_data,
first_filename=options.first_filename,
copy_files=True, in_memory=not options.in_disk)
else:
_dir = _dir if _dir != None else os.path.dirname(options.filenames[0])
dataset = Dataset(_dir=_dir,
first_filename=options.first_filename,
filenames=options.filenames,
copy_files=True, in_memory=not options.in_disk)
if not options.first_filename:
filenames = sorted([x for x in glob.glob(_dir + "/*") if os.path.isfile(x)])
dataset = Dataset(_dir=_dir,
filenames=filenames,
copy_files=True, in_memory=not options.in_disk)
else:
dataset = Dataset(_dir=_dir,
first_filename=options.first_filename,
copy_files=True, in_memory=not options.in_disk)
main(input_data=(dataset, None, None, None), channel='dataset')
"""
......
......@@ -41,6 +41,7 @@ from silx.gui import qt
from darfix.core import utils
from darfix.gui.blindSourceSeparationWidget import Method
from darfix.gui.grainPlotWidget import GrainPlotWidget
from darfix.gui.zSumWidget import ZSumWidget
from darfix.gui.rsmWidget import PixelSize
_input_desc = namedtuple("_input_desc", ["name", "type", "handler", "doc"])
......@@ -292,3 +293,21 @@ class _Transformation:
def set_properties(self, properties):
self._properties = properties
class _ZSum:
inputs = [_input_desc(name='dataset', type=tuple, handler='process',
doc='dataset to process'), ]
outputs = [
_output_desc(name='dataset', type=tuple, doc='dataset to process'), ]
def process(self, dataset):
app = qt.QApplication([])
widget = ZSumWidget()
if dataset:
widget.setDataset(*dataset)
widget.setAttribute(qt.Qt.WA_DeleteOnClose)
widget.show()
app.exec_()
return dataset
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "09/02/2021"
__date__ = "20/07/2021"
import logging
......@@ -280,13 +280,13 @@ class NoiseRemovalWidget(qt.QMainWindow):
else:
bg = None
self._chunks = None
self._step = None
if self._parametersDock.inDiskWidget.isVisible():
if self._parametersDock.inDiskCheckbox.isChecked():
self._step = None
self._chunks = [int(self._parametersDock.verticalChunkSize.text()),
int(self._parametersDock.horizontalChunkSize.text())]
else:
self._chunks = None
self._step = int(self._parametersDock.step.text())
self._thread = OperationThread(self, self._update_dataset.apply_background_subtraction)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "20/07/2021"
from silx.gui import qt
from silx.gui.colors import Colormap
from silx.gui.plot import Plot2D
from darfix.gui.utils import ChooseDimensionDock
class ZSumWidget(qt.QMainWindow):
"""
Widget to apply PCA to a set of images and plot the eigenvalues found.
"""
sigComputed = qt.Signal()
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.origin, self.scale = None, None
self._plot = Plot2D(parent=self)
self._plot.setDefaultColormap(Colormap(name='viridis', normalization='linear'))
self._chooseDimensionDock = ChooseDimensionDock(self)
self._chooseDimensionDock.hide()
self._chooseDimensionDock.widget.filterChanged.connect(self._filterStack)
self._chooseDimensionDock.widget.stateDisabled.connect(self._wholeStack)
layout = qt.QVBoxLayout()
layout.addWidget(self._plot)
layout.addWidget(self._chooseDimensionDock)
widget = qt.QWidget(self)
widget.setLayout(layout)
self.setCentralWidget(widget)
def setDataset(self, dataset, indices=None, bg_indices=None, bg_dataset=None):
# Make sum of dataset data
self.dataset = dataset
self.indices = indices
if len(self.dataset.data.shape) > 3:
self._chooseDimensionDock.show()
self._chooseDimensionDock.widget.setDimensions(self.dataset.dims)
image = self.dataset.zsum(indices=indices)
if self.dataset.transformation:
px = self.dataset.transformation[0][0][0]
py = self.dataset.transformation[1][0][0]
xscale = (self.dataset.transformation[0][-1][-1] - px) / len(self.dataset.transformation[0][0])
yscale = (self.dataset.transformation[1][-1][-1] - py) / len(self.dataset.transformation[1][0])
self.origin = (px, py)
self.scale = (xscale, yscale)
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
self._plot.addImage(image)
def _filterStack(self, dim=0, val=0):
image = self.dataset.zsum(indices=self.indices, dimension=[dim, val])
if image.shape[0]:
if self.origin:
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
else:
self._plot.clear()
def _wholeStack(self):
if self.origin:
self._plot.addImage(self.dataset.zsum(), origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(self.dataset.zsum(), xlabel='pixels', ylabel='pixels')
......@@ -26,19 +26,17 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "15/12/2020"
__date__ = "20/07/2021"
from silx.gui.colors import Colormap
from silx.gui.plot import Plot2D
from Orange.widgets.widget import OWWidget, Input
from darfix.gui.utils import ChooseDimensionDock
from darfix.gui.zSumWidget import ZSumWidget
class ZSumWidgetOW(OWWidget):
"""
Widget that sums a stack of images by the z axis.
Widget that computes the background substraction from a dataset
"""
name = "z sum"
......@@ -53,57 +51,17 @@ class ZSumWidgetOW(OWWidget):
def __init__(self):
super().__init__()
self._plot = Plot2D(parent=self)
self._plot.setDefaultColormap(Colormap(name='viridis', normalization='linear'))
self.controlArea.layout().addWidget(self._plot)
self._chooseDimensionDock = ChooseDimensionDock(self)
self._chooseDimensionDock.hide()
self.controlArea.layout().addWidget(self._chooseDimensionDock)
self.origin, self.scale = None, None
self._chooseDimensionDock.widget.filterChanged.connect(self._filterStack)
self._chooseDimensionDock.widget.stateDisabled.connect(self._wholeStack)
self._widget = ZSumWidget(parent=self)
self.controlArea.layout().addWidget(self._widget)
@Inputs.dataset
def setDataset(self, dataset):
# Make sum of dataset data
if dataset:
self.dataset = dataset[0]
self.indices = dataset[1]
if len(self.dataset.data.shape) > 3:
self._chooseDimensionDock.show()
self._chooseDimensionDock.widget.setDimensions(self.dataset.dims)
image = self.dataset.zsum(indices=self.indices)
if self.dataset.transformation:
px = self.dataset.transformation[0][0][0]
py = self.dataset.transformation[1][0][0]
xscale = (self.dataset.transformation[0][-1][-1] - px) / len(self.dataset.transformation[0][0])
yscale = (self.dataset.transformation[1][-1][-1] - py) / len(self.dataset.transformation[1][0])
self.origin = (px, py)
self.scale = (xscale, yscale)
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
self._plot.addImage(image)
self.open()
self._widget.setDataset(*dataset)
else:
self._plot.clear()
self._widget._plot.clear()
self.open()
@Inputs.colormap
def setColormap(self, colormap):
self._plot.getImage().setColormap(colormap)
def _filterStack(self, dim=0, val=0):
image = self.dataset.zsum(indices=self.indices, dimension=[dim, val])
if image.shape[0]:
if self.origin:
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
else:
self._plot.clear()
def _wholeStack(self):
if self.origin:
self._plot.addImage(self.dataset.zsum(), origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(self.dataset.zsum(), xlabel='pixels', ylabel='pixels')
self._widget.setColormap(colormap)
......@@ -10,4 +10,5 @@ aliases = {
'orangecontrib.darfix.widgets.rockingcurves.RockingCurvesWidgetOW': 'darfix.core.process._RockingCurves',
'orangecontrib.darfix.widgets.grainplot.GrainPlotWidgetOW': 'darfix.core.process._GrainPlot',
'orangecontrib.darfix.widgets.transformation.TransformationWidgetOW': 'darfix.core.process._Transformation',
'orangecontrib.darfix.widgets.zsum.ZSumWidgetOW': 'darfix.core.process._ZSum',
}
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