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

Allow shell wildcard in template

This is useful because, for the year 2021, the last part of Aviso file
names varies.
parent ae59accd
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import sys ...@@ -10,6 +10,7 @@ import sys
from dateutil import parser from dateutil import parser
import netCDF4 import netCDF4
import inst_eddies import inst_eddies
import glob
def filename_generator(first_file, first_date, last_date, template): def filename_generator(first_file, first_date, last_date, template):
dirname = path.dirname(first_file) dirname = path.dirname(first_file)
...@@ -23,6 +24,18 @@ def filename_generator(first_file, first_date, last_date, template): ...@@ -23,6 +24,18 @@ def filename_generator(first_file, first_date, last_date, template):
basename = my_date.strftime(template) basename = my_date.strftime(template)
nc_file = path.join(dirname, basename) nc_file = path.join(dirname, basename)
# 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")
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument("first_file", argparser.add_argument("first_file",
help = "NetCDF file containing SSH and velocity at a " help = "NetCDF file containing SSH and velocity at a "
...@@ -31,7 +44,8 @@ argparser.add_argument("slice", type = int, ...@@ -31,7 +44,8 @@ argparser.add_argument("slice", type = int,
help = "slice number to create") help = "slice number to create")
argparser.add_argument("--template", argparser.add_argument("--template",
help = "template of basename with date.strftime format " help = "template of basename with date.strftime format "
"codes, only used for several dates") "codes (and possible shell wildcards), only used for "
"several dates")
argparser.add_argument("-l", "--last_date", help = "%%Y-%%m-%%d") argparser.add_argument("-l", "--last_date", help = "%%Y-%%m-%%d")
argparser.add_argument("-b", "--bbox", nargs=4, type = float, argparser.add_argument("-b", "--bbox", nargs=4, type = float,
metavar = ("xmin", "xmax", "ymin", "ymax")) metavar = ("xmin", "xmax", "ymin", "ymax"))
......
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