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

how to speed up the process of `getvar`

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

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

評価

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

調査の方向性

まず、Python、wrf.getvar、netCDF4、および記載されている SINALPHA、COSALPHA、uvmet_wspd_wdir 変数を使って、issue のタイミング比較を再現します。getvar のエントリーポイントを追跡し、ALL_TIMES と派生診断の処理を直接読み取る場合と比較します。完了の条件は、ボトルネックを特定し、結果を変更せずにより高速なアプローチを実証することです。

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

説明

I found that using wrf.getvar to get variables is quite slow.
For example

import time
import wrf
import netCDF4 as nc
wrfout = nc.Dataset(wrfout_file)
t0 = time.time()
SINALPHA_WRF = wrf.getvar(wrfout, 'SINALPHA', timeidx=wrf.ALL_TIMES, squeeze=False)
COSALPHA_WRF = wrf.getvar(wrfout, 'COSALPHA', timeidx=wrf.ALL_TIMES, squeeze=False)
t1 = time.time()
sinalpha = wrfout['SINALPHA'][:]
cosalpha = wrfout['COSALPHA'][:]
t2 = time.time()
print(f'getvar: {t1 - t0},directly: {t2 - t1}')

In my PC, the time of getvar is about 0.084 s, and the time of directly is about 0.015 s.
To be a little more complicated, to get the wind speed and the wind direction using wrf.getvar(wrfout, 'uvmet_wspd_wdir', timeidx=wrf.ALL_TIMES, squeeze=False) would take the time about 14.596 s, while we first get ua, va, SINALPHA, COSALPHA by wrf.getvarand then using the relation between these variables to get the wspd and wdir, whose values are not significant different from the result of getvar, but it only takes 2.263 s.

So, what reason make it seems that the calculation speed of getvar is slow and how to improve it?

In my case, I want to extract some variables from wrfout and backup, e.g, most of the variables may be the shape of (4,50,300,300), and I want to save some diagnostic variables to be (4, 10, 300, 300)(interpolated on certain pressure level or height). Any suggestion to efficiently accomplish this kind of task.

wrf.__version__='1.3.2'

主要言語
Python
スター
498
フォーク
178
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

NCAR/wrf-python のほかの issue

NCAR/wrf-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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