pytroll / pytroll/pyresample

Performance improvement: `AreaDefinition.__getitem__` force to lons/lats array recomputations after slicing

Open
#411 9 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.