Newer
Older
"""Compared to inst_eddies.py, this script takes as arguments a
template, a first date and a last date, instead of a list of files. So
import argparse
import datetime
import sys
from dateutil import parser
def filename_generator(template, first_date, last_date):
while my_date <= last_date:
nc_file = my_date.strftime(template)
# The template may contain a wild card as long as there is no
# more than one file matching it. A missing file is ok and
# will be dealt with in inst_eddies.py.
path_list = glob.glob(nc_file)
if len(path_list) == 1:
nc_file = path_list[0]
elif len(path_list) >= 2:
sys.exit(
"inst_eddies_Aviso.py:filename_generator: more than one "
"file matching template"
)
yield nc_file
my_date += datetime.timedelta(1)
argparser = argparse.ArgumentParser()
argparser.add_argument("SHPC_dir")
argparser.add_argument(
"template",
help="template of NetCDF file name (containing SSH "
"and velocity at a single date), including path, "
"with date.strftime format codes (and possible shell "
"wildcards)",
)
argparser.add_argument("first_date", help="%%Y-%%m-%%d")
argparser.add_argument("last_date", help="%%Y-%%m-%%d")
argparser.add_argument(
"-b",
"--bbox",
nargs=4,
type=float,
metavar=("xmin", "xmax", "ymin", "ymax"),
)
args = argparser.parse_args()
first_date = parser.parse(args.first_date).date()
last_date = parser.parse(args.last_date).date()
d = (first_date - datetime.date(1950, 1, 1)).days
if os.access("inst_eddies_nml.txt", os.R_OK):
print("Will use inst_eddies_nml.txt, ignoring date in dates_nml...")
else:
sys.exit('"inst_eddies_nml.txt" not found -- Aborting')
inst_eddies_nml = f90nml.read("inst_eddies_nml.txt")
# We choose to use d as the first date index. We could choose anything.
inst_eddies_nml["dates_nml"]["date"] = d
filename_generator(args.template, first_date, last_date),
args.bbox,