diff --git a/Inst_eddies/inst_eddies_Aviso.py b/Inst_eddies/inst_eddies_Aviso.py new file mode 100755 index 0000000000000000000000000000000000000000..4060b29981040eb7bf46e24ef757d4fc0668e5be --- /dev/null +++ b/Inst_eddies/inst_eddies_Aviso.py @@ -0,0 +1,57 @@ +#!/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)