Commit f7ea6c9f authored by payno's avatar payno

[refactoring] core.experiment._Dim -> core.experiment.Dim

parent 2133963d
......@@ -356,7 +356,7 @@ class AcquisitionDims(object):
self.__dims = {}
def add_dim(self, axis, dim):
assert isinstance(dim, _Dim)
assert isinstance(dim, Dim)
self.__dims[axis] = dim
def clear(self):
......@@ -400,16 +400,16 @@ class AcquisitionDims(object):
_logger.error('axis %s is not defined yet, cannot defined a size '
'for it' % axis)
else:
self.__dims[axis] = _Dim(name=self.__dims[axis].name,
kind=self.__dims[axis].kind,
size=size)
self.__dims[axis] = Dim(name=self.__dims[axis].name,
kind=self.__dims[axis].kind,
size=size)
def __iter__(self):
for iAxis, dim in self.__dims.items():
yield (iAxis, dim)
class _Dim(object):
class Dim(object):
def __init__(self, kind, name, size=None, relative_prev_val=False):
"""
Define a dimension used during the experiment
......@@ -467,7 +467,7 @@ class _Dim(object):
def _setSize(self, size):
"""
.. note: having a setter was needed for GUI and Signal?SLOT stuff
(see :class:`_DimensionItem`)
(see :class:`DimensionItem`)
"""
self._size = size
......
......@@ -46,6 +46,11 @@ class _MappingBase(AdditiveOperation):
"""
@property
def dims(self):
"""
:return:
:rtype: dict with axis index as key, _IMap as value
"""
raise NotImplementedError('Base class')
@property
......@@ -149,6 +154,7 @@ class IntensityMapping(_MappingBase):
@property
def dims(self):
assert type(self.__dim) is dict
return self.__dim
@property
......@@ -211,6 +217,7 @@ class GradientRemoval(_MappingBase):
@property
def dims(self):
assert type(self.__dim) is dict
return self.__dim
@property
......
......@@ -29,7 +29,7 @@ __date__ = "09/10/2018"
import unittest
from id06workflow.core.experiment import AcquisitionDims, _Dim, DEFAULT_METADATA
from id06workflow.core.experiment import AcquisitionDims, Dim, DEFAULT_METADATA
class TestDataset(unittest.TestCase):
......@@ -45,15 +45,15 @@ class TestAcquisitionDims(unittest.TestCase):
"""global test of the AcquisitionDims APi"""
acquiDim = AcquisitionDims()
self.assertTrue(acquiDim.shape == (1, ))
acquiDim.add_dim(axis=0, dim=_Dim(kind=DEFAULT_METADATA, name='0', size=10))
acquiDim.add_dim(axis=1, dim=_Dim(kind=DEFAULT_METADATA, name='1'))
acquiDim.add_dim(axis=0, dim=Dim(kind=DEFAULT_METADATA, name='0', size=10))
acquiDim.add_dim(axis=1, dim=Dim(kind=DEFAULT_METADATA, name='1'))
self.assertTrue(acquiDim.shape == (10, -1))
acquiDim.set_size(axis=1, size=2)
self.assertTrue(acquiDim.shape == (10, 2))
acquiDim.clear()
self.assertTrue(acquiDim.shape == (1, ))
acquiDim.add_dim(axis=1, dim=_Dim(kind=DEFAULT_METADATA, name='0', size=10))
acquiDim.add_dim(axis=4, dim=_Dim(kind=DEFAULT_METADATA, name='1'))
acquiDim.add_dim(axis=1, dim=Dim(kind=DEFAULT_METADATA, name='0', size=10))
acquiDim.add_dim(axis=4, dim=Dim(kind=DEFAULT_METADATA, name='1'))
self.assertTrue(acquiDim.shape == (1, 10, 1, 1, -1))
......
......@@ -64,11 +64,11 @@ class TestShift(unittest.TestCase):
[ff_files.append(os.path.join(dir_ff, _file)) for _file in
os.listdir(dir_ff)]
dim1 = experiment._Dim(kind=experiment.POSITIONER_METADATA,
name='diffry', relative_prev_val=True,
size=31)
dim2 = experiment._Dim(kind=experiment.POSITIONER_METADATA,
name='obpitch')
dim1 = experiment.Dim(kind=experiment.POSITIONER_METADATA,
name='diffry', relative_prev_val=True,
size=31)
dim2 = experiment.Dim(kind=experiment.POSITIONER_METADATA,
name='obpitch')
self._dims = {0: dim1, 1: dim2}
return experiment.Dataset(data_files_pattern=data_file_pattern,
......
......@@ -32,7 +32,7 @@ import os
import unittest
from id06workflow.core.experiment import Experiment, Dataset, \
POSITIONER_METADATA, _Dim
POSITIONER_METADATA, Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.operation.mapping import IntensityMapping
......@@ -69,9 +69,9 @@ class TestMappingOperation(unittest.TestCase):
self.experiment = Experiment(dataset=self.dataset, geometry=geometry)
# define dimensions
dim1 = _Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = _Dim(kind=POSITIONER_METADATA, name='obpitch')
dim1 = Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = Dim(kind=POSITIONER_METADATA, name='obpitch')
self.experiment.set_dims(dims={0: dim1, 1: dim2})
def testIntensityMapping(self):
......
......@@ -35,7 +35,7 @@ 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.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
......@@ -70,9 +70,9 @@ class TestOperationStream(unittest.TestCase):
def applyDimsDef(self):
"""Apply experimentation dimension definition"""
dim1 = _Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = _Dim(kind=POSITIONER_METADATA, name='obpitch')
dim1 = Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = Dim(kind=POSITIONER_METADATA, name='obpitch')
self.experiment.set_dims(dims={0: dim1, 1: dim2})
def testDimensionManual(self):
......
......@@ -29,7 +29,7 @@ __date__ = "03/10/2018"
from silx.gui import qt
from id06workflow.core.experiment import _Dim, Experiment
from id06workflow.core.experiment import Dim, Experiment
from id06workflow.core.experiment import _METADATA_TYPES, _METADATA_TYPES_I, DEFAULT_METADATA
import logging
......@@ -87,7 +87,7 @@ class DimensionMapping(qt.QWidget):
"""
:param axis: which axis is defining this dimension
:param :class:_Dim dim: definition of the dimension to add
:param :class:Dim dim: definition of the dimension to add
"""
if axis is None:
axis = self._getNextFreeAxis()
......@@ -104,13 +104,13 @@ class DimensionMapping(qt.QWidget):
def setDims(self, dims):
"""
:param dict dims: axis as key and :class:`_Dim` as value
:param dict dims: axis as key and :class:`Dim` as value
:return:
"""
self.clear()
for axis, dim in dims.items():
assert type(axis) is int
assert isinstance(dim, _Dim)
assert isinstance(dim, Dim)
self.addDim(axis=axis, dim=dim)
def removeDim(self, row):
......@@ -214,7 +214,7 @@ class DimensionWidget(DimensionMapping):
"""
:param axis: which axis is defining this dimension
:param :class:_Dim dim: definition of the dimension to add
:param :class:`Dim` dim: definition of the dimension to add
"""
widget = super().addDim(axis, dim)
if self.__experiment is not None and len(self.__experiment.metadata) > 0:
......@@ -222,7 +222,7 @@ class DimensionWidget(DimensionMapping):
return widget
class _DimensionItem(_Dim, qt.QWidget):
class _DimensionItem(Dim, qt.QWidget):
"""Widget use to define a dimension"""
removed = qt.Signal(qt.QObject)
"""Signal emitted when the Item should be removed"""
......@@ -294,7 +294,7 @@ class _DimensionItem(_Dim, qt.QWidget):
:param int row: row position in the QTableWidget. Also used as ID
"""
qt.QWidget.__init__(self, parent)
_Dim.__init__(self, kind=DEFAULT_METADATA, name='')
Dim.__init__(self, kind=DEFAULT_METADATA, name='')
self.__metadata = None
......@@ -331,7 +331,7 @@ class _DimensionItem(_Dim, qt.QWidget):
self._kindCB.currentIndexChanged.connect(self._updateNames)
self._infoButton.pressed.connect(self.showUniqueNames)
# update values from _Dim
# update values from `Dim` class
self._kindCB.currentTextChanged.connect(self._setKind)
self._namesCB.currentTextChanged.connect(self._setName)
self._sizeWidget.valueChanged.connect(self._setSize)
......@@ -363,7 +363,7 @@ class _DimensionItem(_Dim, qt.QWidget):
self._infoButton.show()
def setDim(self, dim):
assert isinstance(dim, _Dim)
assert isinstance(dim, Dim)
_kind = _METADATA_TYPES_I[dim.kind]
idx = self._kindCB.findText(_kind)
assert idx >= 0
......@@ -397,8 +397,8 @@ class _DimensionItem(_Dim, qt.QWidget):
@property
def dim(self):
return _Dim(name=self.name, kind=self.kind, size=self.dimsize,
relative_prev_val=self.relative)
return Dim(name=self.name, kind=self.kind, size=self.dimsize,
relative_prev_val=self.relative)
@property
def dimsize(self):
......@@ -416,7 +416,7 @@ class _DimensionItem(_Dim, qt.QWidget):
return self._namesCB.currentText()
def _setSize(self, size):
_Dim._setSize(self, size)
Dim._setSize(self, size)
self._sizeWidget.setValue(size=size, editable=self.relative)
def setNames(self, names):
......
......@@ -33,7 +33,7 @@ import unittest
from silx.gui import qt
from id06workflow.core.experiment import Experiment, Dataset, \
POSITIONER_METADATA, _Dim
POSITIONER_METADATA, Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.core.operation.mapping import IntensityMapping
from id06workflow.gui.mapping import MappingPlot
......@@ -73,9 +73,9 @@ class TestMappingOperation(unittest.TestCase):
self.experiment = Experiment(dataset=self.dataset, geometry=geometry)
# define dimensions
dim1 = _Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = _Dim(kind=POSITIONER_METADATA, name='obpitch')
dim1 = Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = Dim(kind=POSITIONER_METADATA, name='obpitch')
self.experiment.set_dims(dims={0: dim1, 1: dim2})
self._widget = MappingPlot(parent=None)
......
......@@ -31,7 +31,7 @@ import unittest
from silx.gui import qt
from orangecontrib.id06workflow.test.OrangeWorkflowTest import OrangeWorflowTest
from id06workflow.core.experiment import Dataset, POSITIONER_METADATA
from id06workflow.core.experiment import _Dim
from id06workflow.core.experiment import Dim
from id06workflow.unitsystem import metricsystem
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
import os
......@@ -124,9 +124,9 @@ class TestTrueData(OrangeWorflowTest):
self.dataset = Dataset(data_files_pattern=data_file_pattern,
ff_files=data_bb_files)
dim1 = _Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = _Dim(kind=POSITIONER_METADATA, name='obpitch')
dim1 = Dim(kind=POSITIONER_METADATA, name='diffry',
relative_prev_val=True, size=31)
dim2 = Dim(kind=POSITIONER_METADATA, name='obpitch')
self._dims = {0: dim1, 1: dim2}
return self.dataset
......
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