sidpy/hdf/reg_ref.py
def write_region_references(h5_dset, reg_ref_dict, add_labels_attr=True,
                            verbose=False):
    """
    Creates attributes of a h5py.Dataset that refer to regions in the dataset

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_dict : dict
        The slicing information must be formatted using tuples of slice objects
        . For example {'region_1':(slice(None, None), slice (0,1))}
    add_labels_attr : bool, optional, default = True
        Whether or not to write an attribute named 'labels' with the
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages
    """
    if not isinstance(reg_ref_dict, dict):
        raise TypeError('slices should be a dictionary but is instead of type '
                        '{}'.format(type(reg_ref_dict)))
    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 verbose:
        print('Starting to write Region References to Dataset', h5_dset.name,
              'of shape:', h5_dset.shape)
    for reg_ref_name, reg_ref_tuple in reg_ref_dict.items():
        if verbose:
            print('About to write region reference:', reg_ref_name, ':',
                  reg_ref_tuple)

        reg_ref_tuple = clean_reg_ref(h5_dset, reg_ref_tuple, verbose=verbose)

        h5_dset.attrs[reg_ref_name] = h5_dset.regionref[reg_ref_tuple]

        if verbose:
            print('Wrote Region Reference:%s' % reg_ref_name)

    '''
    Next, write these label names as an attribute called labels
    Now make an attribute called 'labels' that is a list of strings 
    First ascertain the dimension of the slicing:
    '''
    if add_labels_attr:
        found_dim = False
        dimen_index = None

        for key, val in reg_ref_dict.items():
            if not isinstance(val, (list, tuple)):
                reg_ref_dict[key] = [val]

        for dimen_index, slice_obj in enumerate(list(reg_ref_dict.values())[0]):
            # We make the assumption that checking the start is sufficient
            if slice_obj.start is not None:
                found_dim = True
                break
        if found_dim:
            headers = [None] * len(reg_ref_dict)
            # The list that will hold all the names
            for col_name in reg_ref_dict.keys():
                headers[reg_ref_dict[col_name][dimen_index].start] = col_name
            if verbose:
                print('Writing header attributes: {}'.format('labels'))
            # Now write the list of col / row names as an attribute:
            h5_dset.attrs['labels'] = clean_string_att(headers)
        else:
            warn('Unable to write region references for {}'
                 ''.format(h5_dset.name.split('/')[-1]))

        if verbose:
            print('Wrote Region References of Dataset {}'
                  ''.format(h5_dset.name.split('/')[-1]))

    Creates attributes of a h5py.Dataset that refer to regions in the dataset

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_dict : dict
        The slicing information must be formatted using tuples of slice objects
        . For example {'region_1':(slice(None, None), slice (0,1))}
    add_labels_attr : bool, optional, default = True
        Whether or not to write an attribute named 'labels' with the
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages
    
Creates attributes of a h5py.Dataset that refer to regions in the dataset
Parameters


Creates attributes of a h5py . Dataset that refer to regions in the dataset Parameters
def write_region_references(h5_dset, reg_ref_dict, add_labels_attr=True,
                            verbose=False):
    if not isinstance(reg_ref_dict, dict):
        raise TypeError('slices should be a dictionary but is instead of type '
                        '{}'.format(type(reg_ref_dict)))
    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 verbose:
        print('Starting to write Region References to Dataset', h5_dset.name,
              'of shape:', h5_dset.shape)
    for reg_ref_name, reg_ref_tuple in reg_ref_dict.items():
        if verbose:
            print('About to write region reference:', reg_ref_name, ':',
                  reg_ref_tuple)
        reg_ref_tuple = clean_reg_ref(h5_dset, reg_ref_tuple, verbose=verbose)
        h5_dset.attrs[reg_ref_name] = h5_dset.regionref[reg_ref_tuple]
        if verbose:
            print('Wrote Region Reference:%s' % reg_ref_name)
    if add_labels_attr:
        found_dim = False
        dimen_index = None
        for key, val in reg_ref_dict.items():
            if not isinstance(val, (list, tuple)):
                reg_ref_dict[key] = [val]
        for dimen_index, slice_obj in enumerate(list(reg_ref_dict.values())[0]):
            if slice_obj.start is not None:
                found_dim = True
                break
        if found_dim:
            headers = [None] * len(reg_ref_dict)
            for col_name in reg_ref_dict.keys():
                headers[reg_ref_dict[col_name][dimen_index].start] = col_name
            if verbose:
                print('Writing header attributes: {}'.format('labels'))
            h5_dset.attrs['labels'] = clean_string_att(headers)
        else:
            warn('Unable to write region references for {}'
                 ''.format(h5_dset.name.split('/')[-1]))
        if verbose:
            print('Wrote Region References of Dataset {}'
                  ''.format(h5_dset.name.split('/')[-1]))
