Commit ad013952 authored by payno's avatar payno

[refactoring] move tomwer.core.experiment.operation to tomwer.core.operation

- also remove one outdated unit test
parent aa10a212
......@@ -28,18 +28,20 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "01/10/2018"
import logging
from collections import OrderedDict
from silx.io import fabioh5
from silx.io.fabioh5 import FabioReader
import numpy
from id06workflow.core.operation import _BaseOperation
from id06workflow.core.operation.datareduction import DataReduction
from id06workflow.core.Dataset import Dataset
from id06workflow.core.geometry import GeometryBase
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.experiment.operation import _BaseOperation
from id06workflow.core.experiment.operation.roi import RoiOperation
from id06workflow.core.experiment.operation.datareduction import DataReduction
from collections import OrderedDict
from id06workflow.core.operation.roi import RoiOperation
from id06workflow.core.utils import metadata as metadatautils
from silx.io.fabioh5 import FabioReader
from silx.io import fabioh5
import numpy
import logging
_logger = logging.getLogger(__file__)
......
......@@ -42,79 +42,6 @@ class TestDataset(unittest.TestCase):
pass
class TestExperiement(unittest.TestCase):
"""Test behavior of :class:Experiment"""
def testApplyThreshod(self):
"""
Make sure the :func:`apply_threshold` is correctly applied
"""
dims = (100, 100)
pattern = numpy.arange(dims[0]*dims[1]).reshape(dims)
background = numpy.zeros(dims)
dataset = utils.createDataset(_dir=tempfile.mkdtemp(),
pattern=pattern,
background=background,
nb_data_files=10)
experiment = Experiment(dataset=dataset)
thRes = pattern.copy()
thRes[thRes < 20.0] = 0.0
back_sub_data = experiment.apply_threshold(threshold=20, lower=True,
replacement_value=0.0)
self.assertTrue(numpy.array_equal(back_sub_data[0], thRes))
thRes[thRes > 70.0] = 0.0
back_sub_data = experiment.apply_threshold(threshold=70, lower=False,
replacement_value=0.0)
self.assertTrue(numpy.array_equal(back_sub_data[0], thRes))
def testApplyBackgroundSubstraction(self):
"""
Make sure the :func:`apply_background_subtraction` is correctly applied
"""
dims = (100, 100)
pattern = numpy.zeros(dims)
background = numpy.random.random(dims)
dataset = utils.createDataset(_dir=tempfile.mkdtemp(),
pattern=pattern,
background=background,
nb_data_files=10,
nb_flat_field_files=1)
experiment = Experiment(dataset=dataset)
back_sub_data = experiment.apply_background_subtraction()
self.assertTrue(numpy.array_equal(back_sub_data[2], numpy.zeros(dims)))
back_sub_data = experiment.apply_background_subtraction()
self.assertTrue(numpy.array_equal(back_sub_data[3], numpy.zeros(dims)))
@unittest.skipUnless(os.path.exists('/nobackup/linazimov/payno/dev/esrf/ID06/dataset/for_mapping'), reason='Data files not available')
def testMapping(self):
# TODO: store datasets on the web and retrieve them using utils.getDataset()
_dir = '/nobackup/linazimov/payno/dev/esrf/ID06/dataset/for_mapping'
files = []
[files.append(os.path.join(_dir, _file)) for _file in os.listdir(_dir)]
dataset = Dataset(data_files_pattern=files)
geometry = TwoThetaGeometry(
twotheta=0.03, # for now those are defined in degree but should
# be defined in radians
xmag=1.0, # what is the unit of this ?
xpixelsize=1.0,
ypixelsize=1.0,
orientation=TwoThetaGeometry.VERTICAL)
experiment = Experiment(dataset=dataset, geometry=geometry)
experiment.roi = (750, 750), (600, 600)
dim = experiment.compute_dx2d_map()
self.assertTrue(dim is not None)
self.assertTrue(len(dim) is 1)
self.assertTrue(dim[0].shape == (274, 274, 4))
from id06workflow.gui.mapping import MappingPlot
from silx.gui import qt
app = qt.QApplication([])
widget = MappingPlot()
widget.setExperiment(experiment)
widget.show()
app.exec_()
class TestAcquisitionDims(unittest.TestCase):
"""
Test the AcquisitionDims API
......@@ -137,7 +64,7 @@ class TestAcquisitionDims(unittest.TestCase):
def suite():
test_suite = unittest.TestSuite()
for ui in (TestDataset, TestAcquisitionDims):
for ui in (TestDataset, TestAcquisitionDims,):
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(ui))
return test_suite
......
......@@ -28,11 +28,13 @@ __license__ = "MIT"
__date__ = "03/10/2018"
import unittest
import os
from id06workflow.core.experiment.operation.mapping import IntensityMapping
from id06workflow.core.experiment import Experiment, Dataset, POSITIONER_METADATA, _Dim
import unittest
from id06workflow.core.experiment import Experiment, Dataset, \
POSITIONER_METADATA, _Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.operation.mapping import IntensityMapping
@unittest.skipIf(os.path.exists('/nobackup/linazimov/payno/datasets/id06/strain_scan') is False, reason='data files not available')
......
......@@ -29,9 +29,11 @@ __date__ = "08/10/2018"
import unittest
from id06workflow.core.experiment.operation.noisereduction import MaskSubstraction
import numpy
from id06workflow.core.operation.noisereduction import MaskSubstraction
class TestMask(unittest.TestCase):
"""
......
......@@ -28,13 +28,17 @@ __license__ = "MIT"
__date__ = "03/10/2018"
import shutil
import tempfile
import unittest
from id06workflow.core.experiment.operation import OverwritingOperation, AdditiveOperation, shift
import numpy
from id06workflow.core.operation import OverwritingOperation, \
AdditiveOperation
from id06workflow.core.experiment import Experiment
from id06workflow.core.operation import shift
from id06workflow.test import utils
import shutil
import numpy
import tempfile
class TestOperation(unittest.TestCase):
......@@ -115,6 +119,7 @@ class TestShift(unittest.TestCase):
def testPracticalResult(self):
original_data = self.experiment.data.copy()
operation = shift.Shift(self.experiment, dx=1.0, dy=-1.0, dz=0)
shifted_data = operation.compute()
self.assertTrue(numpy.allclose(original_data[1, :-1, 1:],
......
......@@ -28,14 +28,17 @@ __license__ = "MIT"
__date__ = "21/11/2018"
import os
import unittest
from id06workflow.core.experiment import Experiment, Dataset, POSITIONER_METADATA
from id06workflow.core.operation.mapping import IntensityMapping, \
GradientRemoval
from id06workflow.core.experiment import Dataset, POSITIONER_METADATA
from id06workflow.core.experiment import Experiment, _Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.operation import noisereduction
from id06workflow.core.utils import metadata as metadatautils
from id06workflow.core.experiment.operation.mapping import IntensityMapping, GradientRemoval
from id06workflow.core.experiment.operation import noisereduction
from id06workflow.core.experiment import Experiment, _Dim
import os
@unittest.skipIf(os.path.exists('/nobackup/linazimov/payno/datasets/id06/strain_scan') is False, reason='data files not available')
......@@ -105,7 +108,7 @@ class TestOperationStream(unittest.TestCase):
lower=True, threshold=0.2)
ope_low_threshold.compute()
ope_high_threshold = noisereduction.ThresholdRemoval(self.experiment,
lower=False, threshold=10000.0)
lower=False, threshold=10000.0)
ope_high_threshold.compute()
ope_intensity_map = IntensityMapping(experiment=self.experiment)
ope_intensity_map.compute()
......
......@@ -28,11 +28,12 @@ __license__ = "MIT"
__date__ = "04/10/2018"
import logging
from collections import OrderedDict
from silx.gui import qt
from silx.gui.plot import Plot2D
from collections import OrderedDict
from id06workflow.core.experiment.operation.com import COM as COMOperation
import logging
from id06workflow.core.operation.com import COM as COMOperation
_logger = logging.getLogger(__file__)
......
......@@ -28,15 +28,17 @@ __license__ = "MIT"
__date__ = "10/10/2018"
import functools
import logging
from collections import OrderedDict
from silx.gui import qt
from silx.gui.plot import Plot2D
from id06workflow.core.mapping import MEAN, VARIANCE, SKEWNESS, KURTOSIS, MODES, \
INTENSITY
from id06workflow.core.operation.mapping import _MappingBase
from id06workflow.gui import icons
from id06workflow.core.mapping import MEAN, VARIANCE, SKEWNESS, KURTOSIS, MODES, INTENSITY
from id06workflow.core.experiment.operation.mapping import _MappingBase
from id06workflow.gui.settings import DEFAULT_COLORMAP
from collections import OrderedDict
import functools
import logging
_logger = logging.getLogger(__file__)
......
......@@ -28,15 +28,14 @@ __license__ = "MIT"
__date__ = "05/10/2018"
from collections import namedtuple
from silx.gui import qt
from silx.gui.plot.StackView import StackViewMainWindow
from id06workflow.core.experiment.operation import noisereduction
from id06workflow.gui.utils import _IllustrationWidget
from collections import namedtuple
from id06workflow.core.experiment import Experiment
from id06workflow.core.operation import noisereduction
from id06workflow.gui.settings import DEFAULT_COLORMAP
import copy
from id06workflow.gui.utils import _IllustrationWidget
_ReconsParams = namedtuple('_ReconsParam', ['scale'])
......
......@@ -28,15 +28,18 @@ __license__ = "MIT"
__date__ = "08/10/2018"
import logging
from functools import partial
from silx.gui import qt
from silx.gui.plot import Plot2D
from id06workflow.core.experiment.operation.shift import Shift as ShiftOperation
from id06workflow.core.experiment.operation.ThreadedOperation import ThreadedOperation
from id06workflow.core.image import guess_shift
from silx.gui.plot.StackView import StackViewMainWindow
from id06workflow.core.operation.ThreadedOperation import \
ThreadedOperation
from id06workflow.core.image import guess_shift
from id06workflow.core.operation.shift import Shift as ShiftOperation
from id06workflow.gui.settings import DEFAULT_COLORMAP
from functools import partial
import logging
_logger = logging.getLogger(__file__)
......
......@@ -28,15 +28,16 @@ __license__ = "MIT"
__date__ = "03/10/2018"
import unittest
import os
from id06workflow.core.experiment.operation.mapping import IntensityMapping
from id06workflow.gui.mapping import MappingPlot
from id06workflow.core.experiment import Experiment, Dataset, POSITIONER_METADATA, _Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from silx.gui.utils.testutils import TestCaseQt
import unittest
from silx.gui import qt
from id06workflow.core.experiment import Experiment, Dataset, \
POSITIONER_METADATA, _Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.operation.mapping import IntensityMapping
from id06workflow.gui.mapping import MappingPlot
app = qt.QApplication.instance() or qt.QApplication([])
# TODO: do it with TestCaseQt
......
......@@ -27,12 +27,14 @@ __authors__ = ["H.Payno"]
__license__ = "MIT"
__date__ = "15/05/2017"
import numpy
import fabio
import os
import tempfile
import fabio
import numpy
from id06workflow.core.experiment import Dataset
from id06workflow.core.experiment.operation.mapping import _MappingBase
import os
from id06workflow.core.operation.mapping import _MappingBase
def createRandomDataset(dims, nb_data_files=10, nb_dark_files=2,
......
......@@ -28,14 +28,17 @@ __license__ = "MIT"
__date__ = "18/10/2018"
import logging
from Orange.canvas.registry.description import OutputSignal, InputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import OutputSignal, InputSignal
from id06workflow.core.operation.mapping import _MappingBase
from id06workflow.core.experiment import Experiment
from id06workflow.core.experiment.operation.mapping import _MappingBase
from id06workflow.core.experiment.operation.com import COM as COMOperation
from id06workflow.core.operation.com import COM as COMOperation
from id06workflow.gui.com import ComWidget
import logging
_logger = logging.getLogger(__file__)
......
......@@ -28,15 +28,16 @@ __license__ = "MIT"
__date__ = "16/10/2018"
from Orange.canvas.registry.description import InputSignal, OutputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.experiment import Experiment
from id06workflow.core.experiment import _METADATA_TYPES_I
from id06workflow.core.mapping import MEAN, VARIANCE, SKEWNESS, KURTOSIS
from id06workflow.gui.mapping import MappingPlot
from id06workflow.core.experiment import Experiment
from id06workflow.core.experiment.operation.mapping import GradientRemoval, _MappingBase
from id06workflow.core.operation.mapping import GradientRemoval, _MappingBase
from id06workflow.core.types import _Image
from id06workflow.gui.mapping import MappingPlot
class GradientRemovalOW(OWWidget):
......
......@@ -27,18 +27,21 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "01/10/2018"
import logging
from functools import partial
from Orange.canvas.registry.description import InputSignal, OutputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.operation.mapping import IntensityMapping, \
_MappingBase
from id06workflow.core.experiment import Experiment
from id06workflow.core.experiment.operation.mapping import IntensityMapping, _MappingBase
from id06workflow.core.experiment.operation.ThreadedOperation import ThreadedOperation
from id06workflow.core.mapping import MEAN, VARIANCE, SKEWNESS, KURTOSIS
from id06workflow.core.experiment import _METADATA_TYPES_I
from id06workflow.core.mapping import MEAN, VARIANCE, SKEWNESS, KURTOSIS
from id06workflow.core.operation.ThreadedOperation import ThreadedOperation
from id06workflow.core.types import _Image
from id06workflow.gui.mapping import MappingPlot
from functools import partial
import logging
_logger = logging.getLogger(__file__)
......
......@@ -27,14 +27,17 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "02/10/2018"
import logging
from silx.gui import qt
from Orange.canvas.registry.description import InputSignal, OutputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from id06workflow.core.experiment import Experiment
from id06workflow.core.experiment.operation.roi import RoiOperation
from silx.gui import qt
from id06workflow.core.operation.roi import RoiOperation
from id06workflow.gui.roiselection import ROIOnStackView
import logging
_logger = logging.getLogger(__file__)
......
......@@ -27,15 +27,16 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "02/10/2018"
from Orange.widgets import gui
import logging
from silx.gui import qt
from Orange.widgets.widget import OWWidget
from Orange.canvas.registry.description import InputSignal, OutputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from id06workflow.core.experiment import Experiment
from id06workflow.core.types import _Image
from id06workflow.gui.shifcorrection import ShiftCorrectionWidget
from id06workflow.core.experiment.operation.shift import Shift
import logging
_logger = logging.getLogger(__file__)
......
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