When using the resample_nearest function in pyresample for interpolation, it sometimes produces NaN values.

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

メンテナーはふだん 1 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
numpy, python
領域
data

調査の方向性

まず、提供された再現コードを、指定された NumPy データと resample_nearest の繰り返し呼び出しで実行します。resample_nearest のエントリポイントと、関連する pyresample kd-tree リサンプリングパスを読み、近傍にソースデータがあるにもかかわらず、なぜ 1 つのチャネル全体が NaN になり得るのかを特定します。繰り返し実行しても決定論的な結果が得られ、予期しない全体が all-NaN になる出力が発生せず、プロジェクトの既存のテスト構成が対応している場合は回帰テストも追加されていれば完了です。

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

説明

When I use the following code to interpolate the data, I find that the results occasionally contain NaN values after multiple runs.

import numpy as np
from pyresample.geometry import SwathDefinition, AreaDefinition
from pyresample.kd_tree import resample_nearest
import os
def resample_wgs84_to_grid(lat2d, lon2d, data2d,
                           lons_1d, lats_1d,
                           radius_of_influence=50000,
                           fill_value=np.nan):
    np.random.seed(42)

    src_swath = SwathDefinition(lons=np.asarray(lon2d),
                                lats=np.asarray(lat2d))


    proj_dict = {'proj': 'longlat', 'datum': 'WGS84'}
    area_extent = (lons_1d[0], lats_1d[0],
                   lons_1d[-1], lats_1d[-1])
    dst_area = AreaDefinition(
        'dst_grid', 'WGS84 regular', proj_dict,
        proj_dict,
        width=lons_1d.size,
        height=lats_1d.size,
        area_extent=area_extent
    )


    data_resampled = resample_nearest(
        src_swath, np.asarray(data2d),
        dst_area,
        radius_of_influence=radius_of_influence,
        fill_value=fill_value,nprocs=1

    )
    lon2d_dst, lat2d_dst = np.meshgrid(lons_1d, lats_1d)
    return data_resampled, lon2d_dst, lat2d_dst
fy4_data = np.load(r'H:\Yan\DATA\冰雹云\FY4\FY4B\AGRI\L1\FDI\DISK\4000M\2023\20230323\FY4B-_AGRI--_N_DISK_1330E_L1-_FDI-_MULT_NOM_20230323164500_20230323165959_4000M_V0001.npz')
ir = fy4_data['ir']
lat_f = fy4_data['lat']
lon_f = fy4_data['lon']
DeterministicInterpolator
target_lons = np.linspace(110,120,256)
target_lats = np.linspace(20,30,256)
for i in range(ir.shape[0]):
    d = copy.deepcopy(ir)
    grid_product, grid_x, grid_y = resample_wgs84_to_grid(
                    lat_f.astype(np.float64), lon_f.astype(np.float64), d[i].astype(np.float64),
                    lons_1d=target_lons.astype(np.float64),  # 目标经度轴
                    lats_1d=target_lats.astype(np.float64),  # 目标纬度轴
                    radius_of_influence=15000
            )
    print(np.nanmin(grid_product))

The expected result under normal operation should be

217.77999877929688
199.92999267578125
210.5399932861328
211.10000610351562
167.19000244140625
214.86000061035156
214.22999572753906
212.9199981689453
213.42999267578125

However, after repeated runs, a value of NaN may randomly appear in a certain channel, resulting in the following output:

217.77999877929688
nan
G:\py_project\radar_code\dor_2_nc\123.py:19: RuntimeWarning: All-NaN slice encountered
  print(np.nanmin(grid_product))
210.5399932861328
211.10000610351562
167.19000244140625
214.86000061035156
214.22999572753906
212.9199981689453
213.42999267578125
主要言語
Python
スター
388
フォーク
104
平均マージ
2日 16時間
マージ済み PR(30日)
3

環境構築

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

はじめの一歩

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

pytroll/pyresample のほかの issue

pytroll/pyresample の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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