Handle (mask & ignore) off-domain values natively in log plots
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
cfplot/cfplot.py の calculate_levels から開始し、トレースバックに示されている失敗する np.max(field[pts]) 呼び出しの周辺を確認して、cfp.setvars(level_spacing="log") と cfp.con(f) を使って MRE を再現します。完了条件は、log および loglike プロットがゼロまたは負の値を自動的に処理し、blockfill の動作を使用し、マスキングについて説明する警告を出力することです。
索引モデルが issue の本文から書いたものです。
説明
At the moment, cf-plot supports logarithmic level plotting, i.e. when the colour scale is on a log scale to visualise the underlying data in a logarithmic fashion (not to be confused with log axes for the projected flat representation via xlog or ylog, etc.). However, when there are array values which are invalid for the domain of a log operation, namely zero or negative, they cause the plot to show an opaque error of ValueError: zero-size array to reduction operation maximum which has no identity. A log plot can still be produced by masking the invalid values out and then plotting with blockfill=True to handle the masked values (see example below), but this all needs to be done manually as prep. We should allow the log call to work as-is where the invalid domain values are masked automatically and the plot is converted to a blockfill, with a warning-level log message to indicate why this has occured.
MRE of failing naive log attempt and workaround
(From a real user support case today.)
>>> a = cf.read("liap_MMR_2006bco.nc")[0]
>>> >>> f = a[0, 0]
>>> f
<CF Field: long_name=actual contrail coverage (not area weighted)(long_name=hours since 1900-01-01 00:00 UTC at the first of the month(1), long_name=pressure_level(1), long_name=latitude(73), long_name=longitude(144)) %>
>>> f.shape
(1, 1, 73, 144)
>>> cfp.con(f) # non-log plot, works
>>>
>>> # Attempt to get a log plot via the supported approach
>>> cfp.setvars(level_spacing="log")
>>> cfp.con(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 3438, in con
clevs, mult, fmult = calculate_levels(
^^^^^^^^^^^^^^^^^
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 10183, in calculate_levels
close_below = np.max(field[pts])
^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 3164, in max
return _wrapreduction(a, np.maximum, 'max', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity
>>> cfp.setvars(level_spacing="loglike")
>>> cfp.con(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 3438, in con
clevs, mult, fmult = calculate_levels(
^^^^^^^^^^^^^^^^^
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 10183, in calculate_levels
close_below = np.max(field[pts])
^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 3164, in max
return _wrapreduction(a, np.maximum, 'max', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity
>>>
>>> # Workaround by masking values out of the valid domain then plotting with blockfill=True
>>> a_with_zeros_masked = a.where(cf.isclose(0.0), cf.masked) # mask out all zero values - note you need cf.isclose() to deal with float precision differences
>>> cfp.setvars() # reset level spacing from before
>>> cfp.con(a_with_zeros_masked[0, 0], blockfill=True) # standard, non-log plot
>>> cfp.setvars(level_spacing="log")
>>> cfp.con(a_with_zeros_masked[0, 0], blockfill=True) # logarithmic scale plot, works
- 主要言語
- Python
- スター
- 21
- フォーク
- 11
- 平均マージ
- 7時間 11分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NCAS-CMS/cf-plot のほかの issue
-
testing
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
-
Add `AGENTS.md` fileオープンdocs enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
-
Add animation hooks into cf-plot再び着手できるかも @bnlawrence が 98 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
-
bug v35plus
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
NCAS-CMS/cf-plot の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Vector35/community-plugins#376 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
py-econometrics/pyfixest#1883 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
ietf-tools/rfc2html#81 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
mysql/mysql-operator#60 ·
-
Python: Bug: split_plaintext_paragraph / split_markdown_paragraph can return a chunk larger than max_tokens対応中かも @xThreeh が今日担当しました。 オープンpython triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/semantic-kernel#14566 ·
メンテナーはふだん 4 日以内に返信