Skip to content

Add ssar#1494

Open
ehavazli wants to merge 18 commits into
insarlab:mainfrom
ehavazli:add_ssar
Open

Add ssar#1494
ehavazli wants to merge 18 commits into
insarlab:mainfrom
ehavazli:add_ssar

Conversation

@ehavazli
Copy link
Copy Markdown
Contributor

@ehavazli ehavazli commented May 27, 2026

Description of proposed changes

This PR adds SSAR support to the NISAR loading workflow while keeping the current LSAR behavior as the default.

It introduces a new band option for NISAR loading through both the CLI and the MintPy template:

  • --band in prep_nisar.py
  • mintpy.load.band in smallbaselineApp.cfg

The selected band is passed through load_data.py into prep_nisar.py, where the HDF5 dataset and metadata paths are now resolved dynamically from the NISAR product family instead of being hardcoded for LSAR.

As part of this update, the NISAR preparation logic is made band-aware across:

  • dataset lookup
  • metadata extraction
  • subset reading
  • geometry generation
  • water-mask handling
  • date-pair parsing
  • stack preparation

This allows the same workflow to ingest both LSAR and SSAR GUNW products without manual path edits or separate code paths.

Defaults remain backward compatible:

  • band=auto resolves to LSAR
  • frequency=auto continues to resolve to A

These changes keep existing LSAR processing unchanged while extending MintPy support to SSAR NISAR products.

Reminders

  • Fix #xxxx
  • 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.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

Summary by Sourcery

Add band-aware NISAR loading to support both LSAR and SSAR products while keeping LSAR as the default.

New Features:

  • Introduce a configurable NISAR SAR band option (LSAR or SSAR) exposed via the CLI and MintPy configuration.
  • Enable band-aware handling of NISAR GUNW datasets across metadata extraction, subset reading, geometry generation, date-pair parsing, and stack preparation.

Enhancements:

  • Generalize hardcoded LSAR HDF5 paths into reusable helpers that resolve dataset and metadata locations based on the selected SAR band.
  • Improve error messages for missing NISAR datasets by including the selected product family in the diagnostics.

Documentation:

  • Document the new mintpy.load.band configuration option in the default smallbaselineApp.cfg template.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 27, 2026

Reviewer's Guide

Adds a band-aware NISAR loading workflow that introduces a configurable SAR product family (LSAR/SSAR) option, threads it through CLI and MintPy config, and refactors all NISAR HDF5 path resolution and preparation utilities to derive datasets dynamically from the selected band while preserving LSAR as the default.

Flow diagram for band-aware NISAR loading pipeline

flowchart LR
    subgraph User_Input
        A1[CLI prep_nisar.py --band]
        A2[smallbaselineApp.cfg mintpy.load.band]
    end

    A1 --> B[prep_nisar.load_nisar]
    A2 --> C[load_data.prepare_metadata]

    C -->|builds args with --band| D[CLI prep_nisar.py]
    D --> B

    B --> E[_normalize_sar_band]
    E -->|sar_band| F[_science_root]
    E -->|sar_band| G[_processinfo]

    B -->|sar_band, frequency, polarization| H[_datasets_for_pol]
    B -->|sar_band| I[_get_date_pairs]
    B -->|sar_band| J[extract_metadata]
    B -->|sar_band| K[prepare_geometry]
    B -->|sar_band| L[prepare_water_mask]
    B -->|sar_band| M["prepare_stack (ifgram/ion/tropo/set)"]

    F --> H
    G --> J
    G --> I
    G --> K
    G --> L
    G --> M
Loading

File-Level Changes

Change Details Files
Introduce SAR band abstraction and dynamic HDF5 path resolution for NISAR products instead of LSAR-only hardcoded paths.
  • Define DEFAULT_SAR_BAND/VALID_SAR_BANDS and a _normalize_sar_band helper with validation and auto->LSAR behavior.
  • Replace global IDENTIFICATION/PROCESSINFO constants with helpers (_science_root, _identification_root, _radargrid_root, _processinfo) parameterized by sar_band.
  • Update helpers that build dataset paths (_dataset_root_unw, _parameters_root, _center_frequency_path, _datasets_for_pol) to take sar_band and construct /science/{sar_band}/... paths.
