Polar stereo stipple() fails for data on curvilinear/2d grid
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 21
- Forks
- 11
- Avg merge
- 7h 11m
- Merged PRs (30d)
- 1
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with polar_test_2d_coord_data.py from the attached archive, then compare it with the working polar_test_1d_coord_data.py case. Read the stipple_fix.py and regrid_fix.py proposals alongside the stipple() and regrid() paths in cfplot.py; done means curvilinear-grid stippling produces a plot without breaking the 1D-coordinate case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100