1

I have a dataset at a given resolution and its variable is an Area measure. When regridding to another resolution, the techniques are usually interpolation (bilinear, conservative, etc.), but this would only work for variables where the value is independent of the size of the grid (Think of temperature or precipitation). Because I'm using an Area variable, this would not work as if I want to upscale the resolution of the grid, the Area should be summed instead of interpolated. Therefore, I would like to upscale or group or sum my Area variable according to the change in coordinates (If I upscale 2x across lat and lon, the area would be multiplied by 4, as in the example below), but I do not know how to do it.

Example below:

What I currently have:

test_stack
Out[20]: 
<xarray.DataArray 'Harvested_area' (time: 1, lat: 2, lon: 2)>
array([[[10, 10],
        [10, 10]]])
Coordinates:
  * time     (time) int32 1981
  * lat      (lat) float64 6.246 6.237
  * lon      (lon) float64 -74.25 -74.24

What I would like to have:

sum_test_stack
Out[20]: 
<xarray.DataArray 'Harvested_area' (time: 1, lat: 1, lon: 1)>
array([[[40]]])
Coordinates:
  * time     (time) int32 1981
  * lat      (lat) float64 6.246
  * lon      (lon) float64 -74.25

Thank you!

Henrique
  • 135
  • 6
  • Do you solely plan to go from finer to coarser resolution? – cobarzan Jul 23 '21 at 23:58
  • Thank you for the reply. At the current time, yes. But it would be interesting to know if there is a possibility of doing both directions as well. – Henrique Jul 26 '21 at 09:09
  • Both ways are projection dependent. If you just want to use a latlon grid and accept area is distorted by it, then it can be done both ways easily. – cobarzan Jul 26 '21 at 20:52
  • Ok, let's say then we want to go from finer to coarser only. How would this aggregation technique work out for additive units? – Henrique Jul 27 '21 at 09:32

1 Answers1

1

Try looking at xarray.DataArray.coarsen, using a simple sum as the function. https://docs.xarray.dev/en/stable/generated/xarray.DataArray.coarsen.html

hudowudo
  • 26
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '22 at 07:23