Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mintpy/asc_desc2horz_vert.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_asc_desc2horz_vert(inps):
"""

## 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.

S, N, W, E = get_overlap_lalo(atr_list)
lat_step = float(atr_list[0]['Y_STEP'])
lon_step = float(atr_list[0]['X_STEP'])
Expand All @@ -176,6 +176,7 @@ def run_asc_desc2horz_vert(inps):
## 2. read LOS data and geometry
num_file = len(inps.file)
dlos = np.zeros((num_file, length, width), dtype=np.float32)
dataset_order = len(inps.ds_name)
if inps.geom_file:
los_inc_angle = np.zeros((num_file, length, width), dtype=np.float32)
los_az_angle = np.zeros((num_file, length, width), dtype=np.float32)
Expand All @@ -190,7 +191,12 @@ def run_asc_desc2horz_vert(inps):
box = (x0, y0, x0 + width, y0 + length)

# read data
dlos[i, :] = readfile.read(fname, box=box, datasetName=inps.ds_name)[0]
if dataset_order > 1:
for i in range(dataset_order):
Comment on lines +194 to +195
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.

if inps.file.index(fname) == i:
dlos[i, :] = readfile.read(fname, box=box, datasetName=inps.ds_name[i])[0]
else:
dlos[i, :] = readfile.read(fname, box=box, datasetName=inps.ds_name)[0]
msg = f'{inps.ds_name} ' if inps.ds_name else ''
print(f'read {msg} from file: {fname}')

Expand Down
2 changes: 1 addition & 1 deletion src/mintpy/cli/asc_desc2horz_vert.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_parser(subparsers=None):
parser.add_argument('file', nargs=2,
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.

parser.add_argument('-g','--geom-file', dest='geom_file', nargs=2, help='Geometry files for the input data files.')

# inputs - checking
Expand Down