Translate the results of metar.parse

    Keys: Wind, Visibility, Clouds, Temperature, Dewpoint, Altimeter, Other
777749
def metar(wxdata: MetarData, units: Units) -> MetarTrans:
    
    translations = shared(wxdata, units)
    translations['wind'] = wind(wxdata.wind_direction, wxdata.wind_speed,
                                wxdata.wind_gust, wxdata.wind_variable_direction,
                                units.wind_speed)
    translations['temperature'] = temperature(wxdata.temperature, units.temperature)
    translations['dewpoint'] = temperature(wxdata.dewpoint, units.temperature)
    translations['remarks'] = remarks.translate(wxdata.remarks)  # type: ignore
    return MetarTrans(**translations)
615072
def formatted(self):
    '''  '''

    return """
Weather Station: %s (%s, %s)
Elevation: %s m
Time: %s UTC
Air Temperature: %s C (%s F)
Wind Speed: %s m/s (%s mph)
Wind Direction: %s
Present Weather Obs: %s
Precipitation: %s
Cloud Coverage: %s oktas
Cloud Summation: %s
Solar Irradiance: %s 
    """ % (self.weather_station, self.latitude, self.longitude,
           self.elevation, self.datetime, self.air_temperature,
           self.air_temperature.get_fahrenheit(), self.wind_speed,
           self.wind_speed.get_miles(), self.wind_direction,
           str(self.present_weather), str(self.precipitation),
           str(self.sky_cover), str(self.sky_cover_summation),
           str(self.solar_irradiance))
1086570
def translate(remarks: str) -> typing.Dict[str, str]:  # noqa
    
    ret = {}
    # Add and replace static multi-word elements
    for key in REMARKS_GROUPS:
        if key in remarks:
            ret[key.strip()] = REMARKS_GROUPS[key]
            remarks.replace(key, ' ')
    # For each remaining element
    for rmk in remarks.split()[1:]:
        rlen = len(rmk)
        # Static single-word elements
        if rmk in REMARKS_ELEMENTS:
            ret[rmk] = REMARKS_ELEMENTS[rmk]
        # Digit-only encoded elements
        elif rmk.isdigit():
            if rlen == 5 and rmk[0] in LEN5_DECODE:
                rmk_ = LEN5_DECODE[rmk[0]](rmk)  # type: ignore
                ret[rmk] = rmk_
            # 24-hour min/max temperature
            elif rlen == 9:
                ret[rmk] = f'24-hour temperature: max {_tdec(rmk[1:5])} min {_tdec(rmk[5:])}'
        # Sea level pressure: SLP218
        elif rmk.startswith('SLP'):
            ret[rmk] = f'Sea level pressure: 10{rmk[3:5]}.{rmk[5]} hPa'
        # Temp/Dew with decimal: T02220183
        elif rlen == 9 and rmk[0] == 'T' and rmk[1:].isdigit():
            ret[rmk] = f'Temperature {_tdec(rmk[1:5])} and dewpoint {_tdec(rmk[5:])}'
        # Precipitation amount: P0123
        elif rlen == 5 and rmk[0] == 'P' and rmk[1:].isdigit():
            ret[rmk] = f'Hourly precipitation: {int(rmk[1:3])}.{rmk[3:]} in.'
        # Weather began/ended
        elif rlen == 5 and rmk[2] in ('B', 'E') and rmk[3:].isdigit() and rmk[:2] in WX_TRANSLATIONS:
            state = 'began' if rmk[2] == 'B' else 'ended'
            ret[rmk] = f'{WX_TRANSLATIONS[rmk[:2]]} {state} at :{rmk[3:]}'
    return ret
188041
def __convert_keys_2(header, d):
        
        d_out = {}
        try:
            for k, v in d.items():
                try:
                    noaa_key = LIPD_NOAA_MAP_BY_SECTION[header][k]
                    d_out[noaa_key] = v
                except Exception:
                    logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: ran into an error converting {}".format(k))
        except KeyError:
            logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: KeyError: header key {} is not in NOAA_ALL_DICT".format(header))
        except AttributeError:
            logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: AttributeError: metdata is wrong data type".format(header))
            return d
        return d_out
