xCDAT / xcdat

An extension of xarray for climate data analysis on structured grids.
https://xcdat.readthedocs.io/en/latest/
Apache License 2.0
106 stars 11 forks source link

[Feature]: Consider implementing the SCRIP or libcf regridder #357

Open pochedls opened 1 year ago

pochedls commented 1 year ago

Is your feature request related to a problem?

Some non-rectangular grids do not provide the cell bounds, which are needed for xESMF to regrid the data. I think the SCRIP regridder may handle these situations.

Example:

import xcdat
import numpy as np

fn='/p/css03/scratch/cmip6/CMIP/CAS/FGOALS-f3-L/historical/r1i1p1f1/SImon/siconc/gn/v20191031/siconc_SImon_FGOALS-f3-L_historical_r1i1p1f1_gn_185001-201412.nc'

nlat = np.arange(-88.75, 90, 2.5)
nlon = np.arange(1.25, 360, 2.5)
ngrid = xcdat.regridder.grid.create_grid(nlat, nlon)

ds = xcdat.open_dataset(fn)
ds = ds.isel(time=[0])
ds2 = ds.regridder.horizontal('siconc', ngrid, tool='xesmf', method='conservative_normed', periodic=True)

KeyError: 'lon_b'

See related issue here.

When I try to regrid this file using CDAT it works and provides the following output:

Warning: avariable.regrid: regridTool = 'esmf' requires bounds for source grid, will switch to regridTool = 'libcf'

This dataset appears to have the same issue: /p/css03/esgf_publish/CMIP6/CMIP/CAS/CAS-ESM2-0/historical/r1i1p1f1/SImon/siconc/gn/v20201225/.

Describe the solution you'd like

Consider providing an interface to the SCRIP regridder (and switching to SCRIP under some conditions, as CDAT does).

Describe alternatives you've considered

No response

Additional context

No response

durack1 commented 1 year ago

This repo looks long-forgotten, but just because I know it exists - https://github.com/SCRIP-Project/SCRIP

rljacob commented 1 year ago

Yes SCRIP is no longer developed. E3SM is using TempestRemap when it doesn't use ESMF so I'd suggest you look there. https://github.com/ClimateGlobalChange/tempestremap

durack1 commented 1 year ago

Another option is libCF, as your CDAT commentary notes - looks like it's still rolling https://github.com/conda-forge/libcf-feedstock

@taylor13 was very complimentary of tempestremap when he investigated..

taylor13 commented 1 year ago

To clarify, I have not actually used tempestremap, but I've read the published papers about the theory, and it looks solid. that being said, as far as I know any regridder operating on anything but a lonxlat rectangular grid needs to know something about the shape of the grid cell (as provided by bounds or cell corner coordinates. Even for lonxlat grids, without bounds the regridder must make an assumption (sometimes incorrect) about where the bounds are.

pochedls commented 1 year ago

I modified this to say "or libcf" because that is what is in the warning message (I had thought SCRIP came up in the warning, but I don't think it does).

I think of this as a lower priority issue. I mostly wanted to document cases where CDAT "works" and xcdat does not. I think if tempest/SCRIP/libcf were implemented and can handle this case, we should provide a warning about the assumptions being made, but it would still be useful to be able to do something reasonable for these kinds of datasets.

rljacob commented 1 year ago

While the libcf conda feedstock is maintained, it looks like the code hasn't been touched in 5 years.

Yes tempestremap needs to know the bounds and most climate model output doesn't have that. You need to get a "grid file" with more complete info.

durack1 commented 1 year ago

Yes tempestremap needs to know the bounds and most climate model output doesn't have that. You need to get a "grid file" with more complete info.

This was theoretically one of the features of SCRIP, though I have not used it personally.

As an aside libCF was an LLNL-ESGF funded sub-project back in 2011/12, which was deprecated (by that project) when ESMF became available