NCAS-CMS / cf-plot

Code-light plotting for earth science and aligned research
https://ncas-cms.github.io/cf-plot/build/
MIT License
12 stars 8 forks source link

`UnboundLocalError` reachable from `con` contour call #60

Closed sadielbartholomew closed 1 month ago

sadielbartholomew commented 2 months ago

It is possible to hit an UnboundLocalError when calling con, for example from this example (though note with some environment/setup of cfp and its plotvars we run into Issue #59 first ,but I am noting it here to save time to create another minimal example that might display the bug):

>>> f = cf.read("cfplot_data/ukcp_rcm_test.nc")[0]
>>> cfp.mapset(proj="UKCP", resolution="50m")  # note Issue #59 for running this by test suite
>>> 
>>> cfp.levs(-3, 7, 0.5)
>>> cfp.setvars(grid_x_spacing=1, grid_y_spacing=1)
>>> cfp.con(f, lines=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 4100, in con
    cbar(
  File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 10056, in cbar
    ax1,
    ^^^
UnboundLocalError: cannot access local variable 'ax1' where it is not associated with a value