sidpy/hdf/reg_ref.py
def copy_reg_ref_reduced_dim(h5_source, h5_target, h5_source_inds,
                             h5_target_inds, key):
    """
    Copies a region reference from one dataset to another taking into account
    that a dimension has been lost from source to target

    Parameters
    ----------
    h5_source : HDF5 Dataset
            source dataset for region reference copy
    h5_target : HDF5 Dataset
            target dataset for region reference copy
    h5_source_inds : HDF5 Dataset
            indices of each dimension of the h5_source dataset
    h5_target_inds : HDF5 Dataset
            indices of each dimension of the h5_target dataset
    key : String
            Name of attribute in h5_source that contains
            the Region Reference to copy

    Returns
    -------
    ref_inds : Nx2x2 array of unsigned integers
            Array containing pairs of points that define
            the corners of each hyperslab in the region
            reference

    """
    for param, param_name in zip([h5_source, h5_target, h5_source_inds,
                                  h5_target_inds],
                                 ['h5_source', 'h5_target', 'h5_source_inds',
                                  'h5_target_inds']):
        if not isinstance(param, h5py.Dataset):
            raise TypeError(param_name + ' should be a h5py.Dataset object')
    if not isinstance(key, (str, unicode)):
        raise TypeError('key should be a string')
    key = key.strip()

    '''
    Determine which dimension is missing from the target
    '''
    lost_dim = []
    for dim in h5_source_inds.attrs['labels']:
        if dim not in h5_target_inds.attrs['labels']:
            lost_dim.append(np.where(h5_source_inds.attrs['labels'] == dim)[0])
    ref = h5_source.attrs[key]
    ref_inds = get_indices_for_region_ref(h5_source, ref,
                                          return_method='corners')
    '''
    Convert to proper spectroscopic dimensions
    First is special case for a region reference that spans the entire dataset
    '''
    if len(ref_inds.shape) == 2 and all(ref_inds[0] == [0, 0]) and all(ref_inds[1] + 1 == h5_source.shape):
        ref_inds[1, 1] = h5_target.shape[1] - 1
        ref_inds = np.expand_dims(ref_inds, 0)
    else:
        '''
    More common case of reference made of hyperslabs
        '''
        spec_ind_zeroes = np.where(h5_source_inds[lost_dim] == 0)[1]

        ref_inds = ref_inds.reshape([-1, 2, 2])

        for start, stop in ref_inds[:-1]:
            start[1] = np.where(start[1] == spec_ind_zeroes)[0]
            stop[1] = np.where(stop[1] == spec_ind_zeroes - 1)[0] - 1

        ref_inds[-1, 0, 1] = np.where(ref_inds[-1, 0, 1] == spec_ind_zeroes)[0]
        stop = np.where(ref_inds[-1, 1, 1] == spec_ind_zeroes - 1)[0]
        if stop.size == 0:
            stop = len(spec_ind_zeroes)
        ref_inds[-1, 1, 1] = stop - 1
    '''
    Create the new reference from the indices
    '''
    h5_target.attrs[key] = create_region_reference(h5_target, ref_inds)

    return ref_inds

    Copies a region reference from one dataset to another taking into account
    that a dimension has been lost from source to target

    Parameters
    ----------
    h5_source : HDF5 Dataset
            source dataset for region reference copy
    h5_target : HDF5 Dataset
            target dataset for region reference copy
    h5_source_inds : HDF5 Dataset
            indices of each dimension of the h5_source dataset
    h5_target_inds : HDF5 Dataset
            indices of each dimension of the h5_target dataset
    key : String
            Name of attribute in h5_source that contains
            the Region Reference to copy

    Returns
    -------
    ref_inds : Nx2x2 array of unsigned integers
            Array containing pairs of points that define
            the corners of each hyperslab in the region
            reference

    
Copies a region reference from one dataset to another taking into account
that a dimension has been lost from source to target

Parameters



Returns

