Skip to content

Handle Sentinel-1D ReferenceGranule in HyP3 metadata#1501

Open
teinori wants to merge 3 commits into
insarlab:mainfrom
teinori:fix-s1d-hyp3-reference-granule
Open

Handle Sentinel-1D ReferenceGranule in HyP3 metadata#1501
teinori wants to merge 3 commits into
insarlab:mainfrom
teinori:fix-s1d-hyp3-reference-granule

Conversation

@teinori

@teinori teinori commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This PR is stacked on top of #1496 and fixes one remaining Sentinel-1D HyP3 parsing issue.

The current Sentinel-1D product-name parsing handles S1DD-style HyP3 Gamma product names, but add_hyp3_metadata() can still fail when the HyP3 metadata contains a ReferenceGranule starting with S1D_IW_SLC__.

Example failure:

ValueError: Un-recognized Sentinel-1 satellite from S1D_IW_SLC__1SDV_20260610T042337_20260610T042418_003169_005832_1158

This patch adds the Sentinel-1D relative orbit equation and a corresponding test.

Summary by Sourcery

Handle Sentinel-1D HyP3 INSAR_GAMMA products and reference granules in metadata parsing.

Bug Fixes:

  • Add Sentinel-1D-specific relative orbit calculation when parsing HyP3 ReferenceGranule metadata to avoid ValueError for S1D products.

Enhancements:

  • Extend INSAR_GAMMA product-name parsing to recognize Sentinel-1D HyP3 Gamma filenames.

Tests:

  • Add unit coverage for Sentinel-1D INSAR_GAMMA product-name parsing and metadata extraction, including relative orbit and timing fields from S1D reference granules.

@welcome

welcome Bot commented Jun 30, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! Please check out our contributing guidelines. 💖
Keep in mind that all new features should be documented. It helps to write the comments next to the code or below your functions describing all arguments, and return types before writing the code. This will help you think about your code design and usually results in better code.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Extend HyP3 Sentinel-1 metadata handling to fully support Sentinel-1D INSAR_GAMMA products, including product-name parsing and relative orbit computation for reference granules, and add tests to guard the new behavior.

File-Level Changes

Change Details Files
Extend INSAR_GAMMA product-name parsing to support Sentinel-1D Gamma products
  • Broaden the INSAR_GAMMA filename regex to accept Sentinel-1D mission IDs in addition to A/B/C
  • Add a unit test ensuring a Sentinel-1CD-style INSAR_GAMMA filename is parsed into the expected product name and type
src/mintpy/prep_hyp3.py
tests/test_prep_hyp3.py
Handle Sentinel-1D ReferenceGranule metadata and compute its relative orbit
  • Implement the Sentinel-1D relative orbit equation using an absolute-orbit offset of 42 and wrap into a 175-orbit cycle
  • Wire the new equation into add_hyp3_metadata() when the reference granule starts with S1D, instead of raising an error
  • Add a regression test that builds a HyP3 metadata text file with an S1D_IW_SLC__ ReferenceGranule and verifies relative_orbit and start/stopUTC parsing
src/mintpy/prep_hyp3.py
tests/test_prep_hyp3.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 found 2 issues, and left some high level feedback:

  • In add_hyp3_metadata, the new Sentinel‑1D handling introduces a duplicate else at the same indentation level; this should be an explicit elif ref_granule.startswith('S1D'): (or similar) so the ValueError path is preserved and the code remains syntactically valid.
  • The new test test_add_hyp3_metadata_insar_gamma_s1d_reference_granule appears to be indented relative to the module level, which will either nest it inside the previous test or cause syntax/style issues; align the def with the other top‑level tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `add_hyp3_metadata`, the new Sentinel‑1D handling introduces a duplicate `else` at the same indentation level; this should be an explicit `elif ref_granule.startswith('S1D'):` (or similar) so the `ValueError` path is preserved and the code remains syntactically valid.
- The new test `test_add_hyp3_metadata_insar_gamma_s1d_reference_granule` appears to be indented relative to the module level, which will either nest it inside the previous test or cause syntax/style issues; align the `def` with the other top‑level tests.

## Individual Comments

### Comment 1
<location path="src/mintpy/prep_hyp3.py" line_range="158-160" />
<code_context>
             meta['relative_orbit'] = ((abs_orbit - 172) % 175) + 1
         else:
-            # add equation for Sentinel-D in the future
+            meta['relative_orbit'] = ((abs_orbit - 42) % 175) + 1
+        else:
             raise ValueError(f'Un-recognized Sentinel-1 satellite from {ref_granule}!')

         # first/last_frame [to be completed]
</code_context>
<issue_to_address>
**issue (bug_risk):** The control flow now has two consecutive `else` clauses, which is syntactically invalid and breaks the `if`/`elif` chain.

The new Sentinel‑1D `meta['relative_orbit']` assignment was added under an `else` that previously only had a TODO, but the original `else` with `ValueError` is still there. This creates an `elif ... else ... else` structure, which is invalid Python and also makes the S1D branch unreachable. Please restructure so S1D has its own explicit `elif` and there is only a single `else` for unknown platforms, e.g.:

```python
elif ref_granule.startswith('S1D'):
    meta['relative_orbit'] = ((abs_orbit - 42) % 175) + 1
else:
    raise ValueError(...)
```
</issue_to_address>

### Comment 2
<location path="tests/test_prep_hyp3.py" line_range="192-201" />
<code_context>
+   def test_add_hyp3_metadata_insar_gamma_s1d_reference_granule(tmp_path):
</code_context>
<issue_to_address>
**issue (testing):** The new Sentinel-1D reference granule test is incorrectly indented and will likely cause an ImportError or prevent pytest from discovering it.

This test function is indented at module scope, which risks it being nested inside a previous block and not discovered by pytest. Please unindent the `def` so it aligns with the other top-level tests.
</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.

Comment thread src/mintpy/prep_hyp3.py
Comment thread tests/test_prep_hyp3.py Outdated
Comment on lines +192 to +201
def test_add_hyp3_metadata_insar_gamma_s1d_reference_granule(tmp_path):
product_name = 'S1DD_20260610T042337_20260622T042338_VVR012_INT80_G_weF_0B7B'
(tmp_path / f'{product_name}.txt').write_text(
'\n'.join([
'UTC time: 15817.0',
'Azimuth looks: 4',
'Range looks: 20',
'Earth radius at nadir: 6337286.638938101',
'Spacecraft height: 693000.0',
'Slant range near: 846099.1914484155',

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.

issue (testing): The new Sentinel-1D reference granule test is incorrectly indented and will likely cause an ImportError or prevent pytest from discovering it.

This test function is indented at module scope, which risks it being nested inside a previous block and not discovered by pytest. Please unindent the def so it aligns with the other top-level tests.

@teinori teinori force-pushed the fix-s1d-hyp3-reference-granule branch from e2f3995 to e5972d8 Compare June 30, 2026 07:55
@teinori teinori force-pushed the fix-s1d-hyp3-reference-granule branch from e5972d8 to 9e36a95 Compare June 30, 2026 07:57
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