Skip to content

Conversation

bjmarfito
Copy link
Contributor

@bjmarfito bjmarfito commented Aug 27, 2025

Description of proposed changes

Modified asc_desc2horz_vert.py to specify different dataset other than the same dataset for the two input files when decomposing to horizontal and vertical displacement/velocity.

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

Allow users to specify a different dataset name for each input file when converting ascending/descending measurements to horizontal and vertical components

New Features:

  • Accept multiple dataset names via the -d/--dset CLI option to map one dataset per input file
  • Use each provided dataset name when reading attributes and data for its corresponding file instead of assuming a single common dataset

Enhancements:

  • Maintain backward compatibility by falling back to the original single-dataset behavior if only one name is given

Copy link
Contributor

sourcery-ai bot commented Aug 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enable per-file dataset selection by converting the --dset/ ds_name parameter to a list, updating the CLI to accept multiple dataset names, and adjusting internal logic to read attributes and LOS data using the corresponding dataset entry for each input file.

Class diagram for updated input parameter handling in asc_desc2horz_vert.py

classDiagram
    class Inps {
        file: list[str]
        ds_name: list[str]  // now supports multiple dataset names
        geom_file: list[str]
    }
    class run_asc_desc2horz_vert {
        +run_asc_desc2horz_vert(inps: Inps)
    }
    Inps <.. run_asc_desc2horz_vert: uses
Loading

Flow diagram for per-file dataset selection in asc_desc2horz_vert.py

flowchart TD
    A[Start] --> B[Parse CLI arguments]
    B --> C{Are multiple datasets specified?}
    C -- Yes --> D[Assign each ds_name to corresponding file]
    C -- No --> E[Use single ds_name for both files]
    D --> F[Read attributes and data per file/dataset]
    E --> F
    F --> G[Continue processing]
Loading

File-Level Changes

Change Details Files
Extend CLI to accept multiple dataset names for input files
  • Change --dset parser to use nargs='+' and produce a list of dataset names
  • Update ds_name parameter type to list of strings
src/mintpy/cli/asc_desc2horz_vert.py
Update dataset handling in asc_desc2horz_vert.py to support per-file datasets
  • Use ds_name[0] for overlap attribute calculation
  • Introduce dataset_order = len(ds_name) for conditional logic
  • Branch LOS data read: iterate per file index to pick ds_name[i], fallback to original ds_name for single entry
src/mintpy/asc_desc2horz_vert.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

@bjmarfito bjmarfito requested a review from yunjunz August 27, 2025 06:41
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:

  • Simplify the dataset selection logic by directly using the loop index to pick ds_name[i] (or default to ds_name[0]) instead of the nested range and inps.file.index calls.
  • Normalize ds_name at the beginning (e.g., wrap a single string into a list matching the number of input files) and guard against it being None to avoid len(None) errors.
  • Ensure the same per-file dataset selection is applied when reading los_inc_angle and los_az_angle to keep the logic consistent across all readfile calls.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Simplify the dataset selection logic by directly using the loop index to pick ds_name[i] (or default to ds_name[0]) instead of the nested range and inps.file.index calls.
- Normalize ds_name at the beginning (e.g., wrap a single string into a list matching the number of input files) and guard against it being None to avoid len(None) errors.
- Ensure the same per-file dataset selection is applied when reading los_inc_angle and los_az_angle to keep the logic consistent across all readfile calls.

## Individual Comments

### Comment 1
<location> `src/mintpy/asc_desc2horz_vert.py:167` </location>
<code_context>

     ## 1. calculate the overlapping area in lat/lon
-    atr_list = [readfile.read_attribute(fname, datasetName=inps.ds_name) for fname in inps.file]
+    atr_list = [readfile.read_attribute(fname, datasetName=inps.ds_name[0]) for fname in inps.file]
     S, N, W, E = get_overlap_lalo(atr_list)
     lat_step = float(atr_list[0]['Y_STEP'])
</code_context>

<issue_to_address>
Hardcoding ds_name[0] may not generalize for multiple datasets.

Iterate over inps.file and inps.ds_name together to match each file with its corresponding dataset name.
</issue_to_address>

### Comment 2
<location> `src/mintpy/asc_desc2horz_vert.py:194` </location>
<code_context>

         # read data
-        dlos[i, :] = readfile.read(fname, box=box, datasetName=inps.ds_name)[0]
+        if dataset_order > 1:
+            for i in range(dataset_order):
+                if inps.file.index(fname) == i:
+                    dlos[i, :] = readfile.read(fname, box=box, datasetName=inps.ds_name[i])[0]
</code_context>

<issue_to_address>
Nested loop with index reuse may cause logic errors.

Using 'i' for both loops can cause variable shadowing and unintended behavior. Please rename the inner loop variable to prevent this issue.
</issue_to_address>

### Comment 3
<location> `src/mintpy/cli/asc_desc2horz_vert.py:60` </location>
<code_context>
                         help='Ascending and descending files\n'
                              'Both files need to be geocoded in the same spatial resolution.')
-    parser.add_argument('-d', '--dset', dest='ds_name', type=str, help='dataset to use, default: 1st dataset')
+    parser.add_argument('-d', '--dset', dest='ds_name', type=str, nargs='+', help='dataset to use, default: 1st dataset')
     parser.add_argument('-g','--geom-file', dest='geom_file', nargs=2, help='Geometry files for the input data files.')

</code_context>

<issue_to_address>
Changing ds_name to accept multiple values may require validation.

Please ensure the number of dataset names matches the number of geometry files to prevent mismatches.
</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.


## 1. calculate the overlapping area in lat/lon
atr_list = [readfile.read_attribute(fname, datasetName=inps.ds_name) for fname in inps.file]
atr_list = [readfile.read_attribute(fname, datasetName=inps.ds_name[0]) for fname in inps.file]
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Hardcoding ds_name[0] may not generalize for multiple datasets.

Iterate over inps.file and inps.ds_name together to match each file with its corresponding dataset name.

Comment on lines +194 to +195
if dataset_order > 1:
for i in range(dataset_order):
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Nested loop with index reuse may cause logic errors.

Using 'i' for both loops can cause variable shadowing and unintended behavior. Please rename the inner loop variable to prevent this issue.

help='Ascending and descending files\n'
'Both files need to be geocoded in the same spatial resolution.')
parser.add_argument('-d', '--dset', dest='ds_name', type=str, help='dataset to use, default: 1st dataset')
parser.add_argument('-d', '--dset', dest='ds_name', type=str, nargs='+', help='dataset to use, default: 1st dataset')
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Changing ds_name to accept multiple values may require validation.

Please ensure the number of dataset names matches the number of geometry files to prevent mismatches.

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