96564
def _get_coarse_dataset(self, key, info):
        """"""
        angles = self.root.find('.//Tile_Angles')
        if key in ['solar_zenith_angle', 'solar_azimuth_angle']:
            elts = angles.findall(info['xml_tag'] + '/Values_List/VALUES')
            return np.array([[val for val in elt.text.split()] for elt in elts],
                            dtype=np.float)

        elif key in ['satellite_zenith_angle', 'satellite_azimuth_angle']:
            arrays = []
            elts = angles.findall(info['xml_tag'] + '[@bandId="1"]')
            for elt in elts:
                items = elt.findall(info['xml_item'] + '/Values_List/VALUES')
                arrays.append(np.array([[val for val in item.text.split()] for item in items],
                                       dtype=np.float))
            return np.nanmean(np.dstack(arrays), -1)
        else:
            return
661041
def translate_labels(val):
    '''
    
    '''
    if not isinstance(val, dict):
        if not isinstance(val, list):
            val = split(val)
        new_val = {}
        for item in val:
            if isinstance(item, dict):
                if len(item) != 1:
                    raise SaltInvocationError('Invalid label(s)')
                key = next(iter(item))
                val = item[key]
            else:
                try:
                    key, val = split(item, '=', 1)
                except ValueError:
                    key = item
                    val = ''
            if not isinstance(key, six.string_types):
                key = six.text_type(key)
            if not isinstance(val, six.string_types):
                val = six.text_type(val)
            new_val[key] = val
        val = new_val
    return val
42230
def _parse_supl(content):
        
        col_names = ['year', 'month', 'day', 'hour', 'minute',
                     'hourly_low_pressure', 'hourly_low_pressure_time',
                     'hourly_high_wind', 'hourly_high_wind_direction',
                     'hourly_high_wind_time']

        col_units = {'hourly_low_pressure': 'hPa',
                     'hourly_low_pressure_time': None,
                     'hourly_high_wind': 'meters/second',
                     'hourly_high_wind_direction': 'degrees',
                     'hourly_high_wind_time': None,
                     'time': None}

        df = pd.read_table(StringIO(content), comment='#', na_values='MM',
                           names=col_names, sep=r'\s+')

        df['time'] = pd.to_datetime(df[['year', 'month', 'day', 'hour', 'minute']], utc=True)

        df['hours'] = np.floor(df['hourly_low_pressure_time'] / 100)
        df['minutes'] = df['hourly_low_pressure_time'] - df['hours'] * 100
        df['hours'] = df['hours'].replace(99, np.nan)
        df['minutes'] = df['minutes'].replace(99, np.nan)
        df['hourly_low_pressure_time'] = pd.to_datetime(df[['year', 'month', 'day', 'hours',
                                                            'minutes']], utc=True)

        df['hours'] = np.floor(df['hourly_high_wind_time'] / 100)
        df['minutes'] = df['hourly_high_wind_time'] - df['hours'] * 100
        df['hours'] = df['hours'].replace(99, np.nan)
        df['minutes'] = df['minutes'].replace(99, np.nan)
        df['hourly_high_wind_time'] = pd.to_datetime(df[['year', 'month', 'day',
                                                         'hours', 'minutes']], utc=True)
        df = df.drop(columns=['year', 'month', 'day', 'hour', 'minute', 'hours', 'minutes'])
        df.units = col_units
        return df
349123
def from_json(cls, data):
        
        # Check required and optional keys
        optional_keys = {'wind_direction': 0, 'rain': False, 'snow_on_ground': False}
        assert 'wind_speed' in data, 'Required key "wind_speed" is missing!'
        for key, val in optional_keys.items():
            if key not in data:
                data[key] = val

        return cls(data['wind_speed'], data['wind_direction'], data['rain'],
                   data['snow_on_ground'])
