Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@yunjunz
Copy link
Member

@yunjunz yunjunz commented Nov 22, 2025

Description of proposed changes

  • support --shp-file related options in tsview.py as well

  • add is_native_reference_point() for easier re-use and allow for the potential geo2radar coordinate conversion error, which is usually less than or about 1 pixel.

Reminders

  • Pass Pre-commit check (green)
  • Pass Codacy code review (green)
  • Pass Circle CI test (green)
  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • If modifying functionality, describe changes to function behavior and arguments in a comment below the function declaration.

Summary by Sourcery

Extend tsview functionality to better handle reference points and to support shape-file plotting options via the CLI.

New Features:

  • Allow tsview to accept and use shape-file related command-line options for plotting shapes.
  • Introduce a reusable helper to detect native reference points with tolerance for small geo-to-radar coordinate conversion errors.

Enhancements:

  • Refine handling of native reference points in tsview by centralizing the logic and adding a warning when they fall outside the subset.
  • Clarify CLI help for shape-file options by specifying metavariables for file and color arguments.

+ support --shp-file related options in tsview.py as well

+ add `is_native_reference_point()` for easier re-use and allow for the potential geo2radar coordinate conversion error, which is usually less than or about 1 pixel.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 22, 2025

Reviewer's Guide

Adds shapefile plotting support to tsview, refactors reference-point handling into a reusable helper that tolerates small geo2radar errors, and slightly improves CLI/help text and logging around reference point display.

Sequence diagram for tsview reference point handling with geo2radar tolerance

sequenceDiagram
    actor User as "User"
    participant CLI as "tsview CLI entrypoint"
    participant Parser as "Argument parser"
    participant Core as "mintpy.tsview"
    participant Init as "read_init_info()"
    participant Timeseries as "read_timeseries_data()"
    participant Helper as "is_native_reference_point()"

    User->>CLI: "Run tsview with optional ref_yx and subset"
    CLI->>Parser: "Parse CLI arguments (including ref_yx, pix_box, multilook_num)"
    Parser-->>CLI: "Return populated inps object"

    CLI->>Init: "read_init_info(inps)"
    Init->>Helper: "is_native_reference_point(inps.ref_yx, atr)"
    Helper-->>Init: "True if ref_yx within tolerance of native REF_Y/X"
    Init->>Init: "Check subset box against ref_yx when native and within coverage"
    Init->>Init: "If native ref_yx outside subset, set inps.disp_ref_pixel = False and log warning"
    Init-->>CLI: "Updated inps with display-ref flags"

    CLI->>Timeseries: "read_timeseries_data(inps)"
    Timeseries->>Helper: "is_native_reference_point(inps.ref_yx, atr)"
    Helper-->>Timeseries: "False if ref_yx not within tolerance of native REF_Y/X"
    Timeseries->>Timeseries: "If non-native ref_yx, subset_and_multilook_yx(...) and re-reference data"
    Timeseries-->>CLI: "Timeseries data referenced according to ref_yx behavior"
Loading

Updated class diagram for tsview reference point and CLI shape argument utilities

classDiagram
    class MintpyTsviewCore {
        +read_init_info(inps)
        +read_timeseries_data(inps)
        +subset_and_multilook_yx(yx, pix_box=None, multilook_num=1)
        +is_native_reference_point(ref_yx, atr, max_err=2)
    }

    class ArgUtils {
        +add_shape_argument(parser)
        +add_save_argument(parser)
        +add_subset_argument(parser)
        +add_reference_argument(parser)
        +add_map_argument(parser)
        +add_memory_argument(parser)
    }

    class TsviewCLI {
        +create_parser(subparsers=None)
    }

    TsviewCLI ..> ArgUtils : "uses add_shape_argument() to add --shp-* options"
    TsviewCLI ..> ArgUtils : "uses other add_*_argument() utilities"

    MintpyTsviewCore ..> MintpyTsviewCore : "read_init_info() and read_timeseries_data() call is_native_reference_point()"
