Source code for pycif.plugins.datastreams.fields.oldlmdz_prescrconcs.fetch
import os
import numpy as np
from .....utils import path
from .utils import find_valid_file
[docs]
def fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs):
"""Fetch legacy LMDZ4 prescribed-concentration files.
``input_interval`` is a mapping of key dates to lists of sub-dates;
for each sub-date, calls :func:`~.utils.find_valid_file` to locate
the two straddling files, links them into ``target_dir``, and
deduplicates the resulting file/date pairs.
Args:
ref_dir: directory where the original files are found.
ref_file: (template) name of the original files.
input_interval: mapping of key dates to the list of sub-dates
covered under each key.
target_dir: directory where links to the original files are
created.
tracer: unused, accepted for interface compatibility.
Returns:
list_files: for each key date, the deduplicated array of file
paths matching ``list_dates``.
list_dates: for each key date, the deduplicated, sorted array of
dates found by :func:`~.utils.find_valid_file`.
"""
list_files = {}
list_dates = {}
for datei in input_interval:
tmp_files = []
tmp_dates = []
for dd in input_interval[datei]:
# print('Date to simulate',dd)
files_orig, dates_orig = find_valid_file(ref_dir, ref_file, dd)
# print(files_orig,dates_orig)
tmp_files.extend(files_orig)
tmp_dates.extend(dates_orig)
# print('wwwwwwwwwwwwwwww',tmp_dates)
# Fetching
local_files = []
for f, dd in zip(tmp_files, tmp_dates):
target_file = f"{target_dir}/{dd.strftime(ref_file)}"
# print('ttt',target_file)
path.link(f, target_file)
local_files.append(target_file)
unique_dates, unique_index = np.unique(tmp_dates, return_index=True)
list_files[datei] = np.array(tmp_files)[unique_index]
list_dates[datei] = unique_dates
return list_files, list_dates