JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

Reduce number of steps to regrid #27

Closed ahuang11 closed 5 years ago

ahuang11 commented 5 years ago

Essentially creates

ds_out = xr.Dataset({'lat': (['lat'], np.arange(15, 75.01, 0.25)),
                     'lon': (['lon'], np.arange(200, 330.01, 0.5)),
                    }
                   )

on the go (finds the min/max of the lon/lat) and regrids; just pass in the ds and d_lon.

If d_lat is None, d_lat will be set to d_lon.

This also handles xr.datasets.

Must have 'lon' and 'lat' as coordinate. If a variable does not have lon or lat, it'll raise a warning and skip, but keep it in the final dataset.

Test notebook: https://anaconda.org/ahuang11/test_xesmf_regrid_it

JiaweiZhuang commented 5 years ago

Thanks for the PR! However I've decided to stick to the two-step approach as explained in #9. This encourages people to reuse weights, which I believe is a good practice. But feel free to build your convenience wrapper!

PS: the handling of Dataset will be available in the next version by utilizing xr.apply_ufunc

ahuang11 commented 5 years ago

Okay, continuing with the two-step approach, what are your thoughts on keeping a part of this PR, particularly just having a util to auto generate a grid with matching max and min coordinates of the current grid? Essentially, util.grid_2d without the need to pass in six arguments; just the original xr.DataArray and resolution?

def grid_2d_auto_detect(da, d_lon, d_lat=None):
    if d_lat is None:
        d_lat = d_lon
    grid_out = grid_2d(da[LON].min(), da[LON].max(), d_lon,
                       da[LAT].min(), da[LAT].max(), d_lat)
    return grid_out