Пример #1
0
def fix_one_sfl_line(data, header, cruise, gga=False, west=False):
    """Convert one line of SFL file into dict ready for db insert"""
    dbcolumn_to_fixed_data = {}

    for d, h in zip(data, header):
        h = h.upper()
        h = h.rstrip()
        d = d.rstrip()
        if h in FLOATS:
            h = h.strip().replace(' ', '_')
            try:
                dbcolumn_to_fixed_data[h] = float(d)
            except ValueError:
                dbcolumn_to_fixed_data[h] = None
        elif h in STRS:
            h = h.strip().replace(' ', '_')
            dbcolumn_to_fixed_data[h] = d
        # else, do nothing

    # add cruise, date, and add julian day if missing
    dbcolumn_to_fixed_data[CRUISE] = cruise
    if "DATE" in dbcolumn_to_fixed_data:
        # Input is an SFL converted from SDS which has a DATE column
        pass
    else:
        # Input is new style SFL where date is parsed from file
        dbcolumn_to_fixed_data[DATE] = date_from_file_name(
            dbcolumn_to_fixed_data[FILE])

    if len(dbcolumn_to_fixed_data[FILE].split("/")) == 1:
        # Add julian day directory if missing
        dbcolumn_to_fixed_data[FILE] = "/".join([
            julian_from_file_name(dbcolumn_to_fixed_data[FILE]),
            dbcolumn_to_fixed_data[FILE]
        ])

    # any fields that weren't passed in should be present and None
    for c in FILE_COLUMNS:
        if not c in dbcolumn_to_fixed_data:
            dbcolumn_to_fixed_data[c] = None

    # populate values dict
    values = {}
    for c in FILE_COLUMNS:
        values[c.lower()] = dbcolumn_to_fixed_data[c]
    # File column OCEAN_TEMP was misnamed to ocean_tmp in the sqlite3 sfl
    # table. Rather than fix this everywhere I'm going to just make sure
    # there is an ocean_tmp entry here.
    values["ocean_tmp"] = dbcolumn_to_fixed_data['OCEAN_TEMP']

    if values["lon"] is not None:
        if gga:
            values["lon"] = geo.gga2dd(values["lon"])
        if west:
            values["lon"] = geo.westify_dd_lon(values["lon"])
    if values["lat"] is not None and gga:
        values["lat"] = geo.gga2dd(values["lat"])

    return values
Пример #2
0
def fix_one_sfl_line(data, header, cruise, gga=False, west=False):
    """Convert one line of SFL file into dict ready for db insert"""
    dbcolumn_to_fixed_data = {}

    for d, h in zip(data, header):
        h = h.upper()
        h = h.rstrip()
        d = d.rstrip()
        if h in FLOATS:
            h = h.strip().replace(' ', '_')
            try:
                dbcolumn_to_fixed_data[h] = float(d)
            except ValueError:
                dbcolumn_to_fixed_data[h] = None
        elif h in STRS:
            h = h.strip().replace(' ', '_')
            dbcolumn_to_fixed_data[h] = d
        # else, do nothing

    # add cruise, date, and add julian day if missing
    dbcolumn_to_fixed_data[CRUISE] = cruise
    if "DATE" in dbcolumn_to_fixed_data:
        # Input is an SFL converted from SDS which has a DATE column
        pass
    else:
        # Input is new style SFL where date is parsed from file
        dbcolumn_to_fixed_data[DATE] = date_from_file_name(dbcolumn_to_fixed_data[FILE])

    if len(dbcolumn_to_fixed_data[FILE].split("/")) == 1:
        # Add julian day directory if missing
        dbcolumn_to_fixed_data[FILE] = "/".join([
            julian_from_file_name(dbcolumn_to_fixed_data[FILE]),
            dbcolumn_to_fixed_data[FILE]
        ])

    # any fields that weren't passed in should be present and None
    for c in FILE_COLUMNS:
        if not c in dbcolumn_to_fixed_data:
            dbcolumn_to_fixed_data[c] = None

    # populate values dict
    values = {}
    for c in FILE_COLUMNS :
        values[c.lower()] = dbcolumn_to_fixed_data[c]
    # File column OCEAN_TEMP was misnamed to ocean_tmp in the sqlite3 sfl
    # table. Rather than fix this everywhere I'm going to just make sure
    # there is an ocean_tmp entry here.
    values["ocean_tmp"] = dbcolumn_to_fixed_data['OCEAN_TEMP']

    if values["lon"] is not None:
        if gga:
            values["lon"] = geo.gga2dd(values["lon"])
        if west:
            values["lon"] = geo.westify_dd_lon(values["lon"])
    if values["lat"] is not None and gga:
        values["lat"] = geo.gga2dd(values["lat"])

    return values
Пример #3
0
def fix_coord(coord, gga=False, west=False):
    if coord:
        if gga:
            coord = geo.gga2dd(coord)
        if west:
            coord = geo.westify_dd_lon(coord)
    return coord
Пример #4
0
def fix_coord(coord, gga=False, west=False):
    if coord:
        if gga:
            coord = geo.gga2dd(coord)
        if west:
            coord = geo.westify_dd_lon(coord)
    return coord