NOAA-Omics / noaa-omics-templates

Documentation for study data templates developed by NOAA Omics
https://noaa-omics-templates.readthedocs.io
GNU Affero General Public License v3.0
2 stars 1 forks source link

Function to convert MIxS format (value + units) to numeric (value only) #10

Open lukenoaa opened 5 months ago

lukenoaa commented 5 months ago

Here is a Python function that works to convert MIxS format (value [space] units) to numeric (value only):

def mixs_to_numeric(value_plus_units):
    '''Takes a value with units after it (str) and returns only the numeric value (float)'''
    '''Does not support scientific notation (yet)'''
    '''Inputs containing no numerals or dash or period will return np.nan'''
    value_only = re.sub(r'([-\.0-9]*).*', r'\1', value_plus_units)
    if value_only == '':
        return(np.nan)
    else:
        return(float(value_only))

This could be integrated into Opal (issue #5) or a Python script that converts a MIxS-formatted sample data file and returns a fully machine-readable metadata file.

@ksilnoaa @Zenith2198