1022077
function translateOptions(cliOptions) {
  return {
    config: cliOptions.config,
    output: cliOptions.output,
    watch : cliOptions.watch
  };
}
1001214
def __parse_loc_data(loc_data, result):
    """"""
    result[DATA] = {ATTRIBUTION: ATTRIBUTION_INFO,
                    FORECAST: [],
                    PRECIPITATION_FORECAST: None}

    for key, [value, func] in SENSOR_TYPES.items():
        result[DATA][key] = None
        try:
            sens_data = loc_data[value]
            if key == CONDITION:
                # update weather symbol & status text
                desc = loc_data[__WEATHERDESCRIPTION]
                result[DATA][CONDITION] = __cond_from_desc(desc)
                result[DATA][CONDITION][IMAGE] = loc_data[__ICONURL]
                continue
            if key == STATIONNAME:
                result[DATA][key] = __getStationName(loc_data[__STATIONNAME],
                                                     loc_data[__STATIONID])
                continue
            # update all other data:
            if func is not None:
                result[DATA][key] = func(sens_data)
            else:
                result[DATA][key] = sens_data
        except KeyError:
            if result[MESSAGE] is None:
                result[MESSAGE] = "Missing key(s) in br data: "
            result[MESSAGE] += "%s " % value
            log.warning("Data element with key='%s' "
                        "not loaded from br data!", key)
    result[SUCCESS] = True
    return result
