Skip to content

Commit 08c38df

Browse files
committed
Use shared functionailty for calling ncremap
1 parent 25f71db commit 08c38df

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

compass/landice/tests/ismip6_GrIS_forcing/ref_smb_climatology.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import xarray as xr
44
from mpas_tools.io import write_netcdf
5-
from mpas_tools.logging import check_call
65

6+
from compass.landice.tests.ismip6_GrIS_forcing.utilities import remap_variables
77
from compass.step import Step
88

99

@@ -33,7 +33,6 @@ def setup(self):
3333
config = self.config
3434
smb_ref_section = config["smb_ref_climatology"]
3535

36-
#
3736
racmo_directory = smb_ref_section.get("racmo_directory")
3837
# this filename should probably just be hardcoded.....
3938
racmo_smb_fn = smb_ref_section.get("racmo_smb_fn")
@@ -70,6 +69,9 @@ def setup(self):
7069
def run(self):
7170
"""
7271
"""
72+
racmo_smb = self.racmo_smb
73+
smb_ref_climatology = self.test_case.smb_ref_climatology
74+
racmo_2_mali_weights = self.test_case.racmo_2_mali_weights
7375

7476
# parse user specified parameters from the config
7577
config = self.config
@@ -79,12 +81,11 @@ def run(self):
7981
clima_end = smb_ref_section.getint("climatology_end")
8082

8183
# remap the gridded racmo data onto the mpas grid
82-
self.remap_variable(self.racmo_smb,
83-
self.test_case.smb_ref_climatology,
84-
self.test_case.racmo_2_mali_weights)
84+
remap_variables(
85+
racmo_smb, smb_ref_climatology, racmo_2_mali_weights, ["SMB_rec"]
86+
)
8587

86-
ds = xr.open_dataset(self.test_case.smb_ref_climatology,
87-
decode_times=False)
88+
ds = xr.open_dataset(smb_ref_climatology, decode_times=False)
8889

8990
# find indices of climatology start/end (TO DO: make more robust)
9091
s_idx = ((clima_start - 1958) * 12) - 1
@@ -105,17 +106,4 @@ def run(self):
105106
# expand sfcMassBal dimension to match what MALI expects
106107
ds["sfcMassBal"] = ds.sfcMassBal.expand_dims("Time")
107108
# write the file
108-
write_netcdf(ds, self.test_case.smb_ref_climatology)
109-
110-
def remap_variable(self, input_file, output_file, weights_file):
111-
"""
112-
"""
113-
114-
# remap the forcing file onto the MALI mesh
115-
args = ["ncremap",
116-
"-i", input_file,
117-
"-o", output_file,
118-
"-m", weights_file,
119-
"-v", "SMB_rec"]
120-
121-
check_call(args, logger=self.logger)
109+
write_netcdf(ds, smb_ref_climatology)

0 commit comments

Comments
 (0)