Loading

File-Level Changes

Change Details Files
Refactor native reference point detection to a reusable helper that tolerates small geo2radar conversion errors and update its usage.
  • Introduce is_native_reference_point(ref_yx, atr, max_err=2) to detect native REF_Y/X with a configurable pixel tolerance.
  • Use is_native_reference_point in read_init_info to decide whether to display the native reference pixel after subsetting, and change the log message to a clearer warning.
  • Use is_native_reference_point in read_timeseries_data to decide when to re-reference data to a user-specified pixel, instead of directly comparing to REF_Y/X.
src/mintpy/tsview.py
Extend tsview CLI to support shapefile overlay options consistent with other tools.
  • Expose the generic shape plotting arguments to tsview by adding arg_utils.add_shape_argument(parser) to the tsview CLI parser.
  • Improve argument help/UX for shape plotting options by specifying metavar for --shp-file and --shp-color in the shared argument builder.
src/mintpy/cli/tsview.py
src/mintpy/utils/arg_utils.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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In is_native_reference_point(), you only guard against missing 'REF_Y' but access 'REF_X' unconditionally, which can raise a KeyError for datasets without REF_X; consider checking for 'REF_X' as well or using atr.get with a sensible default.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In is_native_reference_point(), you only guard against missing 'REF_Y' but access 'REF_X' unconditionally, which can raise a KeyError for datasets without REF_X; consider checking for 'REF_X' as well or using atr.get with a sensible default.

## Individual Comments

### Comment 1
<location> `src/mintpy/tsview.py:271-274` </location>
<code_context>
+                max_err - int, maximum allowable error to account for
+                          potential geo2radar coordinate conversion error
+    """
+    if 'REF_Y' not in atr.keys():
+        return False
+
+    ref_x = int(atr['REF_X'])
+    ref_y = int(atr['REF_Y'])
+    x0, x1 = ref_x - max_err, ref_x + max_err
</code_context>

<issue_to_address>
**issue:** Guard against missing REF_X key as well as REF_Y when checking native reference point.

This only checks for 'REF_Y' but then indexes atr['REF_X'], which will raise a KeyError if 'REF_X' is missing or misnamed. Please either check for both keys before use (e.g., `if 'REF_X' not in atr or 'REF_Y' not in atr: return False`) or use `atr.get` with a defined fallback to avoid crashes when metadata is incomplete or varies between datasets.
</issue_to_address>

### Comment 2
<location> `src/mintpy/tsview.py:279-282` </location>
<code_context>
def is_native_reference_point(ref_yx, atr, max_err=2):
    """Check if the given ref_yx is the native reference point or not.

    Parameters: ref_yx  - list of int, input reference point in row/col
                atr     - dict, attributes, to retrieve the native REF_Y/X
                max_err - int, maximum allowable error to account for
                          potential geo2radar coordinate conversion error
    """
    if 'REF_Y' not in atr.keys():
        return False

    ref_x = int(atr['REF_X'])
    ref_y = int(atr['REF_Y'])
    x0, x1 = ref_x - max_err, ref_x + max_err
    y0, y1 = ref_y - max_err, ref_y + max_err

    if (x0 <= ref_yx[1] < x1 and y0 <= ref_yx[0] < y1):
        return True
    else:
        return False

</code_context>

<issue_to_address>
**suggestion (code-quality):** We've found these issues:

- Replace if statement with if expression ([`assign-if-exp`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/assign-if-exp/))
- Simplify boolean if expression ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- Remove unnecessary casts to int, str, float or bool ([`remove-unnecessary-cast`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/remove-unnecessary-cast/))

```suggestion
    return x0 <= ref_yx[1] < x1 and y0 <= ref_yx[0] < y1
```
</issue_to_address>

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.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@yunjunz yunjunz merged commit 2c24dc2 into insarlab:main Nov 22, 2025
8 checks passed
@yunjunz yunjunz deleted the tsview_shp branch November 22, 2025 06:27
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.

1 participant