17731
def get_weather(conn, geometry, year):
    
    """
    rename_dc = {
        'ASWDIFD_S': 'dhi',
        'ASWDIR_S': 'dirhi',
        'PS': 'pressure',
        'T_2M': 'temp_air',
        'WSS_10M': 'v_wind',
        'Z0': 'z0'}

    if geometry.geom_type in ['Polygon', 'MultiPolygon']:
        # Create MultiWeather
        # If polygon covers only one data set switch to SingleWeather
        sql_part = """
            SELECT sp.gid, ST_AsText(point.geom), ST_AsText(sp.geom)
            FROM coastdat.cosmoclmgrid AS sp
            JOIN coastdat.spatial AS point ON (sp.gid=point.gid)
            WHERE st_intersects(ST_GeomFromText('{wkt}',4326), sp.geom)
            """.format(wkt=geometry.wkt)
        df = fetch_raw_data(sql_weather_string(year, sql_part), conn, geometry)
        obj = create_multi_weather(df, rename_dc)
    elif geometry.geom_type == 'Point':
        # Create SingleWeather
        sql_part = """
            SELECT sp.gid, ST_AsText(point.geom), ST_AsText(sp.geom)
            FROM coastdat.cosmoclmgrid AS sp
            JOIN coastdat.spatial AS point ON (sp.gid=point.gid)
            WHERE st_contains(sp.geom, ST_GeomFromText('{wkt}',4326))
            """.format(wkt=geometry.wkt)
        df = fetch_raw_data(sql_weather_string(year, sql_part), conn, geometry)
        obj = create_single_weather(df, rename_dc)
    else:
        logging.error('Unknown geometry type: {0}'.format(geometry.geom_type))
        obj = None
    return obj
1091511
def __parse(self):
        
        logger_noaa_lpd.info("enter parse")

        # Strings
        missing_str = ''
        data_filename = ''

        # Counters
        grant_id = 0
        funding_id = 0
        data_col_ct = 1
        line_num = 0

        # Boolean markers
        description_on = False
        publication_on = False
        abstract_on = False
        site_info_on = False
        chronology_on = False
        chron_vals_on = False
        variables_on = False
        data_vals_on = False
        data_on = False

        # Lists
        lat = []
        lon = []
        elev = []
        pub = []
        funding = []
        temp_abstract = []
        temp_description = []
        data_var_names = []
        data_col_list = []
        data_tables = []

        # All dictionaries needed to create JSON structure
        temp_funding = OrderedDict()
        temp_pub = OrderedDict()
        core_len = OrderedDict()
        geo_properties = OrderedDict()
        chron_dict = OrderedDict()
        data_dict_upper = OrderedDict()
        final_dict = OrderedDict()

        try:
            # Open the text file in read mode. We'll read one line at a time until EOF
            with open(self.filename_txt, 'r') as f:
                logger_noaa_lpd.info("opened noaa file: {}".format(self.filename_txt))
                for line in iter(f):
                    line_num += 1

                    # PUBLICATION
                    # There can be multiple publications. Create a dictionary for each one.
                    if publication_on:
                        # End of the section. Add the dictionary for this one publication to the overall list
                        if '-----' in line:
                            temp_pub = self.__reorganize_doi(temp_pub)
                            pub.append(temp_pub.copy())
                            temp_abstract.clear()
                            temp_pub.clear()
                            publication_on = False
                            logger_noaa_lpd.info("end section: Publication")
                        elif abstract_on:
                            # End of abstract: possibly more variables after.
                            if "#" in line:
                                abstract_on = False
                                temp_pub['abstract'] = ''.join(temp_abstract)
                                logger_noaa_lpd.info("end section: Abstract")
                                line = self.__str_cleanup(line)
                                key, value = self.__slice_key_val(line)
                                temp_pub[self.__camel_case(key)] = value
                            else:
                                temp_abstract.append(self.__str_cleanup(line))

                        # Add all info into the current publication dictionary
                        else:
                            line = self.__str_cleanup(line)
                            key, value = self.__slice_key_val(line)
                            if key in ("Author", "Authors"):
                                temp_pub["author"] = self.__reorganize_authors(value)
                            else:
                                temp_pub[self.__camel_case(key)] = value
                                if key == 'Abstract':
                                    logger_noaa_lpd.info("reading section: Abstract")
                                    abstract_on = True
                                    temp_abstract.append(value)

                    # DESCRIPTION AND NOTES
                    # Descriptions are often long paragraphs spanning multiple lines, but don't follow the key/value format
                    elif description_on:

                        # End of the section. Turn marker off and combine all the lines in the section
                        if '-------' in line:
                            description_on = False
                            value = ''.join(temp_description)
                            final_dict['description'] = value
                            logger_noaa_lpd.info("end section: Description_and_Notes")

                        # The first line in the section. Split into key, value
                        elif 'Description:' in line:
                            key, val = self.__slice_key_val(line)
                            temp_description.append(val)

                        # Keep a running list of all lines in the section
                        else:
                            line = self.__str_cleanup(line)
                            temp_description.append(line)

                    # SITE INFORMATION (Geo)
                    elif site_info_on:

                        if '-------' in line:
                            site_info_on = False
                            logger_noaa_lpd.info("end section: Site_Information")

                        else:
                            line = self.__str_cleanup(line)
                            key, value = self.__slice_key_val(line)
                            if key.lower() in ["northernmost_latitude", "southernmost_latitude"]:
                                lat.append(self.__convert_num(value))

                            elif key.lower() in ["easternmost_longitude", "westernmost_longitude"]:
                                lon.append(self.__convert_num(value))

                            elif key.lower() in ["site_name", "location", "country", "elevation"]:
                                if key.lower() == 'elevation':
                                    val, unit = self.__split_name_unit(value)
                                    elev.append(val)
                                else:
                                    geo_properties[self.__camel_case(key)] = value

                    # CHRONOLOGY
                    elif chronology_on:
                        """
                        HOW IT WORKS:
                        Chronology will be started at "Chronology:" section header
                        Every line starting with a "#" will be ignored
                        The first line without a "#" is considered the variable header line. Variable names are parsed.
                        Each following line will be considered column data and sorted accordingly.
                        Once the "-----" barrier is reached, we exit the chronology section.
                        """
                        # When reaching the end of the chron section, set the marker to off and close the CSV file
                        if '-------' in line:
                            # Turn off markers to exit section
                            chronology_on = False
                            chron_vals_on = False
                            try:
                                # If nothing between the chronology start and the end barrier, then there won't be a CSV
                                if chron_start_line != line_num - 1:
                                    try:
                                        chron_csv.close()
                                        logger_noaa_lpd.info("parse: chronology: no data found in chronology section")
                                    except NameError:
                                        logger_noaa_lpd.debug(
                                            "parse: chronology_on: NameError: chron_csv ref before assignment, {}".format(
                                                self.filename_txt))
                                        print(
                                            "Chronology section is incorrectly formatted. "
                                            "Section data will not be converted")

                                logger_noaa_lpd.info("end section: Chronology")
                            except NameError:
                                logger_noaa_lpd.debug(
                                    "parse: chronology_on: NameError: chron_start_line ref before assignment, {}".format(
                                        self.filename_txt))
                                print("Chronology section is incorrectly formatted. Section data will not be converted")

                        # Data values line. Split, then write to CSV file
                        elif chron_vals_on:
                            values = line.split()
                            try:
                                cw.writerow(values)
                            except NameError:
                                logger_noaa_lpd.debug(
                                    "parse: chronology_on: NameError: csv writer ref before assignment, {}".format(
                                        self.filename_txt))
                                print("Chronology section is incorrectly formatted. Section data will not be converted")

                        else:
                            try:
                                # Chron variable headers line
                                if line and line[0] != "#":
                                    chron_filename = self.dsn + '.chron1.measurementTable1.csv'
                                    # Organize the var header into a dictionary
                                    variables = self.__reorganize_chron_header(line)

                                    # Create a dictionary of info for each column
                                    chron_col_list = self.__create_chron_cols(variables)
                                    chron_dict['filename'] = chron_filename
                                    chron_dict['chronTableName'] = 'Chronology'
                                    chron_dict['columns'] = chron_col_list

                                    # Open CSV for writing
                                    csv_path = os.path.join(self.dir_bag, chron_filename)
                                    chron_csv = open(csv_path, 'w+', newline='')
                                    logger_noaa_lpd.info("opened csv file: {}".format(chron_filename))
                                    cw = csv.writer(chron_csv)
                                    # Turn the marker on to start processing the values columns
                                    chron_vals_on = True
                            except IndexError:
                                logger_noaa_lpd.debug("parse: chronology: IndexError when attempting chron var header")

                    # VARIABLES
                    elif variables_on:
                        """
                        HOW IT WORKS:
                        Variable lines are the only lines that have a "##" in front of them.
                        Ignore all lines that don't match the "##" regex.
                        Once there's a match, start parsing the variable lines, and create a column entry for each line.
                        """
                        process_line = False
                        # End of the section. Turn marker off
                        if "------" in line:
                            variables_on = False
                            logger_noaa_lpd.info("end section: Variables")
                        for item in NOAA_VAR_LINES:
                            if item.lower() in line.lower():
                                process_line = False
                        for item in NOAA_EMPTY:
                            if item == line:
                                process_line = False
                        m = re.match(re_var, line)
                        if m:
                            process_line = True

                        # If the line isn't in the ignore list, then it's a variable line
                        if process_line:

                            # Split the line items, and cleanup
                            cleaned_line = self.__separate_data_vars(line)

                            # Add the items into a column dictionary
                            data_col_dict = self.__create_paleo_col(cleaned_line, data_col_ct)

                            # Keep a list of all variable names
                            try:
                                # Use this list later to cross check with the variable line in the Data section
                                data_var_names.append(data_col_dict['variableName'])
                            except KeyError:
                                data_var_names.append('')
                                logger_noaa_lpd.warn("parse: variables: "
                                                     "KeyError: {} not found in {}".format("variableName", "data_col_dict"))
                            # Add the column dictionary into a final dictionary
                            data_col_list.append(data_col_dict)
                            data_col_ct += 1

                    # DATA
                    # Missing Value, Create data columns, and output Data CSV
                    elif data_on:
                        """
                        HOW IT WORKS:
                        Capture the "Missing Value" entry, if it exists.
                        Data lines should not have a "#" in front of them.
                        The first line without a "#" should be the variable header line
                        All lines that follow should have column data.
                        """
                        # Do not process blank or template lines
                        process_line = True
                        for item in NOAA_DATA_LINES:
                            if item in line:
                                process_line = False
                        for item in NOAA_EMPTY:
                            if item == line:
                                process_line = False
                        for item in ALTS_MV:
                            # Missing value found. Store entry
                            if item in line.lower():
                                process_line = False
                                line = self.__str_cleanup(line)
                                key, missing_str = self.__slice_key_val(line)

                        if process_line:
                            # Split the line at each space (There SHOULD one space between each variable. Not always true)
                            values = line.split()
                            # Write all data values to CSV
                            if data_vals_on:
                                try:
                                    dw.writerow(values)
                                except NameError:
                                    logger_noaa_lpd.debug(
                                        "parse: data_on: NameError: csv writer ref before assignment, {}".format(
                                            self.filename_txt))

                            # Check for the line of variables
                            else:
                                var = self.__str_cleanup(values[0].lstrip())
                                # Check if a variable name is in the current line
                                if var.lower() in line.lower():
                                    data_vals_on = True
                                    logger_noaa_lpd.info("start section: Data_Values")
                                    # Open CSV for writing
                                    data_filename = "{}.paleoData1.measurementTable1.csv".format(self.dsn)
                                    csv_path = os.path.join(self.dir_bag, data_filename)
                                    data_csv = open(csv_path, 'w+', newline='')
                                    logger_noaa_lpd.info("opened csv file: {}".format(data_filename))
                                    dw = csv.writer(data_csv)

                    # METADATA
                    else:
                        # Line Continuation: Sometimes there are items that span a few lines.
                        # If this happens, we want to combine them all properly into one entry.
                        if '#' not in line and line not in NOAA_EMPTY and old_val:
                            if old_key in ('funding', 'agency'):
                                try:
                                    temp_funding[old_key] = old_val + line
                                except KeyError as e:
                                    logger_noaa_lpd.debug(
                                        "parse: metadata: line continuation: {} not found in {}, {}".format(old_key,
                                                                                                            "temp_funding",
                                                                                                            e))
                            else:
                                try:
                                    final_dict[old_key] = old_val + line
                                except KeyError as e:
                                    logger_noaa_lpd.debug(
                                        "parse: metadata: line continuation: {} not found in {}, {}".format(old_key,
                                                                                                            "temp_funding",
                                                                                                            e))

                        # No Line Continuation: This is the start or a new entry
                        else:
                            line = self.__str_cleanup(line)

                            # Grab the key and value from the current line
                            try:
                                # Split the line into key, value pieces
                                key, value = self.__slice_key_val(line)
                                l_key = key.lower()
                                cc_key= self.__camel_case(key)

                                # If there is no value, then we are at a section header.
                                # Data often has a blank value, so that is a special check.
                                if not value or l_key == 'data':
                                    # Turn on markers if we run into section headers
                                    if l_key == 'description_and_notes':
                                        description_on = True
                                        logger_noaa_lpd.info("reading section: Description_and_Notes")
                                    elif l_key == 'publication':
                                        publication_on = True
                                        logger_noaa_lpd.info("reading section: Publication")
                                    elif l_key == 'site_information':
                                        site_info_on = True
                                        logger_noaa_lpd.info("reading section: Site_Information")
                                    elif l_key == 'chronology':
                                        chronology_on = True
                                        logger_noaa_lpd.info("reading section: Chronology")
                                        chron_start_line = line_num
                                    elif l_key == 'variables':
                                        variables_on = True
                                        logger_noaa_lpd.info("reading section: Variables")
                                    elif l_key == 'data':
                                        data_on = True
                                        logger_noaa_lpd.info("reading section: Data")
                                # For all
                                else:
                                    # Ignore any entries that are specified in the skip list
                                    _ignore = [item.lower() for item in NOAA_KEYS_BY_SECTION["Ignore"]]
                                    if l_key not in _ignore:
                                        # There can be multiple funding agencies and grants. Keep a list of dict entries
                                        _funding = [item.lower() for item in NOAA_KEYS_BY_SECTION["Funding_Agency"]]
                                        if l_key in _funding:
                                            if l_key == 'funding_agency_name':
                                                funding_id += 1
                                                key = 'agency'
                                            elif l_key == 'grant':
                                                grant_id += 1
                                                key = 'grant'
                                            temp_funding[key] = value
                                            # If both counters are matching, we are ready to add content to the funding list
                                            if grant_id == funding_id:
                                                funding.append(temp_funding.copy())
                                                temp_funding.clear()
                                        else:
                                            # There's likely two "Online_Resource"s, and we need both, so check and concat
                                            if cc_key == "onlineResource":
                                                # If it exists, append. If not, add entry as a list
                                                if cc_key in final_dict:
                                                    final_dict[cc_key].append(value)
                                                else:
                                                    final_dict[cc_key] = [value]
                                            else:
                                                final_dict[cc_key] = value
                                        # Keep track of old key in case we have a line continuation
                                        old_key = key
                                        old_val = value.strip()
                            except TypeError as e:
                                logger_noaa_lpd.warn(
                                    "parse: TypeError: none type received from slice_key_val, {}".format(e))

            # Wait to close the data CSV until we reached the end of the text file
            try:
                data_csv.close()
                logger_noaa_lpd.info("end section: Data_Values")
                logger_noaa_lpd.info("end section: Data")
            except NameError as e:
                print("Error: NOAA text file is contains format errors. Unable to process.")
                logger_noaa_lpd.debug(
                    "parse: NameError: failed to close csv, invalid formatting in NOAA txt file, {}".format(e))

            # Piece together measurements block
            logger_noaa_lpd.info("compiling final paleoData")
            data_dict_upper['filename'] = data_filename
            data_dict_upper['paleoDataTableName'] = 'Data'
            data_dict_upper['missingValue'] = missing_str
            data_dict_upper['columns'] = data_col_list
            data_tables.append(data_dict_upper)

            # Piece together geo block
            logger_noaa_lpd.info("compiling final geo")
            geo = self.__create_coordinates(lat, lon, elev)
            geo['properties'] = geo_properties

            # Piece together final dictionary
            logger_noaa_lpd.info("compiling final master")
            final_dict['pub'] = pub
            final_dict['funding'] = funding
            final_dict['geo'] = geo
            final_dict['coreLength'] = core_len
            final_dict['chronData'] = [{"chronMeasurementTable": chron_dict}]
            final_dict['paleoData'] = data_tables
            self.metadata = final_dict
            logger_noaa_lpd.info("final dictionary compiled")

            # Start cleaning up the metadata
            logger_noaa_lpd.info("removing empty fields")
            self.metadata = rm_empty_fields(self.metadata)
            logger_noaa_lpd.info("removing empty doi")
            self.metadata = rm_empty_doi(self.metadata)
            logger_noaa_lpd.info("removing irrelevant keys")
            self.__remove_irr_fields()

        except Exception as e:
            logger_noaa_lpd.debug("parse: {}".format(e))

        logger_noaa_lpd.info("exit parse")
        return
583864
def visibility(vis: Number, unit: str = 'm') -> str:
    
    if not (vis and unit in ('m', 'sm')):
        return ''
    if vis.repr in VIS_REPR:
        return VIS_REPR[vis.repr]
    if unit == 'm':
        converted = vis.value * 0.000621371
        converted = str(round(converted, 1)).replace('.0', '') + 'sm'  # type: ignore
        value = str(round(vis.value / 1000, 1)).replace('.0', '')
        unit = 'km'
    elif unit == 'sm':
        converted = vis.value / 0.621371
        converted = str(round(converted, 1)).replace('.0', '') + 'km'  # type: ignore
        value = str(vis.value).replace('.0', '')
    return f'{value}{unit} ({converted})'
972089
def items(cls):
        
        return [
            cls.TEMPERATURE,
            cls.PRESSURE,
            cls.HUMIDITY,
            cls.WIND_SPEED,
            cls.WIND_DIRECTION,
            cls.CLOUDS
        ]
976873
def _parse_metadata(self, metadata):
        
        retval = {}

        # these are the first keys, afterwards follows a var-len list of variables/props
        # first key always blank so skip it
        field_keys = [
            "nesdis_id",
            "nwsli",
            "location_text",
            "latitude",
            "longitude",
            "hsa",
            "state",
            "owner",
            "manufacturer",
            "channel",
            "init_transmit",  # HHMM
            "trans_interval",
        ]  # min

        # repeat in blocks of 7 after field_keys
        var_keys = [
            "pe_code",
            "data_interval",  # min
            "coefficient",
            "constant",
            "time_offset",  # min
            "base_elevation",  # ft
            "gauge_correction",
        ]  # ft

        lines = metadata.splitlines()
        for line in lines:
            if len(line) == 0:
                continue

            raw_fields = line.split("|")

            fields = dict(zip(field_keys, raw_fields[1 : len(field_keys)]))

            # how many blocks of var_keys after initial fields
            var_offset = len(field_keys) + 1
            var_blocks = (len(raw_fields) - var_offset) // len(
                var_keys
            )  # how many variables
            vars_only = raw_fields[var_offset:]
            variables = {}

            for offset in range(var_blocks):
                var_dict = dict(
                    zip(
                        var_keys,
                        vars_only[
                            offset
                            * len(var_keys) : (offset + 1)
                            * len(var_keys)
                        ],
                    )
                )
                variables[var_dict["pe_code"]] = var_dict

                var_dict["base_elevation"] = float(var_dict["base_elevation"])
                var_dict["gauge_correction"] = float(
                    var_dict["gauge_correction"]
                )
                del var_dict["pe_code"]  # no need to duplicate

            line_val = {"variables": variables}
            line_val.update(fields)

            # conversions
            def dms_to_dd(dms):
                parts = dms.split(" ")
                sec = int(parts[1]) * 60 + int(parts[2])
                return float(parts[0]) + (
                    sec / 3600.0
                )  # negative already in first portion

            line_val["latitude"] = dms_to_dd(line_val["latitude"])
            line_val["longitude"] = dms_to_dd(line_val["longitude"])

            retval[line_val["nesdis_id"]] = line_val

        return retval
929349
def read(self, vals):
        
        i = 0
        if len(vals[i]) == 0:
            self.year = None
        else:
            self.year = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.month = None
        else:
            self.month = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.day = None
        else:
            self.day = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.hour = None
        else:
            self.hour = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.minute = None
        else:
            self.minute = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.data_source_and_uncertainty_flags = None
        else:
            self.data_source_and_uncertainty_flags = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.dry_bulb_temperature = None
        else:
            self.dry_bulb_temperature = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.dew_point_temperature = None
        else:
            self.dew_point_temperature = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.relative_humidity = None
        else:
            self.relative_humidity = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.atmospheric_station_pressure = None
        else:
            self.atmospheric_station_pressure = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.extraterrestrial_horizontal_radiation = None
        else:
            self.extraterrestrial_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.extraterrestrial_direct_normal_radiation = None
        else:
            self.extraterrestrial_direct_normal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.horizontal_infrared_radiation_intensity = None
        else:
            self.horizontal_infrared_radiation_intensity = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.global_horizontal_radiation = None
        else:
            self.global_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.direct_normal_radiation = None
        else:
            self.direct_normal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.diffuse_horizontal_radiation = None
        else:
            self.diffuse_horizontal_radiation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.global_horizontal_illuminance = None
        else:
            self.global_horizontal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.direct_normal_illuminance = None
        else:
            self.direct_normal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.diffuse_horizontal_illuminance = None
        else:
            self.diffuse_horizontal_illuminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.zenith_luminance = None
        else:
            self.zenith_luminance = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.wind_direction = None
        else:
            self.wind_direction = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.wind_speed = None
        else:
            self.wind_speed = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.total_sky_cover = None
        else:
            self.total_sky_cover = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.opaque_sky_cover = None
        else:
            self.opaque_sky_cover = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.visibility = None
        else:
            self.visibility = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.ceiling_height = None
        else:
            self.ceiling_height = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.present_weather_observation = None
        else:
            self.present_weather_observation = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.present_weather_codes = None
        else:
            self.present_weather_codes = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.precipitable_water = None
        else:
            self.precipitable_water = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.aerosol_optical_depth = None
        else:
            self.aerosol_optical_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.snow_depth = None
        else:
            self.snow_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.days_since_last_snowfall = None
        else:
            self.days_since_last_snowfall = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.albedo = None
        else:
            self.albedo = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.liquid_precipitation_depth = None
        else:
            self.liquid_precipitation_depth = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.liquid_precipitation_quantity = None
        else:
            self.liquid_precipitation_quantity = vals[i]
        i += 1
815567
def get_dataset(self, key, info):
        """"""
        res = super(HRITGOMSFileHandler, self).get_dataset(key, info)

        res = self.calibrate(res, key.calibration)
        res.attrs['units'] = info['units']
        res.attrs['standard_name'] = info['standard_name']
        res.attrs['wavelength'] = info['wavelength']
        res.attrs['platform_name'] = self.platform_name
        res.attrs['sensor'] = 'msu-gs'
        res.attrs['satellite_longitude'] = self.mda['projection_parameters']['SSP_longitude']
        res.attrs['satellite_latitude'] = 0
        res.attrs['satellite_altitude'] = 35785831.00

        return res