Newer
Older
#!/usr/bin/env python3
import os
import pathlib
def create_slice(SHPC_dir, my_slice, init_date, with_proj):
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
if os.access(f"{SHPC_dir}/Slice_{my_slice}", os.F_OK):
shutil.rmtree(f"{SHPC_dir}/Slice_{my_slice}")
for orient in ["Cyclones", "Anticyclones"]:
os.makedirs(f"{SHPC_dir}/Slice_{my_slice}/{orient}")
with shapefile.Writer(
f"{SHPC_dir}/Slice_{my_slice}/{orient}/extremum", shapefile.POINT
) as w:
w.field("ssh", "N", 13, 6)
w.field("date", "N", 5)
w.field("eddy_index", "N", 5)
w.field("speed", "N", 13, 6)
if with_proj:
with shapefile.Writer(
f"{SHPC_dir}/Slice_{my_slice}/{orient}/extr_proj",
shapefile.POINT,
) as w:
w.field("date", "N", 5)
w.field("eddy_index", "N", 5)
for fname in ["outermost_contour", "max_speed_contour"]:
with shapefile.Writer(
f"{SHPC_dir}/Slice_{my_slice}/{orient}/{fname}",
shapefile.POLYGON,
) as w:
w.field("r_eq_area", "N", 10, 4)
w.field("ssh", "N", 13, 6)
w.field("date", "N", 5)
w.field("eddy_index", "N", 5)
pathlib.Path(
f"{SHPC_dir}/Slice_{my_slice}/{orient}/ishape_last.txt"
).touch()
pathlib.Path(f"{SHPC_dir}/Slice_{my_slice}/timings.txt").touch()
with open(f"{SHPC_dir}/Slice_{my_slice}/date_range.txt", "w") as f_obj:
f_obj.write(f"{init_date} {init_date}\n")
if __name__ == "__main__":
import sys
import f90nml
if len(sys.argv) != 3:
sys.exit("Required arguments: SHPC-dir initial-date")
print("Will use inst_eddies_nml.txt")
else:
sys.exit('"inst_eddies_nml.txt" not found -- Aborting')
inst_eddies_nml = f90nml.read("inst_eddies_nml.txt")
try:
my_slice = inst_eddies_nml["main_nml"]["slice"]
except KeyError:
my_slice = 0 # same default value as in Fortran program
try:
with_proj = not inst_eddies_nml["input_ssh_nml"]["uniform_lon_lat"]
except KeyError:
with_proj = False # same default value as in Fortran program
create_slice(
SHPC_dir=sys.argv[1],
my_slice=my_slice,
init_date=sys.argv[2],
with_proj=with_proj,
)