Source code for pycif.plugins.datastreams.fields.oldlmdz_photochem.fetch

import os
import datetime
import pandas as pd
import xarray as xr
from .....utils import path


[docs] def fetch(ref_dir, ref_file, date_interval, target_dir, tracer=None, **kwargs): # Reshape input interval to include full months datei, datef = date_interval list_period_dates = \ pd.date_range(datei, datef, freq=tracer.file_freq).to_pydatetime() list_dates = {} list_files = {} for dd in list_period_dates: dout = datetime.datetime(dd.year + 1, 1, 1) file = dd.strftime("{}/{}".format(ref_dir, ref_file)) if os.path.isfile(file): # Fetching target_file = "{}/{}".format(target_dir, os.path.basename(file)) path.link(file, target_file) # Time stamps ds = xr.open_dataset(target_file) file_hours = list( ds["time_counter"].to_pandas().index.to_pydatetime() ) list_dates[dd] = [ [hh0, hh0 + datetime.timedelta(hours=24)] for hh0 in file_hours] list_files[dd] = (len(list_dates[dd]) * [target_file]) return list_files, list_dates