Commit 6d5dc956 authored by Thomas Vincent's avatar Thomas Vincent

code style

parent 50060d23
......@@ -46,9 +46,9 @@ class InvalidEntryError(Exception):
ScanPositions = namedtuple('ScanPositions',
['motor_0', 'pos_0', 'motor_1', 'pos_1', 'shape'])
MOTORCOLS = {"pix":"adcY",
"piy":"adcX",
"piz":"adcZ"}
MOTORCOLS = {"pix": "adcY",
"piy": "adcX",
"piz": "adcZ"}
def _process_entry(method):
......@@ -61,7 +61,6 @@ def _process_entry(method):
return _method
class XsocsH5(XsocsH5Base):
TOP_ENTRY = 'global'
......@@ -93,9 +92,8 @@ class XsocsH5(XsocsH5Base):
# when there is no attribute NX_class (should return the default
# None)
self.__entries = sorted([key for key in h5_file
if ('NX_class' in h5_file[key].attrs and
h5_file[key].attrs[
'NX_class'].decode() == 'NXentry')])
if ('NX_class' in h5_file[key].attrs and
h5_file[key].attrs['NX_class'].decode() == 'NXentry')])
def entries(self):
if self.__entries is None:
......@@ -152,7 +150,6 @@ class XsocsH5(XsocsH5Base):
"""
return self.__detector_params(entry, 'image_roi_offset')
@_process_entry
def n_images(self, entry):
# TODO : make sure that data.ndims = 3
......@@ -176,8 +173,9 @@ class XsocsH5(XsocsH5Base):
@_process_entry
def image_cumul(self, entry, dtype=None):
"""
Returns the summed intensity for each image.
"""Returns the summed intensity for each image.
:param str entry:
:param dtype: dtype passed to the numpy.sum function.
Default is numpy.double.
:type dtype: numpy.dtype
......@@ -226,12 +224,12 @@ class XsocsH5(XsocsH5Base):
@_process_entry
def is_regular_grid(self, entry):
# TODO
"""
For now grids are always regular
:param entry:
:return:
"""For now grids are always regular
:param str entry:
:rtype: bool
"""
# TODO
return True
@_process_entry
......@@ -331,8 +329,8 @@ class XsocsH5(XsocsH5Base):
class XsocsH5Writer(XsocsH5):
def __init__(self, h5_f, mode='a', **kwargs):
super(XsocsH5Writer, self).__init__(h5_f, mode=mode, **kwargs)
def __init__(self, h5_f, mode='a'):
super(XsocsH5Writer, self).__init__(h5_f, mode=mode)
def __set_detector_params(self, entry, params):
with self._get_file() as h5_file:
......@@ -399,7 +397,7 @@ class XsocsH5Writer(XsocsH5):
grp.attrs['interpretation'] = _np.string_('image')
# setting the nexus classes
#entry_grp.attrs['NX_class'] = _np.string_('NXentry')
# entry_grp.attrs['NX_class'] = _np.string_('NXentry')
grp = entry_grp.require_group('instrument')
grp.attrs['NX_class'] = _np.string_('NXinstrument')
......
......@@ -37,6 +37,22 @@ import h5py as _h5py
import numpy as _np
# We have to work around a limitation of the h5py.Group.copy method
# that fails when a group already exists in the destination file.
def _copy_obj(name, obj, src_grp=None, dest_grp=None):
if isinstance(obj, _h5py.Group):
dest_grp.require_group(name)
else:
src_grp.copy(name,
dest_grp,
name=name,
shallow=False,
expand_soft=True,
expand_external=True,
expand_refs=True,
without_attrs=False)
class XsocsH5Base(object):
# TODO : mechanism to test file type (isValid whatever)
......@@ -153,11 +169,10 @@ class XsocsH5Base(object):
dset[()] = value
def _set_array_data(self, path, value):
"""
Sets the given numpy array at the given path in this HDF5 file.
"""Sets the given numpy array at the given path in this HDF5 file.
:param path:
:param value:
:return:
"""
with self._get_file() as h5_f:
dset = h5_f.require_dataset(path,
......@@ -169,6 +184,7 @@ class XsocsH5Base(object):
"""
Creates a dataset as the given path. All extra arguments are passed
to h5py.DataSet.create_dataset.
:param path:
:param args:
:param kwargs:
......@@ -187,8 +203,8 @@ class XsocsH5Base(object):
@contextmanager
def item_context(self, item_path, **kwargs):
"""
Context manager for the image dataset.
"""Context manager for the image dataset.
WARNING: only to be used as a context manager!
WARNING: the data set must exist. see also QSpaceH5Writer.init_cube
"""
......@@ -202,26 +218,11 @@ class XsocsH5Base(object):
del item
def copy_group(self, src_h5f, src_path, dest_path):
"""
Recursively copies an object from one HDF5 file to another.
"""Recursively copies an object from one HDF5 file to another.
Warning : it fails if it finds a conflict with an already existing
dataset.
"""
# We have to work around a limitation of the h5py.Group.copy method
# that fails when a group already exists in the destination file.
def _copy_obj(name, obj, src_grp=None, dest_grp=None):
if isinstance(obj, _h5py.Group):
dest_grp.require_group(name)
else:
src_grp.copy(name,
dest_grp,
name=name,
shallow=False,
expand_soft=True,
expand_external=True,
expand_refs=True,
without_attrs=False)
with _h5py.File(src_h5f, 'r') as src_h5:
with self._get_file() as h5_file:
src_grp = src_h5[src_path]
......
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