Precision change in regular PP-grid coordinates

Aperta
#7,344 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
data

Direzione di ricerca

Start by reading iris.util.regular_points and the change linked in the issue, then reproduce the reported call with the given zeroth, step, and count values. Compare the first coordinate with the float64 result and inspect the existing tests for regular point generation. Done means the generated coordinates retain the expected precision for this case and the relevant tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Type: Bug

🐛 Bug Report

A change in the handling of dtypes (introduced to iris as part of Numpy 2 upgrade) has resulted in some files being loaded at a lower precision.

The change in behaviour was introduced in iris.util.regular_points, which first attempts to create a regular set of points as float32, and if that is not regular, re-attempts with float64. There are cases where the zeroth and step are float64, but are cast to float32, resulting in a regular array at a lower precision.

How To Reproduce

Steps to reproduce the behaviour:

  1. Start with a UM file with the following field headers:
...
(16) lbcode  :                  101  # Indicates regular lat-lon grid, rotated pole
(17) lbhem   :                    3 
(18) lbrow   :                  190  # Number of points in y
(19) lbnpt   :                  190  # Number of points in x
...
(59) bzy     : -0.27500000000000213  # Zeroth y point
(60) bdy     :                 0.11  # Step in y
(61) bzx     :   341.30499999999995  # Zeroth x point
(62) bdx     :                 0.11  # Step in x
...
  1. In the pp load, in constructing the x coordinate, the following function will be called:
x = iris.util.regular_points(zeroth=341.30499999999995, step=0.11, count=190)
  1. The resulting array has a dtype of float32, even though the inputs were float64. Compare the first element of the array, with the result of doing the calculation with native python floats (or with explicit numpy float64):
>>> x[0]
np.float32(341.41498)
>>> 341.30499999999995 + 0.11
341.41499999999996
>>> np.add(341.30499999999995, 0.11, dtype="float64")
np.float64(341.41499999999996)

The expected start longitude is actually included in the file, as entry 4 of the real constants - and it matches the float64 calculation:

%%%%%%%%%%%%%%%%%%
* real_constants *
%%%%%%%%%%%%%%%%%%
  (1) col_spacing    :                0.11
  (2) row_spacing    :                0.11
  (3) start_lat      : -0.1650000000000027
  (4) start_lon      :  341.41499999999996
  (5) north_pole_lat :               39.25
  (6) north_pole_lon :               198.0

Environment

  • OS & Version: Red Hat Enterprise Linux release 9.8 (Plow)
  • Iris Version: 3.15, but looks to have been introduced from 3.11

Additional context

Click to expand this section... Can provide example file on request.
Lingua principale
Python
Stelle
730
Fork
323
Merge medio
3g 21h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SciTools/iris

Tutte le issue di SciTools/iris

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.