Performance improvement: `AreaDefinition.__getitem__` force to lons/lats array recomputations after slicing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 385
- Forks
- 102
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 9
Description
Problem description
Currently, the method AreaDefinition.__getitem__ (L2436 of geometry.py), when performing AreaDefinition slicing, it discards the possible precomputed lons/lats arrays attached to the class instance.
In the case of a large AreaDef (i.e. geostationary), recomputation of lons/lats after a slicing can take several seconds if the sliced domain is quite large.
Proposition of code to add to AreaDefinition.__getitem__
if self.lats is not None:
lats = lats[yslice, xslice]
else:
lats = None
if self.lons is not None:
lons = lons[yslice, xslice]
else:
lons = None
# Pass lats, lons to the AreaDefinition call
new_area = AreaDefinition(self.area_id, self.description,
self.proj_id, self.crs,
total_cols,
total_rows,
new_area_extent,
lons = lons, lats = lats) # NEW
Side note
The same approach could be employed to also avoid the recomputation of the cartesian_coords attribute.
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
Start in pyresample/geometry.py at AreaDefinition.getitem around line 2436 and inspect how slicing constructs the new AreaDefinition. Check the existing coordinate attributes and validate that slicing preserves already computed values without forcing recomputation; also consider whether the mentioned cartesian_coords case is in scope. Done means sliced areas retain available precomputed coordinates and existing tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100