Add reproject method to AreaDefinition
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 385
- Forks
- 102
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 9
Description
Feature Request
Is your feature request related to a problem? Please describe.
Sometimes I just want to reproject an AreaDefinition e.g. use a different projection but keep the extent and also use a resolution "close" to the source AreaDefinition. Even with all the helpers for creating AreaDefinitions this
is a little cumbersome and takes to much time especially if this is just needed "on-the-fly" (meaning not worth putting it into a yaml file to keep it around).
Describe the solution you'd like
It would be nice to have a reproject method which produces a new AreaDefinition with the given projection.
For use in our working group I created the following some time ago:
import pyproj
from pyresample import geometry
from pyresample.utils.proj4 import proj4_dict_to_str
def reproject_area(area, target_proj):
"""
Reprojects area to target projection
Createa a new area definition in the target projection
while keeping the geographic extent and spatial resolution
of the source area.
Parameters
----------
area : pyresample area definition
target_proj : proj dict
Returns
-------
area
Todo
----
- handling of area definitions based solely on lat/lon
e.g. swath areas
- allow other inputs for target_proj than proj4 dicts
"""
if type(area) == geometry.SwathDefinition:
return NotImplementedError("Areas of type swath are currently not supported!")
area_id = area.area_id
area_desc = area.name
pcs_id = target_proj["proj"]
target_crs = pyproj.CRS.from_proj4(proj4_dict_to_str(target_proj))
xmax, ymax, xmin, ymin = area.area_extent
transformer = pyproj.Transformer.from_crs(area.crs, target_crs, always_xy=True)
xx, yy = transformer.transform([xmin, xmax], [ymin, ymax])
target_extent = [xx[0], yy[0], xx[1], yy[1]]
area_res_x = (xmax - xmin) / area.x_size
area_res_y = (ymax - ymin) / area.y_size
target_size_x = abs(int((target_extent[2] - target_extent[0]) / area_res_x))
target_size_y = abs(int((target_extent[3] - target_extent[1]) / area_res_y))
return geometry.AreaDefinition(area_id, area_desc, pcs_id, target_proj, target_size_x, target_size_y, target_extent)
This currently does not support swath areas and it would be nice to accept other projection formats than proj4 dicts. Also depending on the source area projection handling of the resolution calculation might need some refinement.
Describe any changes to existing user workflow
None.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate AreaDefinition in pyresample.geometry and compare it with the supplied reproject_area example; inspect existing CRS, extent, and resolution handling first. Define completion around a method that creates a new AreaDefinition for another projection while preserving the source extent and resolution intent, and account for the noted swath and projection-input cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100