Skip to content

support --lalo-label for UTM-geocoded products in view.py - #1511

Open
huchangyang wants to merge 3 commits into
insarlab:mainfrom
huchangyang:fix/view-utm-lalo-label
Open

support --lalo-label for UTM-geocoded products in view.py#1511
huchangyang wants to merge 3 commits into
insarlab:mainfrom
huchangyang:fix/view-utm-lalo-label

Conversation

@huchangyang

@huchangyang huchangyang commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Enable view.py --lalo-label for UTM-geocoded files (e.g. NISAR GUNW).
  • Keep the image in UTM on regular matplotlib axes; only convert tick positions/labels to lat/lon (no raster reprojection).

Approach

Previously UTM + --lalo-label raised:
ValueError: --lalo-label is NOT supported for projection: UTM

Now:

  1. Skip cartopy for UTM + --lalo-label
  2. Plot with UTM easting/northing as before
  3. Use draw_utm_lalo_label() to place ticks at UTM coords of lat/lon lines and label them as 101°W / 19°N

Test plan

  • UTM file: view.py velocity.h5 velocity --lalo-label → lat/lon tick labels
  • Lat/lon geo file + --lalo-label unchanged
  • UTM file without --lalo-label unchanged

Summary by Sourcery

Support lat/lon tick labeling on UTM-geocoded maps without reprojecting raster data.

New Features:

  • Add draw_utm_lalo_label to render latitude/longitude tick labels for UTM-geocoded products on regular matplotlib axes.

Enhancements:

  • Update view.py map projection handling so --lalo-label skips Cartopy UTM projection and keeps plots in native UTM coordinates.
  • Route UTM datasets with --lalo-label through the new UTM-specific labeling helper while preserving existing behavior for lat/lon and non-lalo-label cases.

Keep the UTM image on regular axes and label ticks as lat/lon. Fix ccrs.UTM
zone parsing for --coastline-only UTM plots (zone number, not '14N').
Only change behavior for UTM + --lalo-label; keep original ccrs.UTM(utm_zone) for coastline.
@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds support for --lalo-label on UTM-geocoded products by drawing lat/lon tick labels on regular matplotlib axes without using a Cartopy UTM projection, while keeping existing behavior for lat/lon-projected data unchanged.

Flow diagram for --lalo-label handling with UTM and latlon projections

flowchart TD
    A[extent2meshgrid] --> B{inps.lalo_label}
    B -->|False| C[ax.tick_params default UTM or latlon]
    B -->|True| D{inps.coord_unit startswith meter AND UTM_ZONE in metadata}
    D -->|True| E[draw_utm_lalo_label ax metadata inps.geo_box]
    D -->|False| F[draw_lalo_label ax inps.geo_box inps.map_proj_obj]

    subgraph UTM_lalo_label_path
        E --> G[utm2latlon metadata geo_box]
        G --> H[auto_lalo_sequence lalo_box]
        H --> I[latlon2utm metadata mid_lat lons_t]
        H --> J[latlon2utm metadata lats_t mid_lon]
        I --> K[ax.set_xticks xticks]
        J --> L[ax.set_yticks yticks]
    end
Loading

File-Level Changes

Change Details Files
Introduce a helper to render lat/lon tick labels for UTM-geocoded data on regular matplotlib axes.
  • Add draw_utm_lalo_label that converts the UTM extent to a lat/lon box via utm2latlon and derives tick lat/lon sequences using auto_lalo_sequence.
  • Compute UTM x/y tick positions for each lat/lon tick using latlon2utm at the plot-center latitude/longitude.
  • Format tick labels as degrees with N/S/E/W suffixes and apply them via standard matplotlib tick APIs, respecting lalo_loc, lalo_offset, and font_size options.
src/mintpy/utils/map.py
Change projection selection logic so UTM + --lalo-label no longer uses Cartopy and instead stays on regular axes.
  • Update check_map_projection to avoid constructing a Cartopy UTM projection when lalo_label is requested, printing a message instead of raising a ValueError.
  • Keep existing Cartopy UTM behavior when lalo_label is not requested, preserving prior projection setup for non-lalo UTM plots.
src/mintpy/view.py
Wire the new UTM lat/lon labeling behavior into view.py and plot utilities.
  • Update view() to call draw_utm_lalo_label when coord_unit is meters and metadata contains UTM_ZONE, falling back to draw_lalo_label otherwise.
  • Ensure lalo-related parameters (step, loc, max_num, offset, font size, print_msg) are passed through consistently to the appropriate draw_* function.
  • Import draw_utm_lalo_label in plot utilities so it can be used alongside existing mapping helpers.
src/mintpy/view.py
src/mintpy/utils/plot.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider refactoring the lat/lon label formatting (degree + N/S/E/W, decimal digits logic) into a shared helper used by both draw_lalo_label and draw_utm_lalo_label to avoid duplication and keep labeling behavior consistent across projections.
  • In check_map_projection, when --lalo-label is used with UTM you now leave map_proj_obj unset; double-check other code paths that assume a non-None projection and guard or document this UTM + lalo-label behavior to avoid subtle regressions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider refactoring the lat/lon label formatting (degree + N/S/E/W, decimal digits logic) into a shared helper used by both `draw_lalo_label` and `draw_utm_lalo_label` to avoid duplication and keep labeling behavior consistent across projections.
- In `check_map_projection`, when `--lalo-label` is used with UTM you now leave `map_proj_obj` unset; double-check other code paths that assume a non-`None` projection and guard or document this UTM + lalo-label behavior to avoid subtle regressions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants