umbmid/build.py
def import_fd_cal_dataset(cal_type='emp', prune=True, gen='two', sparams='s11',
                          logger=null_logger):
    """Load the calibrated freq-domain s-params of each expt in dataset

    Loads the .txt raw data files of the measured S-parameters in the
    frequency domain for each scan, then subtracts off a calibration
    scan (either empty-chamber calibration or adipose calibration) and
    returns as an array

    Parameters
    ----------
    cal_type : str
        The type of calibration scan to subtract - expected to be in
        ['emp', 'adi']. If 'emp', uses an empty-chamber
        calibration scan, if 'adi' uses an adipose-only phantom
        calibration scan.
    prune : bool
        If True, will return an array containing only the scans that
        were of phantoms containing a fibroglandular component and that
        had a valid reference scan.
    gen : str
        Must be in ['one', 'two'], specifies the generation of data to
        import
    sparams : str
        The sparams to import, must be in ['s11', 's21']
    logger :
        Logger for logging progress

    Returns
    -------
    cal_dataset : array_like
        Array of calibrated data
    cal_metadata : list
        List of calibrated metadata
    """

    assert cal_type in ['emp', 'adi'], \
        "Error: cal_type must be in ['emp', 'adi']"

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

    assert sparams in ['s11', 's21'], \
        "Error: sparams must be in ['s11', 's21']"

    # If using an adipose-only phantom calibration scan
    if cal_type in ['adi']:
        cal_str = 'adi_ref_id'  # Set the cal_str to indicate this

    else:  # If using an empty-chamber calibration scan
        cal_str = 'emp_ref_id'  # Set the cal_str to indicate this

    # Load the freq-domain dataset
    fd_dataset = import_fd_dataset(sparams=sparams,
                                   gen=gen,
                                   logger=logger)

    # Import the metadata for the scans in the dataset
    metadata = import_metadata(gen=gen)

    cal_dataset = np.zeros_like(fd_dataset)  # Init array to return

    for expt_idx in range(len(metadata)):  # For each experiment

        # Get the metadata for this expt
        this_expt_metadata = metadata[expt_idx]

        # Get the unique_id number of the reference scan for this expt
        this_expt_ref_num = this_expt_metadata[cal_str]

        ref_idx = -1

        # Look through all other expts to find the expt with the
        # unique_id number matching the reference for expt_idx
        for second_expt_idx in range(len(metadata)):

            # If the unique_id of this second_expt matches the
            # unique_id of the reference
            if metadata[second_expt_idx]['id'] == this_expt_ref_num:

                # Assign this to be the temporary index of the
                # reference scan
                ref_idx = second_expt_idx

        # If the expt corresponding to expt_idx has a reference scan
        if not np.isnan(this_expt_ref_num):

            assert ref_idx >= 0, ('Error: no ref found for unique ID %d' %
                                  this_expt_metadata['id'])
            # Get the reference expt frequency-domain data for this
            # expt_idx
            ref_expt = fd_dataset[ref_idx, :, :]

            # Get the frequency-domain data for this expt_idx
            this_expt = fd_dataset[expt_idx, :, :]

            # Subtract the reference
            cal_dataset[expt_idx, :, :] = this_expt - ref_expt

    # If pruning the dataset to include scans that had a fibroglandular
    # component and had a valid calibration scan
    if prune:

        # Init lists for storing the samples in the pruned dataset and
        # the metadata of these samples
        pruned_dataset = []
        cal_metadata = []

        for expt_idx in range(len(metadata)):  # For each sample

            # If the phantom contains fibroglandular tissue AND has a
            # valid reference scan
            if ('F' in metadata[expt_idx]['phant_id'] and
                    not np.isnan(metadata[expt_idx][cal_str])):

                # Append this sample to the list of samples
                pruned_dataset.append(cal_dataset[expt_idx, :, :])
                cal_metadata.append(metadata[expt_idx])

        # Convert the dataset to an np array
        cal_dataset = np.reshape(pruned_dataset,
                                 [len(pruned_dataset),
                                  pruned_dataset[0].shape[0],
                                  pruned_dataset[0].shape[1]])

    else:  # If *NOT* pruning the dataset

        # Set the metadata to be returned as the metadata for all the
        # experiments
        cal_metadata = metadata

    return cal_dataset, cal_metadata
Load the calibrated freq-domain s-params of each expt in dataset

    Loads the .txt raw data files of the measured S-parameters in the
    frequency domain for each scan, then subtracts off a calibration
    scan (either empty-chamber calibration or adipose calibration) and
    returns as an array

    Parameters
    ----------
    cal_type : str
        The type of calibration scan to subtract - expected to be in
        ['emp', 'adi']. If 'emp', uses an empty-chamber
        calibration scan, if 'adi' uses an adipose-only phantom
        calibration scan.
    prune : bool
        If True, will return an array containing only the scans that
        were of phantoms containing a fibroglandular component and that
        had a valid reference scan.
    gen : str
        Must be in ['one', 'two'], specifies the generation of data to
        import
    sparams : str
        The sparams to import, must be in ['s11', 's21']
    logger :
        Logger for logging progress

    Returns
    -------
    cal_dataset : array_like
        Array of calibrated data
    cal_metadata : list
        List of calibrated metadata
    
Load the calibrated freq-domain s-params of each expt in dataset
Loads the .txt raw data files of the measured S-parameters in the
frequency domain for each scan, then subtracts off a calibration
scan (either empty-chamber calibration or adipose calibration) and
returns as an array
Load the calibrated freq - domain s - params of each expt in dataset Loads the . txt raw data files of the measured S - parameters in the frequency domain for each scan then subtracts off a calibration scan ( either empty - chamber calibration or adipose calibration ) and returns as an array
def import_fd_cal_dataset(cal_type='emp', prune=True, gen='two', sparams='s11',
                          logger=null_logger):
    assert cal_type in ['emp', 'adi'], \
        "Error: cal_type must be in ['emp', 'adi']"
    assert gen in ['one', 'two', 'three'], \
        "Error: gen must be in ['one', 'two', 'three']"
    assert sparams in ['s11', 's21'], \
        "Error: sparams must be in ['s11', 's21']"
    if cal_type in ['adi']:
        cal_str = 'adi_ref_id'  
    else:  
        cal_str = 'emp_ref_id'  
    fd_dataset = import_fd_dataset(sparams=sparams,
                                   gen=gen,
                                   logger=logger)
    metadata = import_metadata(gen=gen)
    cal_dataset = np.zeros_like(fd_dataset)  
    for expt_idx in range(len(metadata)):  
        this_expt_metadata = metadata[expt_idx]
        this_expt_ref_num = this_expt_metadata[cal_str]
        ref_idx = -1
        for second_expt_idx in range(len(metadata)):
            if metadata[second_expt_idx]['id'] == this_expt_ref_num:
                ref_idx = second_expt_idx
        if not np.isnan(this_expt_ref_num):
            assert ref_idx >= 0, ('Error: no ref found for unique ID %d' %
                                  this_expt_metadata['id'])
            ref_expt = fd_dataset[ref_idx, :, :]
            this_expt = fd_dataset[expt_idx, :, :]
            cal_dataset[expt_idx, :, :] = this_expt - ref_expt
    if prune:
        pruned_dataset = []
        cal_metadata = []
        for expt_idx in range(len(metadata)):  
            if ('F' in metadata[expt_idx]['phant_id'] and
                    not np.isnan(metadata[expt_idx][cal_str])):
                pruned_dataset.append(cal_dataset[expt_idx, :, :])
                cal_metadata.append(metadata[expt_idx])
        cal_dataset = np.reshape(pruned_dataset,
                                 [len(pruned_dataset),
                                  pruned_dataset[0].shape[0],
                                  pruned_dataset[0].shape[1]])
    else:  
        cal_metadata = metadata
    return cal_dataset, cal_metadata
def import_fd_cal_dataset ( cal_type = 'emp' , prune = True , gen = 'two' , sparams = 's11' , logger = null_logger ) : assert cal_type in [ 'emp' , 'adi' ] , "Error: cal_type must be in ['emp', 'adi']" assert gen in [ 'one' , 'two' , 'three' ] , "Error: gen must be in ['one', 'two', 'three']" assert sparams in [ 's11' , 's21' ] , "Error: sparams must be in ['s11', 's21']" if cal_type in [ 'adi' ] : cal_str = 'adi_ref_id' else : cal_str = 'emp_ref_id' fd_dataset = import_fd_dataset ( sparams = sparams , gen = gen , logger = logger ) metadata = import_metadata ( gen = gen ) cal_dataset = np . zeros_like ( fd_dataset ) for expt_idx in range ( len ( metadata ) ) : this_expt_metadata = metadata [ expt_idx ] this_expt_ref_num = this_expt_metadata [ cal_str ] ref_idx = - 1 for second_expt_idx in range ( len ( metadata ) ) : if metadata [ second_expt_idx ] [ 'id' ] == this_expt_ref_num : ref_idx = second_expt_idx if not np . isnan ( this_expt_ref_num ) : assert ref_idx >= 0 , ( 'Error: no ref found for unique ID %d' % this_expt_metadata [ 'id' ] ) ref_expt = fd_dataset [ ref_idx , : , : ] this_expt = fd_dataset [ expt_idx , : , : ] cal_dataset [ expt_idx , : , : ] = this_expt - ref_expt if prune : pruned_dataset = [ ] cal_metadata = [ ] for expt_idx in range ( len ( metadata ) ) : if ( 'F' in metadata [ expt_idx ] [ 'phant_id' ] and not np . isnan ( metadata [ expt_idx ] [ cal_str ] ) ) : pruned_dataset . append ( cal_dataset [ expt_idx , : , : ] ) cal_metadata . append ( metadata [ expt_idx ] ) cal_dataset = np . reshape ( pruned_dataset , [ len ( pruned_dataset ) , pruned_dataset [ 0 ] . shape [ 0 ] , pruned_dataset [ 0 ] . shape [ 1 ] ] ) else : cal_metadata = metadata return cal_dataset , cal_metadata
Load the calibrated freq-domain s-params of each expt in dataset
Loads the .txt raw data files of the measured S-parameters in the
frequency domain for each scan, then subtracts off a calibration
scan (either empty-chamber calibration or adipose calibration) and
returns as an array
Load the calibrated freq - domain s - params of each expt in dataset Loads the . txt raw data files of the measured S - parameters in the frequency domain for each scan then subtracts off a calibration scan ( either empty - chamber calibration or adipose calibration ) and returns as an array
"""Load the calibrated freq-domain s-params of each expt in dataset

    Loads the .txt raw data files of the measured S-parameters in the
    frequency domain for each scan, then subtracts off a calibration
    scan (either empty-chamber calibration or adipose calibration) and
    returns as an array

    Parameters
    ----------
    cal_type : str
        The type of calibration scan to subtract - expected to be in
        ['emp', 'adi']. If 'emp', uses an empty-chamber
        calibration scan, if 'adi' uses an adipose-only phantom
        calibration scan.
    prune : bool
        If True, will return an array containing only the scans that
        were of phantoms containing a fibroglandular component and that
        had a valid reference scan.
    gen : str
        Must be in ['one', 'two'], specifies the generation of data to
        import
    sparams : str
        The sparams to import, must be in ['s11', 's21']
    logger :
        Logger for logging progress

    Returns
    -------
    cal_dataset : array_like
        Array of calibrated data
    cal_metadata : list
        List of calibrated metadata
    """ # If using an adipose-only phantom calibration scan
 # Set the cal_str to indicate this
 # If using an empty-chamber calibration scan
 # Set the cal_str to indicate this
 # Load the freq-domain dataset
 # Import the metadata for the scans in the dataset
 # Init array to return
 # For each experiment
 # Get the metadata for this expt
 # Get the unique_id number of the reference scan for this expt
 # Look through all other expts to find the expt with the
 # unique_id number matching the reference for expt_idx
 # If the unique_id of this second_expt matches the
 # unique_id of the reference
 # Assign this to be the temporary index of the
 # reference scan
 # If the expt corresponding to expt_idx has a reference scan
 # Get the reference expt frequency-domain data for this
 # expt_idx
 # Get the frequency-domain data for this expt_idx
 # Subtract the reference
 # If pruning the dataset to include scans that had a fibroglandular
 # component and had a valid calibration scan
 # Init lists for storing the samples in the pruned dataset and
 # the metadata of these samples
 # For each sample
 # If the phantom contains fibroglandular tissue AND has a
 # valid reference scan
 # Append this sample to the list of samples
 # Convert the dataset to an np array
 # If *NOT* pruning the dataset
 # Set the metadata to be returned as the metadata for all the
 # experiments

Array of calibrated data
Array of calibrated data
array_like

List of calibrated metadata
List of calibrated metadata
list

cal_type
The type of calibration scan to subtract - expected to be in
['emp', 'adi']. If 'emp', uses an empty-chamber
calibration scan, if 'adi' uses an adipose-only phantom
calibration scan.
The type of calibration scan to subtract - expected to be in [ ' emp ' ' adi ' ] . If ' emp ' uses an empty - chamber calibration scan if ' adi ' uses an adipose - only phantom calibration scan .
prune
If True, will return an array containing only the scans that
were of phantoms containing a fibroglandular component and that
had a valid reference scan.
If True will return an array containing only the scans that were of phantoms containing a fibroglandular component and that had a valid reference scan .
gen
Must be in ['one', 'two'], specifies the generation of data to
import
Must be in [ ' one ' ' two ' ] specifies the generation of data to import
sparams
The sparams to import, must be in ['s11', 's21']
The sparams to import must be in [ ' s11 ' ' s21 ' ]
logger
Logger for logging progress
Logger for logging progress