Polar stereo stipple() fails for data on curvilinear/2d grid

Abierto
#112 7 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
matplotlib, python

Línea de trabajo

Reproduce el fallo con polar_test_2d_coord_data.py del archivo adjunto y compáralo después con el caso funcional polar_test_1d_coord_data.py. Lee las propuestas de stipple_fix.py y regrid_fix.py junto con las rutas stipple() y regrid() de cfplot.py; se considera terminado cuando el stippling en una cuadrícula curvilínea produce un gráfico sin romper el caso de coordenadas 1D.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Hi Sadie!

Subject of the issue

Attempting to stipple() over a polar stereo contour plot from data that had 2d lon and lat grid (e.g lon(i,j)) fails.

Steps to reproduce

See attached code

Your environment

The version of cf-plot and its dependencies in which you are encountering an issue.
cf.environment(paths=False) Platform: Linux-5.14.0-503.38.1.el9_5.x86_64-x86_64-with-glibc2.34 HDF5 library: 1.14.2 netcdf library: 4.9.4-development udunits2 library: libudunits2.so.0 esmpy/ESMF: not available Python: 3.10.16 dask: 2025.3.0 netCDF4: 1.7.2 h5netcdf: 1.6.3 h5py: 3.14.0 s3fs: 2025.5.1 psutil: 7.0.0 packaging: 24.2 numpy: 2.2.4 scipy: 1.15.3 matplotlib: 3.10.3 cftime: 1.6.4.post1 cfunits: 3.3.7 cfplot: 3.4.0 cfdm: 1.12.1.0 cf: 3.17.0

Expected behaviour

A stippled plot should be produced

Actual behaviour

Tell us what happens instead. If you see an error please provide the traceback, ideally in full.

`Traceback (most recent call last):
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfplot/cfplot.py", line 9579, in add_cyclic
field, lons = cartopy_util.add_cyclic_point(field, lons)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cartopy/util.py", line 69, in add_cyclic_point
raise ValueError('The coordinate must be 1-dimensional.')
ValueError: The coordinate must be 1-dimensional.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/gws/nopw/j04/canari/users/dlrhodso/spring2025/analysis/FWC/polar_plot_example/./polar_test_2d_coord_data.py", line 10, in
cfp.stipple(f=data,min=28.0,max=40.0)
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfplot/cfplot.py", line 5073, in stipple
field, xpts = add_cyclic(field, xpts)
^^^^^^^^^^^^^^^^^^^^^^^
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cfplot/cfplot.py", line 9583, in add_cyclic
field, lons = cartopy_util.add_cyclic_point(field, lons)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/apps/jasmin/jaspy/miniforge_envs/jaspy3.11/mf3-23.11.0-0/envs/jaspy3.11-mf3-23.11.0-0-v20240815/lib/python3.11/site-packages/cartopy/util.py", line 69, in add_cyclic_point
raise ValueError('The coordinate must be 1-dimensional.')
ValueError: The coordinate must be 1-dimensional.
`

Relevant data

The attached tar file contains polar_test_2d_coord_data.py which attempts to plot a stipple over data on a curvilinear grid (and fails). polar_test_1d_coord_data.py attempts to do the same, but after regridding the data to a standard lon-lat grid (ie 1d coordinate arrays). This works.
The proposed fix is stipple_fix.py adn regrid_fix.py which only makes minor changes to stipple() - to avoid applying cyclic corrections to the longitude coordinates for a 2d longitude array, but also re-writes regrid() to allow the regridding of data on a curvilinear grid (disclosure: I asked co-pilot to write this for me!) - this seems to work!

polar_plot_stipple_examples.tar.gz

Lenguaje dominante
Python
Estrellas
21
Forks
11
Merge medio
2 h 59 min
PR fusionados (30 d)
11

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NCAS-CMS/cf-plot

Todos los issues de NCAS-CMS/cf-plot

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.