-
Notifications
You must be signed in to change notification settings - Fork 290
Modified asc_desc2horz_vert.py to specify different dataset for each input files #1407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
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']) | ||
|
@@ -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) | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.