Beispiel #1
0
 def test_get_convert_dict(self):
     # Run
     result = get_convert_dict(self.fmt)
     # Assert
     self.assertDictEqual(result, {
         'directory': '',
         'platform': '4s',
         'platnum': '2s',
         'time': '%Y%m%d_%H%M',
         'orbit': '05d',
     })
Beispiel #2
0
def adjust_pattern_time_name(pattern, time_name):
    """Adjust filename pattern so that time_name is present."""
    # Get parse definitions and try to figure out if there's
    # an item for time
    convert_dict = get_convert_dict(pattern)
    for key, val in convert_dict.items():
        # Need to exclude 'end_time' and 'proc_time' / 'processing_time'
        if ("time" in key or "%" in val) and \
           "end" not in key and key != time_name:
            logging.debug("Updating pattern from '%s' ...", pattern)

            while '{' + key in pattern:
                pattern = pattern.replace('{' + key, '{' + time_name)
            logging.debug("... to '%s'", pattern)
    return pattern
Beispiel #3
0
def create_fnames(info, product_config, prod_id):
    """Create filename for product *prod*"""
    area_id = info["area_id"]

    # List of products
    products = product_config["product_list"][area_id]["products"]

    # Get area name
    info["areaname"] = product_config["product_list"][area_id]["areaname"]

    # Find output directory
    output_dir = products[prod_id].get("output_dir", "")
    if output_dir == "":
        output_dir = product_config["common"].get("output_dir", "")

    if output_dir == "":
        LOGGER.warning("No output directory specified, "
                       "saving to current directory!")

    # Find filename pattern
    pattern = products[prod_id].get("fname_pattern", "")
    if pattern == "":
        pattern = product_config["common"].get("fname_pattern", "")

    if pattern == "":
        LOGGER.warning("No pattern was given, using built-in default: %s",
                       PATTERN)
        pattern = PATTERN

    # Join output dir and filename pattern
    pattern = os.path.join(output_dir, pattern)

    # Find output formats
    formats = products[prod_id].get("formats", None)
    if formats is None:
        formats = product_config["common"].get("formats", [FORMAT_DEFAULTS])

    prod_name = products[prod_id]["productname"]
    info["productname"] = prod_name

    # Find the name of the available 'nominal_time'
    time_name = None
    for key in info:
        if "time" in key and "end" not in key and "proc" not in key:
            time_name = key
            LOGGER.debug("metadata time name is '%s'", time_name)
            break

    if time_name is None and "time" in pattern:
        return None, None

    # Adjust filename pattern so that time_name is present.
    # Get parse definitions and try to figure out if there's
    # an item for time
    convert_dict = get_convert_dict(pattern)
    for key, val in convert_dict.items():
        if ("time" in key or "%" in val) and \
           "end" not in key and key != time_name:
            LOGGER.debug("Updating pattern from '%s' ...", pattern)

            while '{' + key in pattern:
                pattern = pattern.replace('{' + key,
                                          '{' + time_name)
            LOGGER.debug("... to '%s'", pattern)

    fnames = []
    for fmt in formats:
        info["format"] = fmt["format"]
        # Ensure non-unicode filename
        fnames.append(str(compose(pattern, info)))

    return (fnames, prod_name)