NCAS-CMS / NCAS-CMS/cf-plot

_map_title crashes for orthographic maps with UnboundLocalError: xpt

Open
#122 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This actually occurs for other plot types as well.

Version: cfplot 3.4.0; python 3.12

Observed behavior:

  • Orthographic contour plot crashes when cf-plot tries to render the map title
  • If the title is removed, the plot renders successfully

Expected behavior:

  • Orthographic contour plots should render with a title
  • At minimum, _map_title should not crash if a projection-specific title anchor has not been computed

Minimal failing scenario:

  • Projection: ortho
  • Default GUI-style settings:
    • [lat_0 = 0.0]
    • [lon_0 = 0.0
    • Render a contour plot with a non-empty title

Probable root cause:
_map_title() appears to compute xpt, ypt only for some projections, then unconditionally uses them in the non-dims branch.

From the installed 3.4.0 source, the title-anchor coordinates are assigned for cases such as:

  • npstere
  • spstere
  • lcc

but later the code does:

else:
    halign = "center"
    plotvars.mymap.text(
        xpt,
        ypt,
        title,
        ...
    )

For ortho, xpt/ypt do not appear to be initialized before this branch is reached.

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

Start by locating _map_title and reproduce the minimal ortho contour plot with a non-empty title using the stated default settings. Trace how xpt and ypt are assigned for each projection, then verify that orthographic plots render with titles without an UnboundLocalError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.