Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add reproject method to AreaDefinition

Aperta
#366 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Individuate AreaDefinition in pyresample.geometry e confrontatelo con l’esempio reproject_area fornito; esaminate innanzitutto la gestione esistente di CRS, estensione e risoluzione. Definite il completamento sulla base di un metodo che crei un nuovo AreaDefinition per un’altra proiezione, preservando l’estensione di origine e l’intento della risoluzione, e tenete conto dei casi indicati relativi a swath e input di proiezione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

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.

Lingua principale
Python
Stelle
388
Fork
102
Merge medio
5g 17h
PR unite (30g)
5

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytroll/pyresample

Tutte le issue di pytroll/pyresample

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.