fetch.py 864 Bytes
Newer Older
1
import os
2
import datetime
3
4
import pandas as pd
import xarray as xr
5
from ....utils import path
6

7
from logging import info
8
9


Antoine Berchet's avatar
Antoine Berchet committed
10
11
12
13
def default_fetch(
    ref_dir, ref_file, input_dates, target_dir, tracer=None, **kwargs
):

Antoine Berchet's avatar
Antoine Berchet committed
14
    info("Fetching input files from:")
Antoine Berchet's avatar
Antoine Berchet committed
15
    info("{}/{}".format(ref_dir, ref_file))
16
17
18
19
    
    file_freq = getattr(tracer, "file_freq", "1D")
    list_period_dates = \
        pd.date_range(input_dates[0], input_dates[1], freq=file_freq)
20
    list_dates = {}
21
22
23
24
    list_files = {}
    for dd in list_period_dates:
        file = dd.strftime("{}/{}".format(ref_dir, ref_file))
        if os.path.isfile(file):
25
            list_dates[dd] = [dd]
26
            list_files[dd] = [file]
Antoine Berchet's avatar
Antoine Berchet committed
27

28
29
30
            # Fetching
            target_file = "{}/{}".format(target_dir, os.path.basename(file))
            path.link(file, target_file)
31

32
    return list_files, list_dates