pyresample icon indicating copy to clipboard operation
pyresample copied to clipboard

duplicate an AreaDefinition object with coarser/finer definition

Open TomLav opened this issue 10 years ago • 9 comments

Add a feature for the AreaDefinition class (https://pyresample.readthedocs.org/en/latest/geo_def.html#areadefinition). I would need a class method that creates a new AreaDef object from an existing one. The new AreaDef has the same projection and coordinate extent, but the grid_spacing (equivalently the number of gridpoints x_size and y_size) is scaled by a factor provided by the user. This would return a new AreaDef that matches exactly the existing one, but with twice (thrice, four times as much) the original resolution.

Example:

area_def = geometry.AreaDefinition(area_id, name, proj_id, proj_dict, x_size,y_size, area_extent)
new_area_def = area_def.finer_grid_spacing(3,2)

new_aera_def now has three times as much cells in the x axis, and twice in the y axis. If only 1 value is given, the same is used for x and y.

TomLav avatar Nov 20 '15 08:11 TomLav

Sounds good. How about you can also make the grid coarser ? like half the cells in x and y ?

mraspaud avatar Nov 20 '15 08:11 mraspaud

Originally, my request also had getting the coarser grid spacing. But mixing the two in a single function meant a lot of checks and documentation. Maybe have another method like: new_area_def = area_def.coarser_grid_spacing(3,2) ?

TomLav avatar Nov 20 '15 08:11 TomLav

what about the user provides the number of cells he/she/it wants to have, like:

new_area_def = area_def.new_grid_size(x_size / 2, y_size * 3)

?

mraspaud avatar Nov 20 '15 08:11 mraspaud

Could work. But the routine has to check the validity of the input (that they are exactly multiples or fractions of what is already there).

TomLav avatar Nov 20 '15 09:11 TomLav

And just to think ahead: I see two applications of this:

  1. motion detection. For motion detection from cross-correlation techniques you need two grids: the target grid which is the grid locations where you will have your motion vectors on, and the imaging grid, which is much finer resolution, and is where you reproject your satellite images. The motion algorithms are much easier to write if the two grids are exactly in line, but the imaging grid has finer resolution.

  2. anti-aliasing in pyresample: here the idea is to instantiate a finer grid than the target area_def, do the pyresample against the finer grid, and finally collect the resampled output from the finer grid to the original target grid (simple average).

TomLav avatar Nov 20 '15 09:11 TomLav

Sounds good. I was just thinking of that this could be quite generic and allow any size, but I can see the utility of having the method allowing only integer ratios.

mraspaud avatar Nov 20 '15 09:11 mraspaud

@TomLav what's the status on this ?

mraspaud avatar Apr 23 '18 12:04 mraspaud

I have a version of that in my modules somewhere, but never pushed it to the codebase.

TomLav avatar Apr 24 '18 07:04 TomLav

Please do :)

mraspaud avatar Apr 24 '18 08:04 mraspaud