Skip to content

Commit

Permalink
bugfix in prep_aria.py multilook method option (insarlab#806)
Browse files Browse the repository at this point in the history
+ prep_aria: add default values for multilooking options (x/ystep, method) when no template file is given

+ prep_fringe: use ptime.yyyymmdd_date12() for more robust info extraction

+ utils0.py: add print_command_line() to add "" for arguments containing *, for improved usability.

+ load_data.prepare_metadata(): use ut.print_command_line() to facilitate debugging.

Co-authored-by: Zhang Yunjun <[email protected]>
  • Loading branch information
bbuzz31 and yunjunz committed Jul 6, 2022
1 parent 6e741da commit ee43222
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
8 changes: 4 additions & 4 deletions mintpy/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def prepare_metadata(iDict):
iargs += ['--sensor', iDict['PLATFORM'].lower()]
elif processor == 'cosicorr':
iargs += ['--metadata', iDict['mintpy.load.metaFile']]
print(script_name, ' '.join(iargs))
ut.print_command_line(script_name, iargs)
# run
prep_module.main(iargs)

Expand Down Expand Up @@ -775,7 +775,7 @@ def prepare_metadata(iDict):
iargs += ['--geom-files'] + geom_files

# run module
print('prep_isce.py', ' '.join(iargs))
ut.print_command_line(script_name, iargs)
try:
prep_isce.main(iargs)
except:
Expand Down Expand Up @@ -832,7 +832,7 @@ def prepare_metadata(iDict):
iargs += ['--update']

## run
print('prep_aria.py', ' '.join(iargs))
ut.print_command_line(script_name, iargs)
try:
prep_aria.main(iargs)
except:
Expand All @@ -849,7 +849,7 @@ def prepare_metadata(iDict):

# run prep_*.py
iargs = [custom_temp_files[0]]
print('prep_gmtsar.py', ' '.join(iargs))
ut.print_command_line(script_name, iargs)
try:
prep_gmtsar.main(iargs)
except:
Expand Down
18 changes: 9 additions & 9 deletions mintpy/prep_aria.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,17 @@ def cmd_line_parse(iargs = None):
parser = create_parser()
inps = parser.parse_args(args=iargs)

# default x/ystep
# default multilook options
iDict = vars(inps)
iDict['xstep'] = iDict.get('xstep', 1)
iDict['ystep'] = iDict.get('ystep', 1)
iDict['xstep'] = int(iDict.get('xstep', 1))
iDict['ystep'] = int(iDict.get('ystep', 1))
iDict['method'] = str(iDict.get('method', 'nearest'))

# --template
if inps.template_file:
inps = read_template2inps(inps.template_file, inps)
print('x/ystep: {}/{}'.format(iDict['xstep'], iDict['ystep']))
print('multilook x/ystep: {}/{}'.format(iDict['xstep'], iDict['ystep']))
print('multilook method : {}'.format(iDict['method']))

# --stack-dir
if inps.stackDir is not None:
Expand Down Expand Up @@ -209,13 +211,11 @@ def read_template2inps(template_file, inps=None):
key_list = [i.split(prefix)[1] for i in template.keys() if i.startswith(prefix)]
for key in key_list:
value = template[prefix+key]
if key in ['xstep', 'ystep', 'method']:
if key in ['xstep', 'ystep']:
iDict[key] = int(template[prefix+key])
elif key in ['method']:
iDict[key] = template[prefix+key]

iDict['xstep'] = int(iDict.get('xstep', 1))
iDict['ystep'] = int(iDict.get('ystep', 1))
iDict['method'] = str(iDict.get('method', 'nearest'))

return inps


Expand Down
2 changes: 1 addition & 1 deletion mintpy/prep_fringe.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def prepare_stack(outfile, unw_file, metadata, processor, baseline_dir=None, box
return

# get date info: date12_list
date12_list = [os.path.basename(x).split('.')[0] for x in unw_files]
date12_list = ptime.yyyymmdd_date12([os.path.basename(x).split('.')[0] for x in unw_files])

# prepare baseline info
if baseline_dir is not None:
Expand Down
28 changes: 22 additions & 6 deletions mintpy/utils/utils0.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def incidence_angle(atr, dem=None, dimension=2, print_msg=True):
# consider the local variable due to topography
if dem is not None:
range_dist = range_distance(atr, dimension=2, print_msg=False)
inc_angle = (np.pi - np.arccos(((r+dem)**2 + range_dist**2 - (r+H)**2) /
inc_angle = (np.pi - np.arccos(((r+dem)**2 + range_dist**2 - (r+H)**2) /
(2*(r+dem)*range_dist))) * 180.0/np.pi
else:
inc_angle = np.tile(np.linspace(inc_angle_n, inc_angle_f, num=width,
Expand Down Expand Up @@ -207,8 +207,8 @@ def azimuth_ground_resolution(atr):
def auto_lat_lon_step_size(atr, lat_c=None):
"""Get the default lat/lon step size for geocoding.
Treat the pixel in radar coordinates as an rotated rectangle. Use the bounding box
of the rotated rectangle for the ratio between lat and lon steps. Then scale the
Treat the pixel in radar coordinates as an rotated rectangle. Use the bounding box
of the rotated rectangle for the ratio between lat and lon steps. Then scale the
lat and lon step size to ensure the same area between the pixels in radar and geo
coordinates.
Expand Down Expand Up @@ -726,7 +726,7 @@ def yes_or_no(question):
else:
return yes_or_no("Uhhhh... please enter ")


def update_attribute_or_not(atr_new, atr_orig):
"""Compare new attributes with exsiting ones"""
update = False
Expand Down Expand Up @@ -797,6 +797,24 @@ def check_parallel(file_num=1, print_msg=True, maxParallelNum=8):
return num_cores, enable_parallel, None, None


def print_command_line(script_name, args):
"""print the command line with "" for arguments containing *.
Parameters: script_name - str, e.g. prep_isce.py
args - list(str), list of input arguments
"""
cmd = script_name
for arg in args:
# for option values containing *, add "" in the print out msg
# so that it can be copied and pasted to run directly.
if not arg.startswith('-') and '*' in arg:
cmd += f' "{arg}"'
else:
cmd += f' {arg}'

print(cmd)
return


#################################### Math / Statistics ###################################
def median_abs_deviation(data, center=None, scale=0.67449):
Expand Down Expand Up @@ -926,5 +944,3 @@ def is_number(string):
return True
except ValueError:
return False


0 comments on commit ee43222

Please sign in to comment.