Skip to content
Snippets Groups Projects
Commit f36dca6c authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Create script to generate iterator of Aviso files

parent 1c29f87a
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""We are assuming that all input NetCDF files are in the same
directory and that the time coordinate is in days since 1950-1-1."""
import argparse
import datetime
from os import path
import sys
from dateutil import parser
import netCDF4
import inst_eddies
def filename_generator(first_file, first_date, last_date, template, dirname):
nc_file = first_file
my_date = first_date
while True:
yield nc_file
my_date += datetime.timedelta(1)
if my_date > last_date: break
basename = my_date.strftime(template)
nc_file = path.join(dirname, basename)
argparser = argparse.ArgumentParser()
argparser.add_argument("first_file",
help = "NetCDF file containing SSH and velocity at a "
"single date")
argparser.add_argument("--template",
help = "template of basename with date format, only "
"used for several dates")
argparser.add_argument("-l", "--last_date", help = "%%Y-%%m-%%d")
argparser.add_argument("-b", "--bbox", nargs=4, type = float,
metavar = ("xmin", "xmax", "ymin", "ymax"))
args = argparser.parse_args()
# Get the first date from the time coordinate in the NetCDF file:
with netCDF4.Dataset(args.first_file) as f:
d = f["time"][:].item()
d = round(d)
first_date = datetime.date(1950, 1, 1) + datetime.timedelta(d)
#--
dirname = path.dirname(args.first_file)
if args.last_date:
last_date = parser.parse(args.last_date).date()
if last_date > first_date and not args.template:
sys.exit("template option required for several dates")
else:
last_date = first_date
inst_eddies.loop_inst_eddies(filename_generator(args.first_file, first_date,
last_date, args.template,
dirname), args.bbox, d)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment