sidpy/hdf/reg_ref.py
def clean_reg_ref(h5_dset, reg_ref_tuple, verbose=False):
    """
    Makes sure that the provided instructions for a region reference are indeed
    valid. This method has become necessary since h5py allows the writing of
    region references larger than the maxshape

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_tuple : list / tuple
        The slicing information formatted using tuples of slice objects.
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages

    Returns
    -------
    new_reg_refs : tuple
        Instructions for the corrected region reference
    """
    if not isinstance(reg_ref_tuple, (tuple, dict, slice)):
        raise TypeError('slices should be a tuple, list, or slice but is '
                        'instead of type {}'.format(type(reg_ref_tuple)))
    if not isinstance(h5_dset, h5py.Dataset):
        raise TypeError('h5_dset should be a h5py.Dataset object but is '
                        'instead of type {}'.format(type(h5_dset)))

    if isinstance(reg_ref_tuple, slice):
        # 1D dataset
        reg_ref_tuple = [reg_ref_tuple]

    if len(reg_ref_tuple) != len(h5_dset.shape):
        raise ValueError('Region reference tuple did not have the same '
                         'dimensions as the h5 dataset')

    if verbose:
        print('Comparing {} with h5 dataset maxshape of {}'
              ''.format(reg_ref_tuple, h5_dset.maxshape))

    new_reg_refs = list()

    for reg_ref_slice, max_size in zip(reg_ref_tuple, h5_dset.maxshape):
        if not isinstance(reg_ref_slice, slice):
            raise TypeError('slices should be a tuple or a list but is instead'
                            ' of type {}'.format(type(reg_ref_slice)))

        # For now we will simply make sure that the end of the slice is
        # <= maxshape
        if max_size is not None and reg_ref_slice.stop is not None:
            reg_ref_slice = slice(reg_ref_slice.start,
                                  min(reg_ref_slice.stop, max_size),
                                  reg_ref_slice.step)

        new_reg_refs.append(reg_ref_slice)

    if verbose:
        print('Region reference tuple now: {}'.format(new_reg_refs))

    return tuple(new_reg_refs)

    Makes sure that the provided instructions for a region reference are indeed
    valid. This method has become necessary since h5py allows the writing of
    region references larger than the maxshape

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_tuple : list / tuple
        The slicing information formatted using tuples of slice objects.
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages

    Returns
    -------
    new_reg_refs : tuple
        Instructions for the corrected region reference
    
Makes sure that the provided instructions for a region reference are indeed
valid. This method has become necessary since h5py allows the writing of
region references larger than the maxshape

Parameters

h5_dset : h5.Dataset instance
Dataset to which region references will be added as attributes
reg_ref_tuple : list / tuple
The slicing information formatted using tuples of slice objects.
verbose : Boolean (Optional. Default = False)
Whether or not to print status messages

Returns

new_reg_refs : tuple
Instructions for the corrected region reference
Makes sure that the provided instructions for a region reference are indeed valid . This method has become necessary since h5py allows the writing of region references larger than the maxshape Parameters h5_dset : h5 . Dataset instance Dataset to which region references will be added as attributes reg_ref_tuple : list / tuple The slicing information formatted using tuples of slice objects . verbose : Boolean ( Optional . Default = False ) Whether or not to print status messages Returns new_reg_refs : tuple Instructions for the corrected region reference
def clean_reg_ref(h5_dset, reg_ref_tuple, verbose=False):
    if not isinstance(reg_ref_tuple, (tuple, dict, slice)):
        raise TypeError('slices should be a tuple, list, or slice but is '
                        'instead of type {}'.format(type(reg_ref_tuple)))
    if not isinstance(h5_dset, h5py.Dataset):
        raise TypeError('h5_dset should be a h5py.Dataset object but is '
                        'instead of type {}'.format(type(h5_dset)))
    if isinstance(reg_ref_tuple, slice):
        reg_ref_tuple = [reg_ref_tuple]
    if len(reg_ref_tuple) != len(h5_dset.shape):
        raise ValueError('Region reference tuple did not have the same '
                         'dimensions as the h5 dataset')
    if verbose:
        print('Comparing {} with h5 dataset maxshape of {}'
              ''.format(reg_ref_tuple, h5_dset.maxshape))
    new_reg_refs = list()
    for reg_ref_slice, max_size in zip(reg_ref_tuple, h5_dset.maxshape):
        if not isinstance(reg_ref_slice, slice):
            raise TypeError('slices should be a tuple or a list but is instead'
                            ' of type {}'.format(type(reg_ref_slice)))
        if max_size is not None and reg_ref_slice.stop is not None:
            reg_ref_slice = slice(reg_ref_slice.start,
                                  min(reg_ref_slice.stop, max_size),
                                  reg_ref_slice.step)
        new_reg_refs.append(reg_ref_slice)
    if verbose:
        print('Region reference tuple now: {}'.format(new_reg_refs))
    return tuple(new_reg_refs)
def clean_reg_ref ( h5_dset , reg_ref_tuple , verbose = False ) : if not isinstance ( reg_ref_tuple , ( tuple , dict , slice ) ) : raise TypeError ( 'slices should be a tuple, list, or slice but is ' 'instead of type {}' . format ( type ( reg_ref_tuple ) ) ) if not isinstance ( h5_dset , h5py . Dataset ) : raise TypeError ( 'h5_dset should be a h5py.Dataset object but is ' 'instead of type {}' . format ( type ( h5_dset ) ) ) if isinstance ( reg_ref_tuple , slice ) : reg_ref_tuple = [ reg_ref_tuple ] if len ( reg_ref_tuple ) != len ( h5_dset . shape ) : raise ValueError ( 'Region reference tuple did not have the same ' 'dimensions as the h5 dataset' ) if verbose : print ( 'Comparing {} with h5 dataset maxshape of {}' '' . format ( reg_ref_tuple , h5_dset . maxshape ) ) new_reg_refs = list ( ) for reg_ref_slice , max_size in zip ( reg_ref_tuple , h5_dset . maxshape ) : if not isinstance ( reg_ref_slice , slice ) : raise TypeError ( 'slices should be a tuple or a list but is instead' ' of type {}' . format ( type ( reg_ref_slice ) ) ) if max_size is not None and reg_ref_slice . stop is not None : reg_ref_slice = slice ( reg_ref_slice . start , min ( reg_ref_slice . stop , max_size ) , reg_ref_slice . step ) new_reg_refs . append ( reg_ref_slice ) if verbose : print ( 'Region reference tuple now: {}' . format ( new_reg_refs ) ) return tuple ( new_reg_refs )
Makes sure that the provided instructions for a region reference are indeed
valid.
Makes sure that the provided instructions for a region reference are indeed valid .
"""
    Makes sure that the provided instructions for a region reference are indeed
    valid. This method has become necessary since h5py allows the writing of
    region references larger than the maxshape

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_tuple : list / tuple
        The slicing information formatted using tuples of slice objects.
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages

    Returns
    -------
    new_reg_refs : tuple
        Instructions for the corrected region reference
    """ # 1D dataset # For now we will simply make sure that the end of the slice is # <= maxshape
h5_dset
reg_ref_tuple
verbose