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

Replace positional argument template by optional

Replace positional argument template by optional argument. This
argument is now needed only in case we process several dates, since
the first date is now read from the NetCDF file.
parent 264fcdc5
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,8 @@
"$build_dir/Inst_eddies/inst_eddies.py", "-b", "1.625", "15.625",
"-38.375", "-30.375",
"$large_input_dir/dt_global_allsat_phy_l4_20060101_20190101.nc",
"dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l", "20060115"
"--template=dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l",
"20060115"
]
},
{
......@@ -76,8 +77,8 @@
[
"$build_dir/Inst_eddies/inst_eddies.py",
"$large_input_dir/dt_global_allsat_phy_l4_20060101_20190101.nc",
"dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l", "2006-01-02",
"-b", "5.875", "12.125", "-32.125", "-26.875"
"--template=dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l",
"2006-01-02", "-b", "5.875", "12.125", "-32.125", "-26.875"
]
}
]
......@@ -303,7 +303,8 @@
"$build_dir/Inst_eddies/inst_eddies.py", "-b", "16.125", "20.875",
"-38.875", "-34.125",
"$large_input_dir/dt_global_allsat_phy_l4_20060101_20190101.nc",
"dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l", "20060102"
"--template=dt_global_allsat_phy_l4_%Y%m%d_20190101.nc", "-l",
"20060102"
]
},
{
......@@ -313,7 +314,7 @@
[
"$build_dir/Inst_eddies/inst_eddies.py",
"$src_dir/Inst_eddies/Tests/Input/Region_1/huv_region_1_2006_01_01.nc",
"huv_region_1_%Y_%m_%d.nc", "-l", "2006-01-04"
"--template=huv_region_1_%Y_%m_%d.nc", "-l", "2006-01-04"
]
},
{
......
......@@ -13,13 +13,15 @@ import subprocess
import shapefile
import sys
from dateutil import parser
import netCDF4
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")
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"))
......@@ -33,13 +35,23 @@ inst_eddies_exe = "@CMAKE_CURRENT_BINARY_DIR@/inst_eddies"
if not os.access(inst_eddies_exe, os.X_OK):
sys.exit(inst_eddies_exe + " not found or not executable")
dirname, basename = path.split(args.first_file)
my_date = datetime.datetime.strptime(basename, args.template).date()
# Get the first date from the time coordinate in the NetCDF file:
with netCDF4.Dataset(args.first_file) as f:
my_date = f["time"][:].item()
my_date = round(my_date)
my_date = datetime.date(1950, 1, 1) + datetime.timedelta(my_date)
#--
dirname = path.dirname(args.first_file)
nc_file = args.first_file
nco_instance = nco.Nco()
if args.last_date:
last_date = parser.parse(args.last_date).date()
if last_date > my_date and not args.template:
sys.exit("template option required for several dates")
else:
last_date = my_date
......
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