Skip to content

Commit

Permalink
PR #311 post-merge fix: Test if lon_bnds, lat_bnds exist before dropping
Browse files Browse the repository at this point in the history
gcpy/file_regrid.py
- Add if statements to test if lat_bnds and lon_bnds are in the data
  variables of the dataset before trying to drop them from the dataset.

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
Now allow make_regridder_L2L to use nearest_s2d regridding

gcpy/regrid.py
-
  • Loading branch information
yantosca committed Apr 26, 2024
1 parent 5523c97 commit 9377feb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added missing `n_cores` to `gcpy/examples/diagnostics/compare_diags.yml`
- Added missing `plot_drydep` option to `gcpy/gcpy/benchmark/config/1yr_ch4_benchmark.yml`
- Add `docs/requirements.txt` symbolic link to `docs/environment_files/read_the_docs_requirements.txt` for RTD builds
- `gcpy/file_regrid.py` now tests if `lon_bnds`, `lat_bnds` are in the dataset before trying to drop them

### Removed
- Example script `gcpy/examples/plotting/mda8_o3_timeseries.py`
Expand Down
14 changes: 12 additions & 2 deletions gcpy/file_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,10 @@ def regrid_ll_to_ll(
if "lat" not in dset[var].dims \
and "lon" not in dset[var].dims
]
dset = dset.drop(["lat_bnds", "lon_bnds"])
if "lat_bnds" in dset.data_vars:
dset = dset.drop(["lat_bnds"])
if "lon_bnds" in dset.data_vars:
dset = dset.drop(["lon_bnds"])
non_fields = dset[non_fields]
dset = dset.drop(non_fields)

Expand All @@ -756,14 +759,21 @@ def regrid_ll_to_ll(
dim_format_out="classic"
)

# Decide if we are regridding a data file or a mask
# by testing for the variable name "MASK"
method = "conservative"
if "MASK" in dset.data_vars:
method = "nearest_s2d"

# Create the regridder and regrid the data
regridder = make_regridder_L2L(
ll_res_in,
ll_res_out,
reuse_weights=True,
in_extent=in_extent,
out_extent=out_extent,
weightsdir=weightsdir
weightsdir=weightsdir,
method=method,
)
dset = regridder(
dset,
Expand Down

0 comments on commit 9377feb

Please sign in to comment.