NCAS-CMS / NCAS-CMS/cf-plot

Issue with producing rotated projection with contour

Open
#66 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
21
Forks
11
Avg merge
7h 11m
Merged PRs (30d)
1

Description

As we've observed I can do a default projection (cyl) with the following code, but when introducing mapset with proj as "rotated" an error occurs. I expected a rotated projection to appear with contour plots and a title. The same issue also occurs withe the "ortho" projection/

>>> f=cf.read('cfplot_data/ggap.nc')[0]
>>> cfp.gopen()
>>> cfp.con(f.subspace(pressure=850), lines=False, title = "rotated", colorbar_position=[0.1, 0.1, 0.8, 0.02], colorbar_orientation='horizontal')
>>> cfp.gclose()
>>> cfp.gopen()
>>> cfp.mapset(proj="rotated")
>>> cfp.con(f.subspace(pressure=850), lines=False, title = "rotated", colorbar_position=[0.1, 0.1, 0.8, 0.02], colorbar_orientation='horizontal')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/natalia/anaconda3/lib/python3.12/site-packages/cfplot/cfplot.py", line 1097, in con
    map_title(title)
  File "/home/natalia/anaconda3/lib/python3.12/site-packages/cfplot/cfplot.py", line 9014, in map_title
    plotvars.mymap.text(xpt, ypt, title, va='bottom',
                        ^^^
UnboundLocalError: cannot access local variable 'xpt' where it is not associated with a value

Environment

Using the main branch:

Platform: Linux-5.4.0-131-generic-x86_64-with-glibc2.31
HDF5 library: 1.12.1
netcdf library: 4.8.1
udunits2 library: /home/natalia/anaconda3/lib/libudunits2.so.0
esmpy/ESMF: not available
Python: 3.12.2
dask: 2024.5.0
netCDF4: 1.6.2
psutil: 5.9.0
packaging: 23.2
numpy: 1.26.4
scipy: 1.13.1
matplotlib: 3.8.4
cftime: 1.6.4
cfunits: 3.3.7
cfplot: 3.3.0
cfdm: 1.11.1.0
cf: 3.16.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the rotated and ortho cases from the issue, then inspect cfplot/cfplot.py around map_title(), especially the traceback location where xpt and ypt are passed to map.text. Trace how those coordinates are selected for each projection. Done means contour plots render for both projections with the requested title and no UnboundLocalError.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.