Commit 9e886e0f authored by payno's avatar payno

[com] rework operation.Com amd Com gui to work with n dim

parent f7ea6c9f
......@@ -30,7 +30,7 @@ __date__ = "15/10/2018"
from . import AdditiveOperation
from .mapping import _MappingBase
from .mapping import _MappingBase, _IMap
from collections import namedtuple
import numpy
import logging
......@@ -53,22 +53,22 @@ class COM(AdditiveOperation):
AdditiveOperation.__init__(self, experiment=map.experiment,
name=COM._NAME)
self._map = map
self.__maps = []
self.__maps = {}
def key(self):
return COM._NAME
def compute(self):
assert self._map.ndim is 1
self.__maps = []
for dim in self._map.dims:
_map1 = dim[:, :, 0]
_map1 = _map1 - numpy.nan_to_num(_map1.mean())
_map2 = dim[:, :, 1]
_map2 = _map2 - numpy.nan_to_num(_map2.mean())
self.__maps.append(_MapsCom(map1=_map1, map2=_map2))
self.__maps = {}
for axis, _map in self._map.dims.items():
assert _map.mean.ndim is 2
_mean = _map.mean - numpy.nan_to_num(_map.mean.mean())
_variance = _map.variance - numpy.nan_to_num(_map.variance.mean())
_skewness = _map.skewness - numpy.nan_to_num(_map.skewness.mean())
_kurtosis = _map.kurtosis - numpy.nan_to_num(_map.kurtosis.mean())
self.__maps[axis] = _IMap(name=_map.name, kind=_map.kind,
mean=_mean, variance=_variance,
skewness=_skewness, kurtosis=_kurtosis)
self.registerOperation()
@property
......
......@@ -30,10 +30,9 @@ __date__ = "21/11/2018"
import os
import unittest
from id06workflow.core.operation.mapping import IntensityMapping, \
GradientRemoval
from id06workflow.core.operation.com import COM
from id06workflow.core.experiment import Dataset, POSITIONER_METADATA
from id06workflow.core.experiment import Experiment, Dim
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
......@@ -114,9 +113,9 @@ class TestOperationStream(unittest.TestCase):
ope_intensity_map.compute()
ope_gradient_removal = GradientRemoval(self.experiment)
ope_gradient_removal.compute()
ope_intensity_map_2 = IntensityMapping(experiment=self.experiment)
ope_intensity_map_2.compute()
com_operation = COM(map=ope_gradient_removal)
com_operation.compute()
# TODO: should be call at one moment if the 'project file' is not storing
# each results
# self.experiment.save('myProjectFile.h5')
......
......@@ -29,11 +29,11 @@ __date__ = "04/10/2018"
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
from id06workflow.core.operation.com import COM as COMOperation
from id06workflow.gui.settings import DEFAULT_COLORMAP
_logger = logging.getLogger(__file__)
......@@ -48,6 +48,7 @@ class ComWidget(qt.QWidget):
self._control = _ComControlWidget(parent=self)
self.layout().addWidget(self._control)
self._plot = Plot2D(parent=self)
self._plot.setDefaultColormap(DEFAULT_COLORMAP)
self.layout().addWidget(self._plot)
# connect signal
......@@ -64,30 +65,20 @@ class ComWidget(qt.QWidget):
def _update(self):
self._plot.clear()
dim = self._control.getDim()
_iMap = self._control.getMapType()
if dim >= 0:
# TODO: maps[dims] should be also a list with key values: 'value',
# 'mean', 'gradients' ...
if len(self._operation.maps[dim]) <= _iMap:
_logger.error('map of index %s has not been created' % _iMap)
self._plot.clear()
return
else:
_map = self._operation.maps[dim][_iMap]
self._plot.addImage(_map)
map_type = self._control.getMapType()
if dim is None:
return
class _ComControlWidget(qt.QWidget):
self._plot.clear()
try:
_map = getattr(self._operation.maps[dim], map_type)
self._plot.addImage(_map)
except Exception as e:
_logger.error(e)
_COM_VALUE = 'com value'
_COM_VARIANCE = 'com mean variance'
_COM_GRADIENTS = 'com gradients'
_MAP_TYPES = OrderedDict([
(_COM_VALUE, 0),
(_COM_VARIANCE, 1),
(_COM_GRADIENTS, 2)
])
class _ComControlWidget(qt.QWidget):
sigSelectionChanged = qt.Signal()
"""Signal emitted when the selection of the com change"""
......@@ -102,9 +93,9 @@ class _ComControlWidget(qt.QWidget):
self._map = qt.QComboBox(parent=self)
self.layout().addWidget(self._map)
# TODO: are those name correct ?
for map_type in (_ComControlWidget._MAP_TYPES):
for map_type in (MEAN, VARIANCE, SKEWNESS, KURTOSIS):
self._map.addItem(map_type)
index = self._map.findText(_ComControlWidget._COM_VALUE)
index = self._map.findText(MEAN)
assert index >= 0
self._map.setCurrentIndex(index)
......@@ -124,14 +115,12 @@ class _ComControlWidget(qt.QWidget):
def getDim(self):
currentDim = self._dim.currentText()
if currentDim == '':
return -1
return None
else:
return int(currentDim)
def getMapType(self):
currentMapType = self._map.currentText()
assert currentMapType in _ComControlWidget._MAP_TYPES
return _ComControlWidget._MAP_TYPES[currentMapType]
return self._map.currentText()
def __selectionChanged(self, *args, **kwargs):
self.sigSelectionChanged.emit()
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