ref_inds : Nx2x2 array of unsigned integers
Array containing pairs of points that define
the corners of each hyperslab in the region
reference
Copies a region reference from one dataset to another taking into account that a dimension has been lost from source to target Parameters Returns ref_inds : Nx2x2 array of unsigned integers Array containing pairs of points that define the corners of each hyperslab in the region reference
def copy_reg_ref_reduced_dim(h5_source, h5_target, h5_source_inds,
                             h5_target_inds, key):
    for param, param_name in zip([h5_source, h5_target, h5_source_inds,
                                  h5_target_inds],
                                 ['h5_source', 'h5_target', 'h5_source_inds',
                                  'h5_target_inds']):
        if not isinstance(param, h5py.Dataset):
            raise TypeError(param_name + ' should be a h5py.Dataset object')
    if not isinstance(key, (str, unicode)):
        raise TypeError('key should be a string')
    key = key.strip()
    lost_dim = []
    for dim in h5_source_inds.attrs['labels']:
        if dim not in h5_target_inds.attrs['labels']:
            lost_dim.append(np.where(h5_source_inds.attrs['labels'] == dim)[0])
    ref = h5_source.attrs[key]
    ref_inds = get_indices_for_region_ref(h5_source, ref,
                                          return_method='corners')
    if len(ref_inds.shape) == 2 and all(ref_inds[0] == [0, 0]) and all(ref_inds[1] + 1 == h5_source.shape):
        ref_inds[1, 1] = h5_target.shape[1] - 1
        ref_inds = np.expand_dims(ref_inds, 0)
    else:
        spec_ind_zeroes = np.where(h5_source_inds[lost_dim] == 0)[1]
        ref_inds = ref_inds.reshape([-1, 2, 2])
        for start, stop in ref_inds[:-1]:
            start[1] = np.where(start[1] == spec_ind_zeroes)[0]
            stop[1] = np.where(stop[1] == spec_ind_zeroes - 1)[0] - 1
        ref_inds[-1, 0, 1] = np.where(ref_inds[-1, 0, 1] == spec_ind_zeroes)[0]
        stop = np.where(ref_inds[-1, 1, 1] == spec_ind_zeroes - 1)[0]
        if stop.size == 0:
            stop = len(spec_ind_zeroes)
        ref_inds[-1, 1, 1] = stop - 1
    h5_target.attrs[key] = create_region_reference(h5_target, ref_inds)
    return ref_inds
def copy_reg_ref_reduced_dim ( h5_source , h5_target , h5_source_inds , h5_target_inds , key ) : for param , param_name in zip ( [ h5_source , h5_target , h5_source_inds , h5_target_inds ] , [ 'h5_source' , 'h5_target' , 'h5_source_inds' , 'h5_target_inds' ] ) : if not isinstance ( param , h5py . Dataset ) : raise TypeError ( param_name + ' should be a h5py.Dataset object' ) if not isinstance ( key , ( str , unicode ) ) : raise TypeError ( 'key should be a string' ) key = key . strip ( ) '''
    Determine which dimension is missing from the target
    ''' lost_dim = [ ] for dim in h5_source_inds . attrs [ 'labels' ] : if dim not in h5_target_inds . attrs [ 'labels' ] : lost_dim . append ( np . where ( h5_source_inds . attrs [ 'labels' ] == dim ) [ 0 ] ) ref = h5_source . attrs [ key ] ref_inds = get_indices_for_region_ref ( h5_source , ref , return_method = 'corners' ) '''
    Convert to proper spectroscopic dimensions
    First is special case for a region reference that spans the entire dataset
    ''' if len ( ref_inds . shape ) == 2 and all ( ref_inds [ 0 ] == [ 0 , 0 ] ) and all ( ref_inds [ 1 ] + 1 == h5_source . shape ) : ref_inds [ 1 , 1 ] = h5_target . shape [ 1 ] - 1 ref_inds = np . expand_dims ( ref_inds , 0 ) else : '''
    More common case of reference made of hyperslabs
        ''' spec_ind_zeroes = np . where ( h5_source_inds [ lost_dim ] == 0 ) [ 1 ] ref_inds = ref_inds . reshape ( [ - 1 , 2 , 2 ] ) for start , stop in ref_inds [ : - 1 ] : start [ 1 ] = np . where ( start [ 1 ] == spec_ind_zeroes ) [ 0 ] stop [ 1 ] = np . where ( stop [ 1 ] == spec_ind_zeroes - 1 ) [ 0 ] - 1 ref_inds [ - 1 , 0 , 1 ] = np . where ( ref_inds [ - 1 , 0 , 1 ] == spec_ind_zeroes ) [ 0 ] stop = np . where ( ref_inds [ - 1 , 1 , 1 ] == spec_ind_zeroes - 1 ) [ 0 ] if stop . size == 0 : stop = len ( spec_ind_zeroes ) ref_inds [ - 1 , 1 , 1 ] = stop - 1 '''
    Create the new reference from the indices
    ''' h5_target . attrs [ key ] = create_region_reference ( h5_target , ref_inds ) return ref_inds
Copies a region reference from one dataset to another taking into account
that a dimension has been lost from source to target
Copies a region reference from one dataset to another taking into account that a dimension has been lost from source to target
"""
    Copies a region reference from one dataset to another taking into account
    that a dimension has been lost from source to target

    Parameters
    ----------
    h5_source : HDF5 Dataset
            source dataset for region reference copy
    h5_target : HDF5 Dataset
            target dataset for region reference copy
    h5_source_inds : HDF5 Dataset
            indices of each dimension of the h5_source dataset
    h5_target_inds : HDF5 Dataset
            indices of each dimension of the h5_target dataset
    key : String
            Name of attribute in h5_source that contains
            the Region Reference to copy

    Returns
    -------
    ref_inds : Nx2x2 array of unsigned integers
            Array containing pairs of points that define
            the corners of each hyperslab in the region
            reference

    """ '''
    Determine which dimension is missing from the target
    ''' '''
    Convert to proper spectroscopic dimensions
    First is special case for a region reference that spans the entire dataset
    ''' '''
    More common case of reference made of hyperslabs
        ''' '''
    Create the new reference from the indices
    '''
h5_source
h5_target
h5_source_inds
h5_target_inds
key