Skip to content

Commit 4fc9856

Browse files
committed
Update to newer format
Pareser updated to the newer variable structure
1 parent 6b9bd8c commit 4fc9856

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

schimpy/bctide.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ def write_bctides(self, bctides_file):
650650
## as temperature, salinity or other scalars
651651

652652
if "flow_direction" in self.open_boundaries[i].keys():
653-
flow_direction = self.open_boundaries[i]["flow_directions"]
653+
flow_direction = self.open_boundaries[i]["flow_direction"]
654654
if "flow_direction" == "outflow":
655655
if "temperature" in self.open_boundaries[i].keys():
656656
raise ValueError(
@@ -670,8 +670,16 @@ def write_bctides(self, bctides_file):
670670

671671

672672

673-
if "elevation" in self.open_boundaries[i]["variables"].keys():
674-
elev_boundary = self.open_boundaries[i]["variables"]["elevation"]
673+
# variables in YAML are provided as a list of dicts; helper to find a variable entry
674+
vars_list = self.open_boundaries[i].get("variables", [])
675+
def _get_var(name):
676+
for vv in vars_list:
677+
if isinstance(vv, dict) and name in vv:
678+
return vv[name]
679+
return None
680+
681+
if _get_var("elevation") is not None:
682+
elev_boundary = _get_var("elevation")
675683
elev_source = elev_boundary["source"]
676684
elev_key = elev_source
677685
if isinstance(elev_source, numbers.Number):
@@ -688,8 +696,8 @@ def write_bctides(self, bctides_file):
688696

689697
vel_id = 0
690698
vel_boundary = None
691-
if "velocity" in self.open_boundaries[i]["variables"].keys():
692-
vel_boundary = self.open_boundaries[i]["variables"]["velocity"]
699+
if _get_var("velocity") is not None:
700+
vel_boundary = _get_var("velocity")
693701
vel_source = vel_boundary["source"]
694702
vel_key = vel_source
695703

@@ -711,23 +719,23 @@ def write_bctides(self, bctides_file):
711719
## output temperature and salinity boundary
712720
temp_id = 0
713721
temp_boundary = None
714-
if "temperature" in self.open_boundaries[i]["variables"].keys():
715-
temp_boundary = self.open_boundaries[i]["variables"]["temperature"]
722+
if _get_var("temperature") is not None:
723+
temp_boundary = _get_var("temperature")
716724
temp_source = temp_boundary["source"]
717725
temp_key = temp_source
718726
if isinstance(temp_source, numbers.Number):
719727
temp_key = "constant"
720728

721729
try:
722-
temp_id = self.vel_source[vel_key]
730+
temp_id = self.temp_source[temp_key]
723731
except:
724732
raise ValueError(
725733
temp_key + " temperature boundary is not supported"
726734
)
727735
salt_id = 0
728736
salt_boundary = None
729-
if "salinity" in self.open_boundaries[i]["variables"].keys():
730-
salt_boundary = self.open_boundaries[i]["variables"]["salinity"]
737+
if _get_var("salinity") is not None:
738+
salt_boundary = _get_var("salinity")
731739
salt_source = salt_boundary["source"]
732740
salt_key = salt_source
733741
if isinstance(salt_source, numbers.Number):
@@ -744,13 +752,12 @@ def write_bctides(self, bctides_file):
744752
tracer_boundary_sources = [0] * len(self.tracer_mod_pos)
745753
## this list save sorted tracer boundary index according to SCHISM code order
746754
tracer_boundary_lst_sorted = []
747-
if "tracers" in self.open_boundaries[i]["variables"].keys():
748-
boundary_tracer_mod_num = len(
749-
self.open_boundaries[i]["variables"]["tracers"]
750-
)
755+
if _get_var("tracers") is not None:
756+
tracers_var = _get_var("tracers")
757+
boundary_tracer_mod_num = len(tracers_var)
751758
for j in range(boundary_tracer_mod_num):
752-
tracer_boundary = self.open_boundaries[i]["variables"]["tracers"][j]["source"]
753-
tracer_mod = self.open_boundaries[i]["variables"]["tracers"][j]["module"]
759+
tracer_boundary = tracers_var[j]["source"]
760+
tracer_mod = tracers_var[j]["module"]
754761
## if tracer mod not in self.tracer_mod_pos, raise error
755762
if not (tracer_mod in self.tracer_mod_pos.keys()):
756763
raise ValueError(
@@ -795,7 +802,7 @@ def write_bctides(self, bctides_file):
795802

796803
tracer_boundary_lst_sorted.sort(
797804
key=lambda jj: self.tracer_mod_pos[
798-
self.open_boundaries[i]["tracers"][jj]["tracer"]
805+
tracers_var[jj]["module"]
799806
]
800807
)
801808
outf.write(str(num_nodes) + " ")
@@ -919,7 +926,7 @@ def write_bctides(self, bctides_file):
919926
## tracer bc paraemters
920927
for ii in range(len(tracer_boundary_lst_sorted)):
921928
tracer_index = tracer_boundary_lst_sorted[ii]
922-
tracer = self.open_boundaries[i]["tracers"][tracer_index]
929+
tracer = _get_var("tracers")[tracer_index]
923930
tracer_bc_source = tracer_boundary_sources[ii]
924931
if tracer_bc_source == 2:
925932
tracer_bc_const = tracer["source"]

0 commit comments

Comments
 (0)