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

Read date, slice and `periodic` from namelist file

It was not convenient to read them with input function or on the
command line: too much to read this way, and not clear when saved in
JSON text file. And we already had to create a namelist file
anyway. And this way the namelists can be extended transparently.
parent dc301b06
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@
"Extraction_eddies_region_2_noise": {
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"commands":
[
......@@ -83,7 +83,7 @@
"$build_dir/Inst_eddies/inst_eddies_Aviso.py",
"-b", "1.625", "15.625", "-38.375", "-30.375", "SHPC",
"$Aviso_DT_dir/dt_global_allsat_phy_l4_%Y%m%d_20210726.nc",
"2006-01-01", "2006-01-15", "0", "f"
"2006-01-01", "2006-01-15"
],
"mv grid_nml.txt SHPC"
],
......@@ -93,7 +93,7 @@
"Region_6": {
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml date=20454 slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"commands":
[
......@@ -106,18 +106,17 @@
"mv grid_nml.txt SHPC"
],
"main_command": 0,
"input": "20454\n0\nf\n",
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
},
"Missing_file": {
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"command": [
"$build_dir/Inst_eddies/inst_eddies_Aviso.py", "SHPC",
"$Eurec4A_NRT_dir/dataset-duacs-global-allsat-phy-%Y-%m-%d.nc",
"2020-01-31", "2020-02-02", "0", "f"
"2020-01-31", "2020-02-02"
],
"description":
"Date 2020-02-01 is missing. Test of the script with a missing date.",
......@@ -131,7 +130,7 @@
[
"$build_dir/Inst_eddies/inst_eddies_Aviso.py", "SHPC",
"$Aviso_DT_dir/dt_global_allsat_phy_l4_%Y%m%d_20210726.nc",
"1993-01-01", "1993-03-31", "0", "f",
"1993-01-01", "1993-03-31",
"--bbox", "20", "30", "35", "42"
],
"mv grid_nml.txt SHPC"
......@@ -139,7 +138,7 @@
"main_command": 0,
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
},
......@@ -150,7 +149,7 @@
[
"$build_dir/Inst_eddies/inst_eddies_Aviso.py", "SHPC",
"$Aviso_DT_dir/dt_global_allsat_phy_l4_%Y%m%d_20210726.nc",
"2006-01-01", "2006-01-15", "0", "f",
"2006-01-01", "2006-01-15",
"--bbox", "0.125", "29.875", "-59.875", "-15.125"
],
"mv grid_nml.txt SHPC"
......@@ -158,7 +157,7 @@
"main_command": 0,
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
}
......
......@@ -261,7 +261,7 @@
"description": "Part of the domain has missing values.",
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml date=20454 slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"commands":
[
......@@ -275,34 +275,32 @@
"mv grid_nml.txt SHPC"
],
"main_command": 0,
"input": "20454\n0\nf\n",
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
},
"Inst_eddies_py": {
"description": "Like Extraction_eddies_region_4, but for a single date. This is a test of options of the wrapper script rather than a test of the Fortran executable.",
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml date=20454 slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"command": [
"$build_dir/Inst_eddies/inst_eddies.py",
"-b", "16.125", "20.875", "-38.875", "-34.125",
"SHPC", "$Aviso_DT_dir/dt_global_allsat_phy_l4_20060101_20210726.nc"
],
"input": "20454\n0\nf\n",
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
},
"Inst_eddies_loop": {
"create_file": [
"inst_eddies_nml.txt",
"&config_nml /\n"
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"commands":
[
[
"$build_dir/Inst_eddies/inst_eddies_Aviso.py", "SHPC",
"$src_dir/Inst_eddies/Tests/Input/Region_1/huv_region_1_%Y_%m_%d.nc",
"2006-01-01", "2006-01-04", "0", "f"
"2006-01-01", "2006-01-04"
],
"mv grid_nml.txt SHPC"
],
......@@ -386,13 +384,17 @@
[
"$build_dir/Inst_eddies/inst_eddies_Aviso.py", "SHPC",
"$Aviso_DT_dir/dt_global_allsat_phy_l4_%Y%m%d_20210726.nc",
"2006-01-01", "2006-01-15", "0", "f",
"2006-01-01", "2006-01-15",
"--bbox", "16.125", "20.875", "-38.875", "-34.125"
],
"mv grid_nml.txt SHPC"
],
"main_command": 0,
"create_file": ["inst_eddies_nml.txt", "&config_nml /\n"],
"create_file":
[
"inst_eddies_nml.txt",
"&dates_nml slice=0/\n&config_nml /\n&input_ssh_nml /\n"
],
"sel_diff_args": {"exclude": ["timings.txt", "perf_report.csv"]}
},
"Complete_SSH":
......
......@@ -21,12 +21,9 @@ def process_1_file(
nco_instance,
nc_file,
inst_eddies_exe,
d,
my_slice,
writer,
SHPC_dir,
inst_eddies_nml,
periodic,
):
t0 = time.perf_counter()
......@@ -55,22 +52,18 @@ def process_1_file(
subprocess.run(
[inst_eddies_exe, SHPC_dir, "unpacked.nc"],
check=True,
input=f"&dates_nml date = {d}, slice = {my_slice}/\n"
+ str(inst_eddies_nml)
+ f"\n&input_ssh_nml periodic = {periodic}/\n",
input=str(inst_eddies_nml) + "\n",
text=True,
)
elapsed_Fortran = time.perf_counter() - t0
writer.writerow([d, elapsed_NCO, elapsed_Fortran])
writer.writerow(
[inst_eddies_nml["dates_nml"]["date"], elapsed_NCO, elapsed_Fortran]
)
def loop_inst_eddies(
SHPC_dir, files, bbox, inst_eddies_nml, d, my_slice, periodic
):
def loop_inst_eddies(SHPC_dir, files, bbox, inst_eddies_nml):
"""`files` is an iterator of file paths. The first file must exist,
others can be missing. bbox is a tuple of four real numbers. `d`
is a date index (integer value) for the first date. my_slice is
the slice index (integer value) in the SHPC.
others can be missing. bbox is a tuple of four real numbers.
"""
......@@ -84,6 +77,7 @@ def loop_inst_eddies(
)
nco_instance = nco.Nco()
my_slice = inst_eddies_nml["dates_nml"]["slice"]
if os.access(f"{SHPC_dir}/Slice_{my_slice}", os.F_OK):
shutil.rmtree(f"{SHPC_dir}/Slice_{my_slice}")
......@@ -103,24 +97,27 @@ def loop_inst_eddies(
# First file is out of the loop because it must be present:
nc_file = next(files)
print("inst_eddies.loop_inst_eddies: Date:", d)
print(
"inst_eddies.loop_inst_eddies: Date:",
inst_eddies_nml["dates_nml"]["date"],
)
print("inst_eddies.loop_inst_eddies: Input file:", nc_file, flush=True)
process_1_file(
bbox,
nco_instance,
nc_file,
inst_eddies_exe,
d,
my_slice,
writer,
SHPC_dir,
inst_eddies_nml,
periodic,
)
d += 1
inst_eddies_nml["dates_nml"]["date"] += 1
for nc_file in files:
print("inst_eddies.loop_inst_eddies: Date:", d)
print(
"inst_eddies.loop_inst_eddies: Date:",
inst_eddies_nml["dates_nml"]["date"],
)
print("inst_eddies.loop_inst_eddies: Input file:", nc_file, flush=True)
if os.access(nc_file, os.F_OK):
......@@ -129,12 +126,9 @@ def loop_inst_eddies(
nco_instance,
nc_file,
inst_eddies_exe,
d,
my_slice,
writer,
SHPC_dir,
inst_eddies_nml,
periodic,
)
else:
print("inst_eddies.loop_inst_eddies: Missing file:", nc_file)
......@@ -148,7 +142,7 @@ def loop_inst_eddies(
n_shapes = len(shpr)
ishape_last.write(str(n_shapes - 1) + "\n")
d += 1
inst_eddies_nml["dates_nml"]["date"] += 1
perf_report.close()
os.remove("unpacked.nc")
......@@ -186,22 +180,12 @@ if __name__ == "__main__":
sys.exit(args.file[0] + " not found")
if os.access("inst_eddies_nml.txt", os.R_OK):
print("Will use inst_eddies_nml.txt.")
print(
"Will use inst_eddies_nml.txt, using date in dates_nml as first "
"date..."
)
else:
sys.exit('"inst_eddies_nml.txt" not found -- Aborting')
inst_eddies_nml = f90nml.read("inst_eddies_nml.txt")
d = input("Enter first date index (integer value): ")
d = int(d)
my_slice = input("Enter slice index (integer value): ")
my_slice = int(my_slice)
periodic = input("periodic (t/f)? ")
loop_inst_eddies(
args.SHPC_dir,
iter(args.file),
args.bbox,
inst_eddies_nml,
d,
my_slice,
periodic,
)
loop_inst_eddies(args.SHPC_dir, iter(args.file), args.bbox, inst_eddies_nml)
......@@ -53,8 +53,6 @@ argparser.add_argument(
)
argparser.add_argument("first_date", help="%%Y-%%m-%%d")
argparser.add_argument("last_date", help="%%Y-%%m-%%d")
argparser.add_argument("slice", type=int, help="slice number to create")
argparser.add_argument("periodic", choices=["t", "f"])
argparser.add_argument(
"-b",
"--bbox",
......@@ -68,19 +66,18 @@ 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.")
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
inst_eddies.loop_inst_eddies(
args.SHPC_dir,
filename_generator(args.template, first_date, last_date),
args.bbox,
inst_eddies_nml,
d,
my_slice=args.slice,
periodic=args.periodic,
)
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