Skip to content

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

Description

@dlrhodson

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions