duplicate an AreaDefinition object with coarser/finer definition
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.
Sounds good. How about you can also make the grid coarser ? like half the cells in x and y ?
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) ?
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)
?
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).
And just to think ahead: I see two applications of this:
-
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.
-
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).
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.
@TomLav what's the status on this ?
I have a version of that in my modules somewhere, but never pushed it to the codebase.
Please do :)