Source code for pycif.plugins.datastreams.fluxes.dummy_txt.fetch

import os
import pandas as pd
from .....utils import path
from .make import make


[docs] def fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs): # Extend simulation interval if end date does not include a full period # of fluxes datei = input_interval[0] datef = input_interval[1] tmp_dates = pd.date_range(datei, datef, freq=tracer.period) # Fetching or creating if necessary list_files = {} list_dates = {} for di in tmp_dates: f = datei.strftime("{}/{}".format(ref_dir, ref_file)) target_file = "{}/{}".format(target_dir, os.path.basename(f)) if os.path.isfile(f): path.link(f, target_file) else: flx = tracer.make(tracer) tracer.write("", target_file, flx[0, 0]) df = di + pd.to_timedelta(tracer.period) drange = pd.date_range(di, df, freq=tracer.freq) list_files[di] = (len(drange) - 1) * [target_file] list_dates[di] = [[d0, d1] for d0, d1 in zip(drange[:-1], drange[1:])] return list_files, list_dates