Commit 326719c5 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[orangecontrib] Added data copy widget

parent ffc21045
Pipeline #13472 passed with stage
in 1 minute and 38 seconds
data copy
=========
![image](icons/upload.png)
Widget to select the dataset raw data and dark frames
Signals
-------
- Dataset
**Outputs**:
- Dataset
Description
-----------
TODO
\ No newline at end of file
......@@ -28,6 +28,7 @@ __authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "26/07/2019"
import copy
import numpy
import fabio
......@@ -60,8 +61,9 @@ class Dataset(qt.QObject):
self._data = None
self.dark_frames = []
self.raw_filename = raw_filename
self.dark_filename = dark_filename
self.filenames = filenames
self.progress = 0
self.dark_data = data
if data is not None:
if raw_filename is not None:
......@@ -91,7 +93,12 @@ class Dataset(qt.QObject):
self.dark_frames.append(dark_frame.data)
def startDataset(self):
"""
Function to be modified (or deleted).
For now it reads all data from the fabio file_series and create a list with
the data urls pointing to each file. It also uses the motor_pos column
from the header to obtain the motor positions and the dimensions.
"""
self.data_urls = []
self.motors_positions = []
with fabio.open_series(first_filename=self.raw_filename, filenames=self.filenames) as series:
......@@ -123,3 +130,15 @@ class Dataset(qt.QObject):
@data.setter
def data(self, data):
self._data = data
def __deepcopy__(self, memo):
"""
Create copy of the dataset. The data numpy array is also copied using
deep copy. The rest of the attributes are the same.
"""
dataset = type(self)(self.raw_filename, self.dark_filename, self.filenames, thread=True)
dataset.data_urls = self.data_urls
dataset.motors_positions = self.motors_positions
dataset.dimensions = self.dimensions
dataset.data = copy.deepcopy(self.data, memo)
return dataset
......@@ -44,7 +44,6 @@ def background_substraction(data, dark_frames, method='median'):
:returns: ndarray
:raises: ValueError
"""
background = numpy.zeros(data[0].shape, 'double')
if len(dark_frames):
dark_frames = numpy.asanyarray(dark_frames)
......@@ -64,7 +63,6 @@ def background_substraction(data, dark_frames, method='median'):
else:
raise ValueError("Invalid method specified. Please use `mean`, "
"or `median`.")
return data - background
......
......@@ -55,7 +55,7 @@ class BackgroundSubstractionWidget(qt.QWidget):
self._sv = StackViewMainWindow()
# TODO: modify lower bound after asking the beamline
self._sv.setColormap(Colormap(name='viridis', normalization='linear', vmin=0))
self._sv.setColormap(Colormap(name='viridis', normalization='linear'))
self._computeB = qt.QPushButton("Compute background substraction")
self.layout().addWidget(self._sv)
self.layout().addWidget(self._computeB)
......
......@@ -56,7 +56,7 @@ class ROISelectionWidget(qt.QWidget):
self._okB = qt.QPushButton("Ok", parent=self)
self._okB.pressed.connect(self.applyRoi)
self._okB.setEnabled(False)
self._sv.setColormap(Colormap(name='viridis', normalization='linear', vmin=0))
self._sv.setColormap(Colormap(name='viridis', normalization='linear'))
self.layout().addWidget(self._sv)
self.layout().addWidget(self._okB)
......
......@@ -58,7 +58,7 @@ class ShiftCorrectionWidget(qt.QWidget):
self.layout().addWidget(self._inputW)
self._sv = StackViewMainWindow()
self._sv.setColormap(Colormap(name='viridis', normalization='linear', vmin=0))
self._sv.setColormap(Colormap(name='viridis', normalization='linear'))
self.layout().addWidget(self._sv)
self._inputW.correctionB.clicked.connect(self.correct)
......
# 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__ = "08/08/2019"
import copy
from Orange.widgets.widget import OWWidget, Input, Output
from linkdick06.core.dataset import Dataset
class DataCopyWidgetOW(OWWidget):
"""
Widget that computes the background substraction from a dataset
"""
name = "data copy"
icon = "icons/copy.svg"
want_main_area = False
# Inputs
class Inputs:
dataset = Input("dataset", Dataset)
# Outputs
class Outputs:
dataset = Output("dataset", Dataset)
def __init__(self):
super().__init__()
@Inputs.dataset
def setDataset(self, dataset):
# Copy and send new dataset
cp_dataset = copy.deepcopy(dataset)
self.Outputs.dataset.send(cp_dataset)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
inkscape:version="0.92.1 r15371"
sodipodi:docname="copy.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.24748737"
inkscape:cx="-64.674017"
inkscape:cy="650.73943"
inkscape:document-units="mm"
inkscape:current-layer="g4974"
showgrid="false"
showguides="true"
inkscape:guide-bbox="true"
inkscape:window-width="1274"
inkscape:window-height="648"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="0">
<sodipodi:guide
position="-155.01633,349.58854"
orientation="1,0"
id="guide4867"
inkscape:locked="false" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="g4900"
transform="matrix(0.86529762,0,0,1,5.8042614,0)"
style="stroke-width:1.07502174" />
<g
id="g4931"
transform="translate(30.564772,24.947658)"
style="fill:#fffff9;fill-opacity:1">
<g
id="g4974"
transform="matrix(1.6445439,0,0,1.6422797,-12.783825,-3.1005464)"
style="stroke-width:0.60849035">
<g
id="g4991"
transform="translate(-5.8506818,-0.65097201)">
<g
style="fill:#ffffff;fill-opacity:1;stroke-width:0.41583765"
transform="translate(-30.564772,-24.947658)"
id="g4915">
<path
sodipodi:nodetypes="cccccc"
inkscape:connector-curvature="0"
d="M 43.089524,47.597359 V 130.86144 H 105.16989 L 105.3368,70.862716 85.744404,47.597359 Z"
style="fill:#ffffff;fill-opacity:1;stroke:#000001;stroke-width:2.79905558;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers fill stroke"
id="rect4852" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 55.753879,86.175759 c 36.160956,0 36.160956,0 36.160956,0"
id="path4865"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
id="path4869"
d="m 55.753878,99.539239 c 36.160957,0 36.160957,0 36.160957,0"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 55.753878,112.90272 c 36.160957,0 36.160957,0 36.160957,0"
id="path4871"
inkscape:connector-curvature="0" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 83.407897,72.496463 23.183753,-0.08639"
id="path4875"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path4902"
d="M 84.712578,72.0925 84.606457,46.273292"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
inkscape:connector-curvature="0"
id="path4893"
d="m 55.468826,72.545017 c 18.18547,0 18.18547,0 18.18547,0"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<path
id="path4917"
style="fill:#ffffff;fill-opacity:1;stroke:#000001;stroke-width:2.79905558;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:markers fill stroke"
d="M 43.089524,47.597359 V 130.86144 H 105.16989 L 105.3368,70.862716 85.744404,47.597359 Z"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
inkscape:connector-curvature="0"
id="path4919"
d="m 55.753879,86.175759 c 36.160956,0 36.160956,0 36.160956,0"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 55.753878,99.539239 c 36.160957,0 36.160957,0 36.160957,0"
id="path4921"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
id="path4923"
d="m 55.753878,112.90272 c 36.160957,0 36.160957,0 36.160957,0"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path4925"
d="m 83.3219,72.496463 23.31154,-0.08639"
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905581;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 84.712578,72.091564 84.606457,46.554938"
id="path4927"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2.79905558;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 55.468826,72.545017 c 18.18547,0 18.18547,0 18.18547,0"
id="path4929"
inkscape:connector-curvature="0" />
</g>
</g>
</g>
</g>
</svg>
......@@ -60,7 +60,7 @@ class BackgroundSubstractionWidgetOW(OWWidget):
self._widget.hideButton()
@Inputs.dataset
def set_dataset(self, dataset):
def setDataset(self, dataset):
if dataset:
self._widget.setDataset(dataset=dataset)
self._widget.computeBS()
......
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