Skip to content

Commit 07da14a

Browse files
committed
Use typing to make sure component is Ocean
...in OceanIoStep and OceanModelStep
1 parent ebd8ef1 commit 07da14a

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

polaris/ocean/model/ocean_io_step.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ class OceanIOStep(Step):
77
A step that writes input and/or output files for Omega or MPAS-Ocean
88
"""
99

10+
# make sure component is of type Ocean
11+
component: Ocean
12+
13+
def __init__(self, component: Ocean, **kwargs):
14+
super().__init__(component=component, **kwargs)
15+
1016
def map_to_native_model_vars(self, ds):
1117
"""
1218
If the model is Omega, rename dimensions and variables in a dataset
@@ -24,10 +30,6 @@ def map_to_native_model_vars(self, ds):
2430
The same dataset with variables renamed as appropriate for the
2531
ocean model being run
2632
"""
27-
if not isinstance(self.component, Ocean):
28-
raise TypeError(
29-
'component must be an instance of Ocean to map model vars'
30-
)
3133
return self.component.map_to_native_model_vars(ds)
3234

3335
def write_model_dataset(self, ds, filename):
@@ -43,10 +45,6 @@ def write_model_dataset(self, ds, filename):
4345
filename : str
4446
The path for the NetCDF file to write
4547
"""
46-
if not isinstance(self.component, Ocean):
47-
raise TypeError(
48-
'component must be an instance of Ocean to map model vars'
49-
)
5048
self.component.write_model_dataset(ds, filename)
5149

5250
def map_from_native_model_vars(self, ds):
@@ -65,10 +63,6 @@ def map_from_native_model_vars(self, ds):
6563
ds : xarray.Dataset
6664
The same dataset with variables named as expected in MPAS-Ocean
6765
"""
68-
if not isinstance(self.component, Ocean):
69-
raise TypeError(
70-
'component must be an instance of Ocean to map model vars'
71-
)
7266
return self.component.map_from_native_model_vars(ds)
7367

7468
def open_model_dataset(self, filename, **kwargs):
@@ -89,8 +83,4 @@ def open_model_dataset(self, filename, **kwargs):
8983
ds : xarray.Dataset
9084
The dataset with variables named as expected in MPAS-Ocean
9185
"""
92-
if not isinstance(self.component, Ocean):
93-
raise TypeError(
94-
'component must be an instance of Ocean to map model vars'
95-
)
9686
return self.component.open_model_dataset(filename, **kwargs)

polaris/ocean/model/ocean_model_step.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ class OceanModelStep(ModelStep):
2727
working directory)
2828
"""
2929

30+
# make sure component is of type Ocean
31+
component: Ocean
32+
3033
def __init__(
3134
self,
32-
component,
35+
component: Ocean,
3336
name,
3437
subdir=None,
3538
indir=None,
@@ -337,10 +340,6 @@ def validate_baselines(self):
337340
success : bool
338341
Whether the outputs were successfully validated against a baseline
339342
"""
340-
if not isinstance(self.component, Ocean):
341-
raise TypeError(
342-
'component must be an instance of Ocean to map model vars'
343-
)
344343
# translate variable names to native model names
345344
validate_vars = {}
346345
for filename, vars in self.validate_vars.items():

0 commit comments

Comments
 (0)