umbmid/build.py
def import_metadata(gen='one'):
    """Load the metadata of each expt as a dict, return as list of dicts

    Loads the -metadata.csv files for each experimental session and
    creates a list of the metadata dict for each individual experiment.

    Parameters
    ----------
    gen : str
        The generation of data to import, must be in ['one', 'two']

    Returns
    -------
    metadata : list
        List of the metadata dict for each expt
    """

    assert gen in ['one', 'two', 'three'], \
        "Error: gen must be in ['one', 'two', 'three']"

    this_data_dir = os.path.join(__DATA_DIR, 'gen-%s/raw/' % gen)

    metadata = []  # Init list to return

    # For each experimental session in the dataset
    for expt_session in os.listdir(this_data_dir):

        # If the expt_session is a directory
        if os.path.isdir(os.path.join(this_data_dir, expt_session)):

            # Get the path to the -metadata.csv file for this
            # expt_session
            metadata_path = os.path.join(this_data_dir, expt_session,
                                         expt_session + '-metadata.csv')

            # Load the -metadata.csv file for this expt_session
            session_metadata = np.genfromtxt(metadata_path, delimiter=',',
                                             dtype=str)

            # Get the keys for the metadata
            metadata_keys = session_metadata[0, :]

            for md_key in metadata_keys:

                # Assert the metadata str is valid
                assert md_key in dtypes_dict.keys(), \
                    "Error: invalid metadata str %s in file %s" % (
                        md_key, metadata_path
                    )

            # For each individual scan within this expt_session
            for expt in range(1, np.size(session_metadata, axis=0)):

                # Get the metadata values (as str's) for this expt
                expt_metadata = session_metadata[expt, :]

                expt_metadata_dict = dict()  # Init dict for this expt

                # Create counter for the different pieces of metadata
                # info
                info_counter = 0

                # For each info piece in the metadata
                for info_piece in metadata_keys:

                    # If the value for this info piece is NOT missing
                    if not expt_metadata[info_counter] == '':

                        # Store the value as its proper dtype
                        expt_metadata_dict[info_piece] = \
                            dtypes_dict[info_piece](
                                expt_metadata[info_counter])

                    else:  # If the value for this info piece IS missing

                        assert info_piece in dtypes_dict.keys(), \
                                '%s not valid info-piece, in file: %s' \
                                % (info_piece, metadata_path)

                        # If the dtype for this info piece is an int
                        # or float, store as NaN
                        if (dtypes_dict[info_piece] == int or
                                dtypes_dict[info_piece] == float):

                            expt_metadata_dict[info_piece] = np.NaN

                        # If the dtype for this info piece is a str,
                        # store as empty str
                        else:
                            expt_metadata_dict[info_piece] = ''

                    info_counter += 1  # Increase the info counter

                # Append the metadata dict for this expt to the list
                metadata.append(expt_metadata_dict)

    return metadata
Load the metadata of each expt as a dict, return as list of dicts

    Loads the -metadata.csv files for each experimental session and
    creates a list of the metadata dict for each individual experiment.

    Parameters
    ----------
    gen : str
        The generation of data to import, must be in ['one', 'two']

    Returns
    -------
    metadata : list
        List of the metadata dict for each expt
    
Load the metadata of each expt as a dict, return as list of dicts
Loads the -metadata.csv files for each experimental session and
creates a list of the metadata dict for each individual experiment.
Load the metadata of each expt as a dict return as list of dicts Loads the - metadata . csv files for each experimental session and creates a list of the metadata dict for each individual experiment .
def import_metadata(gen='one'):
    assert gen in ['one', 'two', 'three'], \
        "Error: gen must be in ['one', 'two', 'three']"
    this_data_dir = os.path.join(__DATA_DIR, 'gen-%s/raw/' % gen)
    metadata = []  
    for expt_session in os.listdir(this_data_dir):
        if os.path.isdir(os.path.join(this_data_dir, expt_session)):
            metadata_path = os.path.join(this_data_dir, expt_session,
                                         expt_session + '-metadata.csv')
            session_metadata = np.genfromtxt(metadata_path, delimiter=',',
                                             dtype=str)
            metadata_keys = session_metadata[0, :]
            for md_key in metadata_keys:
                assert md_key in dtypes_dict.keys(), \
                    "Error: invalid metadata str %s in file %s" % (
                        md_key, metadata_path
                    )
            for expt in range(1, np.size(session_metadata, axis=0)):
                expt_metadata = session_metadata[expt, :]
                expt_metadata_dict = dict()  
                info_counter = 0
                for info_piece in metadata_keys:
                    if not expt_metadata[info_counter] == '':
                        expt_metadata_dict[info_piece] = \
                            dtypes_dict[info_piece](
                                expt_metadata[info_counter])
                    else:  
                        assert info_piece in dtypes_dict.keys(), \
                                '%s not valid info-piece, in file: %s' \
                                % (info_piece, metadata_path)
                        if (dtypes_dict[info_piece] == int or
                                dtypes_dict[info_piece] == float):
                            expt_metadata_dict[info_piece] = np.NaN
                        else:
                            expt_metadata_dict[info_piece] = ''
                    info_counter += 1  
                metadata.append(expt_metadata_dict)
    return metadata
