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

from __future__ import annotations

import datetime
import os
from os import PathLike
from pathlib import Path

import numpy as np
import pandas as pd

from .....utils import path


[docs] def fetch( ref_dir: str, ref_file: str, input_interval: tuple[datetime.datetime, datetime.datetime], target_dir: str, **kwargs, ) -> tuple[ dict[datetime.datetime, list[str]], dict[datetime.datetime, list[tuple[datetime.datetime, datetime.datetime]]], ]: """Fetch Initial condition files and dates for LMDZ. Args: ref_dir (str): Path to the data ref_file (str): File format of the data input_interval (list[datetime.datetime]): Date range target_dir (str): Where to link the data tracer (_type_, optional): _description_. Defaults to None. Returns: (list_files, list_dates): tuple of dictionaries describing input dates and corresponding files """ if not ref_dir and not ref_file: return {}, {} date = input_interval[0] input_file = Path(ref_dir, date.strftime(ref_file)) if not input_file.is_file(): raise FileNotFoundError(f"file '{input_file}' not found") # Fetching target_file = os.path.join(target_dir, os.path.basename(input_file)) target_file = Path(target_dir, input_file.name) path.link(input_file, target_file) list_files = {date: [str(input_file)]} list_dates = {date: [(date, date)]} return list_files, list_dates