def write_region_references ( h5_dset , reg_ref_dict , add_labels_attr = True , verbose = False ) : if not isinstance ( reg_ref_dict , dict ) : raise TypeError ( 'slices should be a dictionary but is instead of type ' '{}' . format ( type ( reg_ref_dict ) ) ) 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 verbose : print ( 'Starting to write Region References to Dataset' , h5_dset . name , 'of shape:' , h5_dset . shape ) for reg_ref_name , reg_ref_tuple in reg_ref_dict . items ( ) : if verbose : print ( 'About to write region reference:' , reg_ref_name , ':' , reg_ref_tuple ) reg_ref_tuple = clean_reg_ref ( h5_dset , reg_ref_tuple , verbose = verbose ) h5_dset . attrs [ reg_ref_name ] = h5_dset . regionref [ reg_ref_tuple ] if verbose : print ( 'Wrote Region Reference:%s' % reg_ref_name ) '''
    Next, write these label names as an attribute called labels
    Now make an attribute called 'labels' that is a list of strings 
    First ascertain the dimension of the slicing:
    ''' if add_labels_attr : found_dim = False dimen_index = None for key , val in reg_ref_dict . items ( ) : if not isinstance ( val , ( list , tuple ) ) : reg_ref_dict [ key ] = [ val ] for dimen_index , slice_obj in enumerate ( list ( reg_ref_dict . values ( ) ) [ 0 ] ) : if slice_obj . start is not None : found_dim = True break if found_dim : headers = [ None ] * len ( reg_ref_dict ) for col_name in reg_ref_dict . keys ( ) : headers [ reg_ref_dict [ col_name ] [ dimen_index ] . start ] = col_name if verbose : print ( 'Writing header attributes: {}' . format ( 'labels' ) ) h5_dset . attrs [ 'labels' ] = clean_string_att ( headers ) else : warn ( 'Unable to write region references for {}' '' . format ( h5_dset . name . split ( '/' ) [ - 1 ] ) ) if verbose : print ( 'Wrote Region References of Dataset {}' '' . format ( h5_dset . name . split ( '/' ) [ - 1 ] ) )
Creates attributes of a h5py.Dataset that refer to regions in the dataset
Parameters
Creates attributes of a h5py . Dataset that refer to regions in the dataset Parameters
"""
    Creates attributes of a h5py.Dataset that refer to regions in the dataset

    Parameters
    ----------
    h5_dset : h5.Dataset instance
        Dataset to which region references will be added as attributes
    reg_ref_dict : dict
        The slicing information must be formatted using tuples of slice objects
        . For example {'region_1':(slice(None, None), slice (0,1))}
    add_labels_attr : bool, optional, default = True
        Whether or not to write an attribute named 'labels' with the
    verbose : Boolean (Optional. Default = False)
        Whether or not to print status messages
    """ '''
    Next, write these label names as an attribute called labels
    Now make an attribute called 'labels' that is a list of strings 
    First ascertain the dimension of the slicing:
    ''' # We make the assumption that checking the start is sufficient # The list that will hold all the names # Now write the list of col / row names as an attribute:
h5_dset
reg_ref_dict
add_labels_attr
verbose