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

import datetime
import glob
import os
import pandas as pd

import numpy as np

from .....utils import path
from logging import info, debug
from .utils import find_valid_file


[docs] def fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, component=None, **kwargs): """Fetch GCP N2O multi-year files bracketing the requested dates. For each date key in ``input_interval``, calls :func:`~pycif.plugins.datastreams.fluxes.GCP_1x1_N2O.utils.find_valid_file` for every sub-date to bracket the nearest available files (before and after), links all found files into ``target_dir``, and returns deduplicated, sorted lists of files/dates per key. Args: ref_dir (str): directory where the original files are found. ref_file (str): (template) name of the original files. input_interval (dict): mapping of reference dates to the list of sub-dates to simulate within each period. target_dir (str): directory where links to the original files are created. tracer: the tracer Plugin; unused directly but kept for interface compatibility. component: the component Plugin; unused directly but kept for interface compatibility. **kwargs: unused, kept for interface compatibility. Returns: (dict, dict): ``list_files`` and ``list_dates``, keyed like ``input_interval``, each value a deduplicated sorted list of file paths / bracketing dates found across all sub-dates of that key. """ debug('Display here the information about the plugin') debug(tracer.plugin.name) debug(tracer.plugin.version) debug(",".join(dir(tracer))) debug(component.plugin.name) debug(component.plugin.version) debug(dir(component)) 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) tmp_files.extend(files_orig) tmp_dates.extend(dates_orig) # Fetching local_files = [] for f in tmp_files: target_file = f"{target_dir}/{os.path.basename(f)}" path.link(f, target_file) local_files.append(target_file) list_files[datei] = sorted(list(set(local_files))) list_dates[datei] = sorted(list(set(tmp_dates))) return list_files, list_dates