Skip to content

Commit 15afe46

Browse files
authored
Simplify the create_regridder function (#220)
* Update Create Regridder Func * update * Unmapped to Nan and warning * Black
1 parent adae56d commit 15afe46

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

regional_mom6/regridding.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import numpy as np
2929
import netCDF4
3030
from regional_mom6.utils import setup_logger, get_edge
31-
31+
from os.path import isfile
3232

3333
regridding_logger = setup_logger(__name__, set_handler=False)
3434

@@ -240,23 +240,20 @@ def create_regridder(
240240
"""
241241
regridding_logger.info("Creating Regridder")
242242

243-
# If outfile exists, reuse weights generated from outfile
244-
if outfile is not None and Path(outfile).exists():
243+
weights_exist = bool(outfile) and isfile(outfile)
244+
if weights_exist:
245245
regridding_logger.warning(
246246
f"Using existing weights file at {outfile} to save computing time. Delete weights file to regenerate weights."
247247
)
248-
reuse_weights = True
249-
else:
250-
reuse_weights = False
251-
252248
regridder = xe.Regridder(
253249
forcing_variables,
254250
output_grid,
255251
method=method,
256252
locstream_out=locstream_out,
257253
periodic=periodic,
258254
filename=outfile,
259-
reuse_weights=reuse_weights,
255+
reuse_weights=weights_exist,
256+
unmapped_to_nan=True,
260257
)
261258

262259
return regridder

0 commit comments

Comments
 (0)