Commit 8d48c1d9 authored by payno's avatar payno

[save image] add box to save "screenshots" of the processing

parent 46f62df7
......@@ -31,8 +31,7 @@ __date__ = "01/10/2018"
from id06workflow.core.Dataset import Dataset
from id06workflow.core.geometry import GeometryBase
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from silx.gui.plot.items.roi import RectangleROI
import collections
from collections import namedtuple
import numpy
import logging
......@@ -303,7 +302,13 @@ class Experiment(object):
def _resetDim(self):
self.__dim = []
for dim in range(self.ndim):
self.__dim.append(numpy.zeros((*(self.data.shape[1:]), 4)))
self.__dim.append(numpy.zeros((*(self.__data.shape[1:]), 4)))
class _Image(object):
def __init__(self, img, name):
self.img = img
self.name = name
def _save2D(_file, data):
......
......@@ -51,7 +51,7 @@ class MappingPlot(qt.QMainWindow):
self.setWindowFlags(qt.Qt.Widget)
self._plot = Plot2D(parent=self)
self._plot.setDefaultColormap(DEFAULT_COLORMAP)
self._plot.setDefaultColormap(DEFAULT_COLORMAP.copy())
self.setCentralWidget(self._plot)
self._data = {
......
......@@ -31,5 +31,5 @@ __date__ = "09/10/2018"
from silx.gui.colors import Colormap
DEFAULT_COLORMAP = Colormap(name='viridis', normalization='log',
DEFAULT_COLORMAP = Colormap(name='viridis', normalization='linear',
vmin=None, vmax=None)
......@@ -58,11 +58,11 @@ class ShiftCorrectionWidget(qt.QWidget):
self.layout().addWidget(self._displayTab)
self._stack = StackViewMainWindow()
self._stack.getPlot().setDefaultColormap(DEFAULT_COLORMAP)
self._stack.getPlot().setDefaultColormap(DEFAULT_COLORMAP.copy())
self._displayTab.addTab(self._stack, 'images')
self._sumPlot = Plot2D(parent=self)
self._sumPlot.setDefaultColormap(DEFAULT_COLORMAP)
self._sumPlot.setDefaultColormap(DEFAULT_COLORMAP.copy())
self._displayTab.addTab(self._sumPlot, 'images sum')
self._rawData = None
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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"
version="1.1"
viewBox="0 0 32 32"
xml:space="preserve"
id="svg2"
inkscape:version="0.48.5 r10040"
width="100%"
height="100%"
sodipodi:docname="document-save.svg"><metadata
id="metadata16"><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><defs
id="defs14" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1151"
inkscape:window-height="846"
id="namedview12"
showgrid="false"
inkscape:zoom="7.375"
inkscape:cx="16.271186"
inkscape:cy="16"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="0"
inkscape:current-layer="svg2" /><path
d="m 28.678339,28.104669 c 0,0.213237 -0.164027,0.387704 -0.364505,0.387704 H 12.992946 c -0.200478,0 -0.364505,-0.174467 -0.364505,-0.387704 V 11.811033 c 0,-0.213237 0.164027,-0.387704 0.364505,-0.387704 h 11.861732 c 0.200478,0 0.478231,0.125616 0.617472,0.279147 l 2.953223,3.257487 c 0.138512,0.15353 0.252966,0.453613 0.252966,0.66685 v 12.477856 z"
id="path4"
inkscape:connector-curvature="0" /><path
d="m 27.009634,25.87925 c 0,0.127942 -0.09842,0.232622 -0.218703,0.232622 H 14.759339 c -0.120287,0 -0.218703,-0.10468 -0.218703,-0.232622 v -5.439483 c 0,-0.127942 0.09842,-0.232622 0.218703,-0.232622 h 12.031592 c 0.120287,0 0.218703,0.10468 0.218703,0.232622 v 5.439483 z"
id="path6"
inkscape:connector-curvature="0"
style="fill:#ffffff" /><path
d="m 23.915713,15.598898 c 0,0.127943 -0.09842,0.232623 -0.218703,0.232623 h -8.937671 c -0.120287,0 -0.218703,-0.10468 -0.218703,-0.232623 v -4.194954 c 0,-0.127942 0.09842,-0.232622 0.218703,-0.232622 h 8.937671 c 0.120286,0 0.218703,0.10468 0.218703,0.232622 v 4.194954 z"
id="path8"
inkscape:connector-curvature="0"
style="fill:#ffffff" /><rect
x="19.903967"
y="11.423329"
width="1.5571667"
height="3.3164175"
id="rect10" /><text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Amiri;-inkscape-font-specification:Amiri"
x="1.6271186"
y="10.576271"
id="text2993"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2995"
x="1.6271186"
y="10.576271">IMG</tspan></text>
</svg>
\ No newline at end of file
<?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="48px"
height="48px"
id="svg2985"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="New document 2">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7"
inkscape:cx="0.14285714"
inkscape:cy="24"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="1920"
inkscape:window-height="1098"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<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
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<g
id="g3771"
transform="matrix(1.2503414,0,0,1.1053548,-4.3634184,-1.0610736)">
<path
sodipodi:cy="0"
sodipodi:cx="0"
sodipodi:r1="15.662252"
transform="matrix(0.33011688,0.25386519,-0.25440835,0.32941208,22.606349,35.476843)"
inkscape:transform-center-y="2.2205053"
inkscape:transform-center-x="-0.89254212"
d="M 9.7142863,12.285715 -2.891299,7.2778376 -15.496884,2.2699612 -4.8571427,-6.1428572 5.7825982,-14.555676 7.7484418,-1.1349804 z"
inkscape:randomized="0"
inkscape:rounded="0"
inkscape:flatsided="false"
sodipodi:arg2="1.9489509"
sodipodi:arg1="0.90175333"
sodipodi:r2="7.8311257"
sodipodi:sides="3"
id="path3763"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
sodipodi:type="star" />
<path
inkscape:connector-curvature="0"
id="path3765"
d="m 22.857143,33 0,-21.428571"
style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
</g>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Amiri;-inkscape-font-specification:Amiri"
x="7.8571429"
y="10.714286"
id="text3767"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3769"
x="7.8571429"
y="10.714286">Z sum</tspan></text>
</g>
</svg>
......@@ -30,7 +30,7 @@ __date__ = "01/10/2018"
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.types import Experiment
from id06workflow.core.types import Experiment, _Image
from id06workflow.gui.mapping import MappingPlot
import logging
......@@ -50,7 +50,8 @@ class MappingOW(OWWidget):
keywords = ["noise", "removal", "dataset", "filter"]
inputs = [InputSignal(name="data", handler='_process', type=Experiment)]
outputs = [OutputSignal(name="data", type=Experiment)]
outputs = [OutputSignal(name="data", type=Experiment),
OutputSignal(name="image", type=_Image)]
want_main_area = True
resizing_enabled = True
......@@ -72,3 +73,9 @@ class MappingOW(OWWidget):
except Exception as e:
_logger.error(e)
self.send("data", experiment)
# TODO: what can be the output image for the mapping ? for now all
self.send("image", _Image(experiment.intensity_map, 'intensity_map'))
self.send("image", _Image(experiment.dim[0][:, :, 0], 'mean'))
self.send("image", _Image(experiment.dim[0][:, :, 1], 'varaiance'))
self.send("image", _Image(experiment.dim[0][:, :, 2], 'skeness'))
self.send("image", _Image(experiment.dim[0][:, :, 3], 'kurtosis'))
......@@ -106,3 +106,4 @@ class RoiSelectionOW(OWWidget):
self.send("data", self._editedExperiment)
# except Exception as e:
# _logger.error(e)
# TODO: what can be the image to send to show roi selection (z sum ?)
# 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__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "10/10/2018"
import os
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal
from silx.gui.utils.image import convertArrayToQImage
from id06workflow.core.types import _Image
import logging
_logger = logging.getLogger(__file__)
class SaveImageOW(OWWidget):
"""
Save image to the folder defined in the os
"""
name = "save screen shot"
id = "orange.widgets.id06workflow.saveimage"
description = "save image to the folder defined in environment variable " \
"'WORKFLOW_OUTPUT'"
icon = "icons/save_img.svg"
priority = 8
category = "esrfWidgets"
keywords = ["dataset", "save"]
inputs = [InputSignal(name="image", type=_Image, handler='_process')]
want_main_area = False
resizing_enabled = True
compress_signal = False
def __init__(self):
super().__init__()
#TODO: display the current status of the experiment
self._experiment = None
def _process(self, image):
assert type(image is _Image)
output = os.environ.get('WORKFLOW_OUTPUT', '.')
_logger.info('save image to %s' % output)
qimage = convertArrayToQImage(image.data)
try:
qimage.save(os.path.join(output, image.name), 'PNG')
except Exception as e:
_logger.error(e)
......@@ -31,7 +31,7 @@ from Orange.widgets import gui
from silx.gui import qt
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.types import Experiment
from id06workflow.core.types import Experiment, _Image
from id06workflow.gui.shifcorrection import ShiftCorrectionWidget
import logging
......@@ -54,7 +54,8 @@ class ShiftCorrectionOW(OWWidget):
keywords = ["dataset", "shift", "correction"]
inputs = [InputSignal(name="data", type=Experiment, handler='_process')]
outputs = [OutputSignal(name="data", type=Experiment)]
outputs = [OutputSignal(name="data", type=Experiment),
OutputSignal(name="image", type=_Image)]
want_main_area = True
resizing_enabled = True
......@@ -101,4 +102,5 @@ class ShiftCorrectionOW(OWWidget):
self._editedExperiment.data = self._widget.getShiftedData()
self.send("data", self._editedExperiment)
self.send("image",
_Image(self._plot.getActiveImage(just_legend=False), 'shift_correction'))
......@@ -32,7 +32,7 @@ from silx.gui.plot import Plot2D
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.types import Experiment
from id06workflow.core.types import Experiment, _Image
from id06workflow.gui.settings import DEFAULT_COLORMAP
import logging
_logger = logging.getLogger(__file__)
......@@ -46,13 +46,14 @@ class ZSumPlotOW(OWWidget):
name = "z sum plot"
id = "orange.widgets.id06workflow.zsum"
description = "Display the data summed over the z axis"
icon = "icons/z_sum.svg"
priority = 8
category = "esrfWidgets"
keywords = ["dataset", "plot", "z", "sum"]
inputs = [InputSignal(name="data", type=Experiment, handler='_process')]
outputs = []
outputs = [OutputSignal(name="image", type=_Image)]
want_main_area = True
resizing_enabled = True
......@@ -71,3 +72,5 @@ class ZSumPlotOW(OWWidget):
self._plot.addImage(experiment.data.sum(axis=0))
else:
self._plot.clear()
self.send("image", _Image(self._plot.getActiveImage(just_legend=False), 'zsum'))
......@@ -56,12 +56,10 @@ class TestTrueData(OrangeWorflowTest):
'orangecontrib.id06workflow.widgets.datareduction.DataReductionOW')
roiSelectionNode = self.addWidget(
'orangecontrib.id06workflow.widgets.roiselection.RoiSelectionOW')
shiftCorrectionNode = self.addWidget(
'orangecontrib.id06workflow.widgets.shiftcorrection.ShiftCorrectionOW')
zSumNode = self.addWidget(
'orangecontrib.id06workflow.widgets.zsum.ZSumPlotOW')
noiseReductionNode = self.addWidget(
'orangecontrib.id06workflow.widgets.noisereduction.NoiseReductionOW')
shiftCorrectionNode = self.addWidget(
'orangecontrib.id06workflow.widgets.shiftcorrection.ShiftCorrectionOW')
mappingNode = self.addWidget(
'orangecontrib.id06workflow.widgets.mapping.MappingOW')
saveNode = self.addWidget(
......@@ -73,10 +71,9 @@ class TestTrueData(OrangeWorflowTest):
self.link(dataSelectionNode, "data", geometryNode, "data")
self.link(geometryNode, "data", dataReductionNode, "data")
self.link(dataReductionNode, "data", roiSelectionNode, "data")
self.link(roiSelectionNode, "data", shiftCorrectionNode, "data")
self.link(shiftCorrectionNode, "data", noiseReductionNode, "data")
self.link(shiftCorrectionNode, "data", zSumNode, "data")
self.link(noiseReductionNode, "data", mappingNode, "data")
self.link(roiSelectionNode, "data", noiseReductionNode, "data")
self.link(noiseReductionNode, "data", shiftCorrectionNode, "data")
self.link(shiftCorrectionNode, "data", mappingNode, "data")
self.link(mappingNode, "data", saveNode, "data")
self.processOrangeEvents()
......@@ -85,7 +82,6 @@ class TestTrueData(OrangeWorflowTest):
self._dataReductionWidget = self.getWidgetForNode(dataSelectionNode)
self._roiSelectionWidget = self.getWidgetForNode(roiSelectionNode)
self._shiftCorrectionWidget = self.getWidgetForNode(shiftCorrectionNode)
self._zSumWidget = self.getWidgetForNode(zSumNode)
self._noiseReductionWidget = self.getWidgetForNode(noiseReductionNode)
self._mappingWidget = self.getWidgetForNode(mappingNode)
self._saveWidget = self.getWidgetForNode(saveNode)
......@@ -106,7 +102,7 @@ class TestTrueData(OrangeWorflowTest):
def createDataset(self):
data_files = []
dir_data = '/users/payno/datasets/id06/strain_scan/strain/'
for _file in os.listdir(dir_data)[::10]:
for _file in os.listdir(dir_data)[::4]:
data_files.append(os.path.join(dir_data, _file))
ff_files = []
......@@ -147,6 +143,12 @@ class TestTrueData(OrangeWorflowTest):
self._roiSelectionWidget.hide()
self._moveToNextStep()
# manage noise reduction
self._noiseReductionWidget.validate()
self._shiftCorrectionWidget.hide()
self._moveToNextStep()
app.exec_()
# manage shift correction
self.assertTrue(self._shiftCorrectionWidget._editedExperiment is not None)
self._shiftCorrectionWidget.setShift(dx=0.0, dy=0.0, dz=0.0)
......@@ -154,12 +156,6 @@ class TestTrueData(OrangeWorflowTest):
self._shiftCorrectionWidget.hide()
self._moveToNextStep()
# manage noise reduction
self._noiseReductionWidget.validate()
self._shiftCorrectionWidget.hide()
self._moveToNextStep()
app.exec_()
def suite():
test_suite = unittest.TestSuite()
......
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