def import_metadata ( gen = 'one' ) : assert gen in [ 'one' , 'two' , 'three' ] , "Error: gen must be in ['one', 'two', 'three']" this_data_dir = os . path . join ( __DATA_DIR , 'gen-%s/raw/' % gen ) metadata = [ ] for expt_session in os . listdir ( this_data_dir ) : if os . path . isdir ( os . path . join ( this_data_dir , expt_session ) ) : metadata_path = os . path . join ( this_data_dir , expt_session , expt_session + '-metadata.csv' ) session_metadata = np . genfromtxt ( metadata_path , delimiter = ',' , dtype = str ) metadata_keys = session_metadata [ 0 , : ] for md_key in metadata_keys : assert md_key in dtypes_dict . keys ( ) , "Error: invalid metadata str %s in file %s" % ( md_key , metadata_path ) for expt in range ( 1 , np . size ( session_metadata , axis = 0 ) ) : expt_metadata = session_metadata [ expt , : ] expt_metadata_dict = dict ( ) info_counter = 0 for info_piece in metadata_keys : if not expt_metadata [ info_counter ] == '' : expt_metadata_dict [ info_piece ] = dtypes_dict [ info_piece ] ( expt_metadata [ info_counter ] ) else : assert info_piece in dtypes_dict . keys ( ) , '%s not valid info-piece, in file: %s' % ( info_piece , metadata_path ) if ( dtypes_dict [ info_piece ] == int or dtypes_dict [ info_piece ] == float ) : expt_metadata_dict [ info_piece ] = np . NaN else : expt_metadata_dict [ info_piece ] = '' info_counter += 1 metadata . append ( expt_metadata_dict ) return metadata
Load the metadata of each expt as a dict, return as list of dicts
Loads the -metadata.csv files for each experimental session and
creates a list of the metadata dict for each individual experiment.
Load the metadata of each expt as a dict return as list of dicts Loads the - metadata . csv files for each experimental session and creates a list of the metadata dict for each individual experiment .
"""Load the metadata of each expt as a dict, return as list of dicts

    Loads the -metadata.csv files for each experimental session and
    creates a list of the metadata dict for each individual experiment.

    Parameters
    ----------
    gen : str
        The generation of data to import, must be in ['one', 'two']

    Returns
    -------
    metadata : list
        List of the metadata dict for each expt
    """ # Init list to return
 # For each experimental session in the dataset
 # If the expt_session is a directory
 # Get the path to the -metadata.csv file for this
 # expt_session
 # Load the -metadata.csv file for this expt_session
 # Get the keys for the metadata
 # Assert the metadata str is valid
 # For each individual scan within this expt_session
 # Get the metadata values (as str's) for this expt
 # Init dict for this expt
 # Create counter for the different pieces of metadata
 # info
 # For each info piece in the metadata
 # If the value for this info piece is NOT missing
 # Store the value as its proper dtype
 # If the value for this info piece IS missing
 # If the dtype for this info piece is an int
 # or float, store as NaN
 # If the dtype for this info piece is a str,
 # store as empty str
 # Increase the info counter
 # Append the metadata dict for this expt to the list

List of the metadata dict for each expt
List of the metadata dict for each expt
list

gen
The generation of data to import, must be in ['one', 'two']
The generation of data to import must be in [ ' one ' ' two ' ]