Newer
Older
1
2
3
4
5
6
7
8
9
10
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
import os
import pathlib
import shapefile
def create_slice(SHPC_dir, my_slice, with_proj):
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()
if __name__ == "__main__":
import sys
import f90nml
if len(sys.argv) != 2:
sys.exit("Required argument: SHPC-dir")
if os.access("inst_eddies_nml.txt", os.R_OK):
print(
"Will use inst_eddies_nml.txt, using date in main_nml as first "
"date..."
)
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(sys.argv[1], my_slice, with_proj)