Skip to content

Commit

Permalink
Fix xesmf regridder api use
Browse files Browse the repository at this point in the history
  • Loading branch information
zklaus committed Jul 20, 2022
1 parent c129f8a commit 6fb8cc9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions esmvaltool/cmorizers/data/formatters/datasets/cds_uerra.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def _regrid_dataset(in_dir, var, cfg):
# Match any year here
filepattern = var['file'].format(year='????', month='??')
filelist = glob.glob(os.path.join(in_dir, filepattern))
regridder = None
for infile in filelist:
_, infile_tail = os.path.split(infile)
outfile = os.path.join(cfg['work_dir'], infile_tail)
Expand All @@ -230,16 +231,15 @@ def _regrid_dataset(in_dir, var, cfg):
assert int((input_da == 0.).sum()) == 0 # Make sure that there
# are no zero's in the data,
# since they will be masked out
shape_in = input_ds["lon"].shape
shape_out = targetgrid_ds["lon"].shape
weights_filename = (
f"bilinear_"
f"{shape_in[0]}x{shape_in[1]}_{shape_out[0]}x{shape_out[1]}.nc")
regridder = xe.Regridder(input_ds,
targetgrid_ds,
'bilinear',
reuse_weights=True,
filename=weights_filename)
shapes = (input_ds["lon"].shape, input_ds["lat"].shape,
targetgrid_ds["lon"].shape, targetgrid_ds["lat"].shape)
if regridder is None:
regridder = xe.Regridder(input_ds,
targetgrid_ds,
'bilinear')
ref_shapes = shapes
else:
assert shapes == ref_shapes
da_out = regridder(input_da)
da_out = da_out.where(da_out != 0.)
da_out = da_out - constantval
Expand Down

0 comments on commit 6fb8cc9

Please sign in to comment.