Closed Timothy-W-Hilton closed 4 days ago
conservative regridding preserves the integral over the area: (cell area * cell value).sum()
@huard, thanks, that equation is really helpful. I understand what's happening now.
So I understand now that I need the the cell areas to test that my regrid didn't add or subtract mass. As far as I can tell, xESMF calculates the cell areas internally but does not expose them via the user API. I'm now calculating areas like the below, inspired by this and this. Have I missed a more streamlined way to use xESMF or ESMPy to get cell areas?
Did merging the area branch into main ever get considered (implements xesmf.util.cell_area()? That seems like it would be useful (at least to me).
def grid_calc_area(g: xesmf.backend.Grid):
"""calculate grid cell area in metres squared
calculate grid cell area in metres squared
Parameters
----------
g : xesmf.backend.Grid
xesmf grid object specifying the grid. For a regridding problem, can use
grid_in and grid_out fields of a xesmf.Regridder object.
Examples
--------
FIXME: Add docs.
"""
M_PER_KM = 1000.0
REARTH = 6371.0 * M_PER_KM # mean radius of Earth, in m
f = esmpy.Field(g)
f.get_area()
# esmpy.Field.get_area assumes a unit sphere. The surface area of a sphere
# is 4*pi*r^2. Therefore to get area on the actual earth in m2 from unit
# sphere grid cell area, multiply by REARTh^2.
area = f.data * REARTH**2
return area
Hi @Timothy-W-Hilton. We could indeed give some attention to the area
branch, I didn't even know it existed! This could be a nice and easy addition to xESMF
.
Hi @Timothy-W-Hilton. We could indeed give some attention to the
area
branch, I didn't even know it existed! This could be a nice and easy addition toxESMF
.
Thanks @aulemahal, that sounds great. I wanted to bring it up but also allow room for whatever I don't know e.g. "oh no we argued about that for months three years ago and no one wants to re-open that can of worms". 😝
My conservative regrid is producing a regridded dataset whose sum is lower by a factor of nearly 10. I am sure I am misunderstanding the way that conservative is defined or the input requirements of xesmf.Regridder, but I sure haven't been able to figure out how.
A minimal example, using two grids in the area of Auckland, New Zealand.
For me this results in ds_source total: 9.0882e+04 ds_regridded total: 1.0098e+04
I expected ds_regridded.sum() to be very close to 9.0882e+04.