Skip to content

Commit 9b22bcd

Browse files
committed
modify according to new bctide main input and fix line indents.
1 parent bdde89f commit 9b22bcd

1 file changed

Lines changed: 104 additions & 77 deletions

File tree

schimpy/bctide.py

Lines changed: 104 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,38 @@
1414
__all__ = ["load_boundary"]
1515

1616

17-
def load_boundary(fn):
17+
def load_main_input(main_yaml):
18+
""" read in main yaml file which contians the grid topology and
19+
boundary condtion yaml files, this input file looks like below
20+
mesh:
21+
mesh_inputfile: ./hgrid.gr3
22+
open_boundaries: !include open_boundary.yaml
23+
24+
bctides:
25+
bctides.in.2d: !include bctides.in.2d.yaml
26+
bctides.in.3d: !include bctides.in.3d.yaml
27+
bctides.in.sed.3d: !include bctides.in.sed.3d.yaml
28+
29+
for each boundary condition yaml file, it will generate the corresponding boundary
30+
class and write out the SCHISM boundary condition btdides input file.
31+
"""
32+
with open(main_yaml, "r") as fn:
33+
main_yaml_dict = load(fn)
34+
35+
mesh_in = main_yaml_dict["mesh"]["mesh_inputfile"]
36+
sr = SchismMeshGr3Reader()
37+
hgrid = sr.read(mesh_in)
38+
open_boundary = None
39+
if "open_boundaries" in main_yaml_dict["mesh"].keys():
40+
open_boundary = main_yaml_dict["mesh"]["open_boundaries"]
41+
42+
bctides_dic = main_yaml_dict["bctides"]
43+
for bctides_key in bctides_dic.keys():
44+
bctides_yaml = bctides_dic[bctides_key]
45+
by = load_boundary(bctides_yaml,hgrid)
46+
by.write_bctides(bctides_key)
47+
48+
def load_boundary(hgrid,fn):
1849
return boundary(fn)
1950

2051

@@ -23,78 +54,76 @@ class boundary(object):
2354
A class to generate boundary condition input file for SCHISM
2455
"""
2556

26-
def __init__(self, yaml_fn=None):
27-
28-
with open(yaml_fn, "r") as fn:
29-
bc_yaml = load(fn)
30-
31-
main_id = "bctides"
32-
self.date = bc_yaml[main_id]["date"]
33-
if "earth_tidals" in bc_yaml[main_id].keys():
34-
self.earth_tidals = bc_yaml[main_id]["earth_tidals"]
35-
else:
36-
self.earth_tidals = None
37-
if "bounary_forcing_tidals" in bc_yaml[main_id].keys():
38-
self.boundary_tidals = bc_yaml[main_id]["bounary_forcing_tidals"]
39-
else:
40-
self.boundary_tidals = None
41-
42-
self.open_boundaries = bc_yaml[main_id]["open_boundaries"]
43-
self.hgrid = bc_yaml[main_id]["hgrid_input_file"]
44-
45-
self.elev_type = {
46-
"elev.th": 1,
47-
"constant": 2,
48-
"tidal": 3,
49-
"elev2D.th.nc": 4,
50-
"tidal elev2D.th.nc": 5,
51-
"none": 0,
52-
}
53-
self.vel_type = {
54-
"flux.th": 1,
55-
"constant": 2,
56-
"tidal": 3,
57-
"uv3D.th.nc": 4,
58-
"tidal uv3D.th.nc": 5,
59-
"flather 1": -1,
60-
"none": 0,
61-
}
62-
63-
self.temp_type = {
64-
"TEM_1.th": 1,
65-
"constant": 2,
66-
"initial profile": 3,
67-
"TEM_3D.th.nc": 4,
68-
"none": 0,
69-
}
70-
71-
self.salt_type = {
72-
"SAL_1.th": 1,
73-
"constant": 2,
74-
"initial profile": 3,
75-
"SAL_3D.th.nc": 4,
76-
"none": 0,
77-
}
78-
79-
## tracer order
80-
self.tracer_lst = {
81-
"GEN": 1,
82-
"AGE": 2,
83-
"SED": 3,
84-
"ECO": 4,
85-
"ICM": 5,
86-
"COSINE": 6,
87-
"FECO": 7,
88-
"TIMOR": 8,
89-
"FABM": 9,
90-
"DVD": 10,
91-
}
92-
self.tracer_type = {
93-
"time history": 1,
94-
"constant": 2,
95-
"initial profile": 3,
96-
"none": 0,
97-
}
57+
def __init__(self, hgrid,bc_yaml=None):
58+
""" initialize the boundary condition from yaml file"""
59+
60+
main_id = "bctides"
61+
self.date = bc_yaml[main_id]["date"]
62+
if "earth_tidals" in bc_yaml[main_id].keys():
63+
self.earth_tidals = bc_yaml[main_id]["earth_tidals"]
64+
else:
65+
self.earth_tidals = None
66+
if "bounary_forcing_tidals" in bc_yaml[main_id].keys():
67+
self.boundary_tidals = bc_yaml[main_id]["bounary_forcing_tidals"]
68+
else:
69+
self.boundary_tidals = None
70+
71+
self.open_boundaries = bc_yaml[main_id]["open_boundaries"]
72+
self.hgrid = hgrid
73+
74+
self.elev_type = {
75+
"elev.th": 1,
76+
"constant": 2,
77+
"tidal": 3,
78+
"elev2D.th.nc": 4,
79+
"tidal elev2D.th.nc": 5,
80+
"none": 0,
81+
}
82+
self.vel_type = {
83+
"flux.th": 1,
84+
"constant": 2,
85+
"tidal": 3,
86+
"uv3D.th.nc": 4,
87+
"tidal uv3D.th.nc": 5,
88+
"flather 1": -1,
89+
"none": 0,
90+
}
91+
92+
self.temp_type = {
93+
"TEM_1.th": 1,
94+
"constant": 2,
95+
"initial profile": 3,
96+
"TEM_3D.th.nc": 4,
97+
"none": 0,
98+
}
99+
100+
self.salt_type = {
101+
"SAL_1.th": 1,
102+
"constant": 2,
103+
"initial profile": 3,
104+
"SAL_3D.th.nc": 4,
105+
"none": 0,
106+
}
107+
108+
## tracer order
109+
self.tracer_lst = {
110+
"GEN": 1,
111+
"AGE": 2,
112+
"SED": 3,
113+
"ECO": 4,
114+
"ICM": 5,
115+
"COSINE": 6,
116+
"FECO": 7,
117+
"TIMOR": 8,
118+
"FABM": 9,
119+
"DVD": 10,
120+
}
121+
self.tracer_type = {
122+
"time history": 1,
123+
"constant": 2,
124+
"initial profile": 3,
125+
"none": 0,
126+
}
98127

99128
def write_bctides(self, bctides_file):
100129

@@ -162,10 +191,8 @@ def write_bctides(self, bctides_file):
162191
num_tidal = 0
163192
outf.write(str(num_tidal) + "\n")
164193

165-
## output open boundaries
166-
## read in mesh grid file
167-
sr = SchismMeshGr3Reader()
168-
hgrid = sr.read(self.hgrid)
194+
195+
hgrid = self.hgrid
169196

170197
if len(hgrid.boundaries) < len(self.open_boundaries):
171198
raise ValueError(

0 commit comments

Comments
 (0)