Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add Resampler helper decorators

オープン
#360 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
numpy, python
領域
data

調査の方向性

まず、#341 の dimension-checker の例と、提案されている array-converter の例にある BaseResampler および resamplers.utils の参照を確認します。サポートする次元、配列クラス、ジオメトリのチェックを定義し、その結果得られるヘルパーが、issue に記載された Resampler のケースを網羅していることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
388
フォーク
103
平均マージ
5日 17時間
マージ済み PR(30日)
5

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytroll/pyresample のほかの issue

pytroll/pyresample の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。