src/mintpy/prep_nisar.py
Make NISAR loading, masking, geometry, troposphere/SET interpolation, and stack preparation band-aware by threading sar_band through the workflow.
  • Extend frequency resolution, dataset existence checks, and error messages to include sar_band context in _resolve_frequency.
  • Add sar_band parameters (with DEFAULT_SAR_BAND default) to mask readers, target-grid readers, radar-grid readers, interpolation setup, and geometry/tropo/SET interpolation functions and use _processinfo(sar_band) and band-aware dataset maps internally.
  • Propagate sar_band through stack-related utilities (_required_paths_for_stack_type, _missing_required_paths, _read_stack_observation, prepare_stack) and through geometry/water-mask helpers (extract_metadata, get_raster_corners, common_raster_bound, read_subset, prepare_geometry, prepare_water_mask).
  • Update date-pair parsing in _get_date_pairs to use band-aware identification paths (reference/secondaryZeroDopplerStartTime from _processinfo).
src/mintpy/prep_nisar.py
Update load_nisar entry point to accept and normalize SAR band and drive a fully band-aware NISAR ingestion path.
  • Normalize inps.sar_band once via _normalize_sar_band in load_nisar and store back to the inps object for downstream use.
  • Pass sar_band into all downstream calls from load_nisar (frequency resolution, metadata extraction, mask computation, geometry preparation, water-mask generation, and stack preparation for ifgram/ion/tropo/set).
  • Adjust logging to print the selected sar_band alongside the resolved NISAR frequency.
src/mintpy/prep_nisar.py
Expose the SAR band configuration through the prep_nisar CLI and thread it from MintPy configuration into the prep_nisar invocation.
  • Add a new -ba/--band CLI option (dest='sar_band', choices auto/LSAR/SSAR, default auto) to prep_nisar’s argument parser, documenting that auto defaults to LSAR.
  • Read mintpy.load.band (default auto) from the configuration in load_data.prepare_metadata and include it in the constructed iargs when invoking prep_nisar.
  • Extend smallbaselineApp.cfg defaults with mintpy.load.band = auto and brief documentation indicating valid values and that it is NISAR-only.
src/mintpy/cli/prep_nisar.py
src/mintpy/load_data.py
src/mintpy/defaults/smallbaselineApp.cfg

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

@ehavazli ehavazli requested review from hfattahi, mirzaees and yunjunz May 27, 2026 19:47
Copy link
Copy Markdown
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 - I've left some high level feedback:

  • Consider defining a module-level constant for the default SAR band (e.g., DEFAULT_SAR_BAND = "LSAR") and using it consistently instead of repeating the literal "LSAR" in many function signatures and messages, which will reduce the risk of future mismatches.
  • Several public helpers now accept a sar_band argument and internally normalize it; you could normalize sar_band once at the top-level (e.g., in load_nisar/CLI) and pass the normalized value through to avoid repeated normalization and make error messages and logging more predictable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider defining a module-level constant for the default SAR band (e.g., `DEFAULT_SAR_BAND = "LSAR"`) and using it consistently instead of repeating the literal "LSAR" in many function signatures and messages, which will reduce the risk of future mismatches.
- Several public helpers now accept a `sar_band` argument and internally normalize it; you could normalize `sar_band` once at the top-level (e.g., in `load_nisar`/CLI) and pass the normalized value through to avoid repeated normalization and make error messages and logging more predictable.

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.

@ehavazli
Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

Copy link
Copy Markdown
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 - I've left some high level feedback:

  • Now that sar_band is threaded through most helpers, consider introducing a small context object (e.g., carrying sar_band, science_root, and processinfo) and passing that instead of the raw sar_band parameter to reduce repeated root/path computation and make future band-specific extensions easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `sar_band` is threaded through most helpers, consider introducing a small context object (e.g., carrying `sar_band`, `science_root`, and `processinfo`) and passing that instead of the raw `sar_band` parameter to reduce repeated root/path computation and make future band-specific extensions easier to maintain.

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.

@ehavazli ehavazli requested a review from EJFielding May 27, 2026 20:00
@ehavazli
Copy link
Copy Markdown
Contributor Author

@yunjunz
Codacy is flagging both D203 and D211 here, but those rules conflict. One requires a blank line before the class docstring; the other forbids it. Could we confirm which convention this repo wants and disable the other rule?

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