Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add Resampler helper decorators

Abierto
#360 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
numpy, python
Área
data

Línea de trabajo

Comienza revisando el ejemplo de dimension-checker de #341 y las referencias a BaseResampler y resamplers.utils en el ejemplo de array-converter propuesto. Define las comprobaciones compatibles de dimensiones, clases de arrays y geometrías, y verifica después que los helpers resultantes cubran los casos de Resampler descritos en el issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement
Context

The assigned developers (among others) have been meeting during the Spring 2021 PCW to discuss a Pyresample 2.0. This issue discusses one of the changes that we think should be implemented on our road to version 2.0. Most features for version 2.0 will be backwards compatible and will not require a deprecation cycle.

For related issues, see the other issues in the v2.0 milestone (see sidebar).

Dimension Checker

A common limitation or check that has to be done on Resampler provided data is the number of dimensions the input data has and what the resampler can accept. To help with this we propose a decorator that checks and slices arrays so that they can be passed to the resample method. Similar work has been done by Martin in #341:

def ensure_3d_data(func):
    """Ensure the data is in three dimensions."""
    @wraps(func)
    def wrapper(data, *args, **kwargs):
        """Wrap around the original function."""
        if data.ndim == 2:
            data_3d = data[np.newaxis, :, :]
        else:
            data_3d = data

        resampled = func(data_3d, *args, **kwargs)

        if data.ndim == 2:
            resampled = resampled.squeeze(0)
        return resampled

    return wrapper

There could also be one for 3D+ to 2D when we know what dimensions are Y and X.

Array Class Converter

Sometimes algorithms are written with specific classes in mind. They could be written specifically for xarray objects or may only work efficiently for numpy arrays. A decorator that converts between the common cases or raises an exception when things can be converted would simplify a lot of logic for the resamplers and reduce duplicate code. I'm not exactly sure what this would look like but here's what I propose originally:

from pyresample.resamplers import BaseResampler
from pyresample.resamplers.utils import array_converter
from pyresample import register_resampler

@register_resampler('some_name')
class MyResamplerClass(BaseResampler):
	...

	@array_converter(as_numpy=True, as_dask=True, as_xr_data_array=True,
                     as_xr_dataset=True, as_arraylike=True)
	@require_2d()  # produce 2D with (y, x) - see DaskResampler ensure_3d
    def resample(self, data, ...):
        self.precompute(...)
        return self.compute()

Other options might be to require the resampler to pick a single input type and simplify what the array converted decorator looks like.

Geometry Checker

A decorator to check what geometry types have been provided to the resampler and verifies that the resampler knows how to resample from one geometry type to another could be helpful. Here's an example:

class MyResampler(BaseResampler):
    @instance_check({
        SwathDefinition: [SwathDefinition, AreaDefinition],
        AreaDefinition: [AreaDefinition],
    })
    def __init__(self, src_geom, dst_geom):
        super().__init__(src_geom, dst_geom)

This says that this resampler can resample from SwathDefinitions to SwathDefinitions or AreaDefinitions or it can resample AreaDefinitions to AreaDefinitions, but no other combinations.

Lenguaje dominante
Python
Estrellas
388
Forks
103
Merge medio
7 d 4 h
PR fusionados (30 d)
4

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytroll/pyresample

Todos los issues de pytroll/pyresample

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.