Commit 308e3563 authored by payno's avatar payno
Browse files

[experiment] create AcquisitionDims class

- will be used to define the view to create on the data (using numpy view)
- allow to define dimension based on a kind and a name (to use the metadata)
- add unit test for this specific class
- link to experiement and creation of the view is not done yet
parent 6c06b725
......@@ -42,11 +42,6 @@ import logging
_logger = logging.getLogger(__file__)
_Dim = namedtuple('_Dim', ['name', 'size'])
# TODO: define dimension of the Experiment, with a get dim...
......@@ -56,6 +51,10 @@ POSITIONER_METADATA = FabioReader.POSITIONER
_Dim = namedtuple('_Dim', ['kind', 'name', 'size'])
# TODO: define dimension of the Experiment, with a get dim...
class Experiment(object):
Define all component of an experiment:
......@@ -77,7 +76,7 @@ class Experiment(object):
Which is different from the raw data contained in the dataset"""
self.__metadata = None
"""Metadata associated to the data. One per slice edf file header"""
self.__ndim = 1
self.__dims = AcquisitionDims()
"""Number of dimension of the experiment (motors scanned/rocked)
For now limited to 1
......@@ -170,6 +169,7 @@ class Experiment(object):
def data(self):
if self.__data is None:
self.__data = self.getRawData()
# TODO: create numpy view according to dims...
return self.__data
......@@ -291,3 +291,45 @@ class Experiment(object):
assert is 3
class AcquisitionDims(object):
Define the view of the data which has to be made
def __init__(self):
self.__dims = {}
def add_dim(self, axis, kind, name, size=None):
assert type(axis) is int
assert size is None or type(size) is int
self.__dims[axis] = _Dim(name=name, kind=kind, size=size)
def clear(self):
self.__dims = {}
def shape(self):
:return: shape of the currently defined dims
shape = []
max_index = -1
for index in self.__dims.keys():
max_index = max(max_index, index)
for iDim in range(max_index + 1):
if iDim not in self.__dims:
shape.append(self.__dims[iDim].size or -1)
return tuple(shape)
def set_size(self, axis, size):
if axis not in self.__dims:
_logger.error('axis %s is not defined yet, cannot defined a size '
'for it' % axis)
self.__dims[axis] = _Dim(self.__dims[axis].name,
......@@ -29,7 +29,7 @@ __date__ = "09/10/2018"
import unittest
from id06workflow.core.experiment import Experiment, Dataset
from id06workflow.core.experiment import Experiment, Dataset, AcquisitionDims
from id06workflow.core.geometry.TwoThetaGeometry import TwoThetaGeometry
from id06workflow.test import utils
import numpy
......@@ -115,9 +115,29 @@ class TestExperiement(unittest.TestCase):
class TestAcquisitionDims(unittest.TestCase):
Test the AcquisitionDims API
def test(self):
"""global test of the AcquisitionDims APi"""
acquiDim = AcquisitionDims()
self.assertTrue(acquiDim.shape == tuple())
acquiDim.add_dim(axis=0, kind='0', name='0', size=10)
acquiDim.add_dim(axis=1, kind='1', name='1')
self.assertTrue(acquiDim.shape == (10, -1))
acquiDim.set_size(axis=1, size=2)
self.assertTrue(acquiDim.shape == (10, 2))
self.assertTrue(acquiDim.shape == tuple())
acquiDim.add_dim(axis=1, kind='0', name='0', size=10)
acquiDim.add_dim(axis=4, kind='1', name='1')
self.assertTrue(acquiDim.shape == (1, 10, 1, 1, -1))
def suite():
test_suite = unittest.TestSuite()
for ui in (TestDataset, ):
for ui in (TestDataset, TestAcquisitionDims):
return test_suite
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