Skip to content

Commit

Permalink
bugfix for mintpy.network.aoiYX/LALO options (#1103)
Browse files Browse the repository at this point in the history
+ Fix the bug of `mintpy.network.aoiYX` and `mintpy.network.aoiLALO` getting ignored, which was introduced in #554.

+ Fix the ·--aoi-lalo· option checking for radar-coded files without lookup file.
  • Loading branch information
yunjunz authored Oct 9, 2023
1 parent cd1cae9 commit 4ac8ad6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/mintpy/cli/modify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def create_parser(subparsers=None):
cohBased.add_argument('--mask', dest='maskFile', default='waterMask.h5',
help='Mask file used to calculate the spatial coherence '
'(default: waterMask.h5 or None)')
cohBased.add_argument('--aoi-yx', dest='aoi_pix_box', type=int, nargs=4, metavar=('X0', 'Y0', 'X1', 'Y1'), default=None,
cohBased.add_argument('--aoi-yx', dest='aoiYX', type=int, nargs=4, metavar=('X0', 'Y0', 'X1', 'Y1'), default=None,
help='AOI in row/column range for coherence calculation (default: %(default)s).')
cohBased.add_argument('--aoi-lalo', dest='aoi_geo_box', type=float, nargs=4, metavar=('W', 'S', 'E', 'N'), default=None,
cohBased.add_argument('--aoi-lalo', dest='aoiLALO', type=float, nargs=4, metavar=('W', 'S', 'E', 'N'), default=None,
help='AOI in lat/lon range for coherence calculation (default: %(default)s).')
cohBased.add_argument('--lookup', dest='lookupFile',
help='Lookup table/mapping transformation file for geo/radar coordinate conversion.\n' +
Expand All @@ -109,7 +109,7 @@ def cmd_line_parse(iargs=None):
inps = parser.parse_args(args=iargs)

# import
from mintpy.utils import utils as ut
from mintpy.utils import readfile, utils as ut

# check: --mask option
if not os.path.isfile(inps.maskFile):
Expand Down Expand Up @@ -137,6 +137,15 @@ def cmd_line_parse(iargs=None):
if not inps.lookupFile:
inps.lookupFile = ut.get_lookup_file()

# check: --aoi-lalo option (not for radar-coded products without lookup files)
if inps.aoiLALO:
atr = readfile.read_attribute(inps.file)
if not inps.lookupFile and 'Y_FIRST' not in atr.keys():
msg = 'WARNING: Can NOT use --aoi-lalo option for files in radar coordinates '
msg += 'without lookup file. Ignore this option and continue.'
print(msg)
inps.aoiLALO = None

# default: turn --reset ON if:
# 1) no input options found to drop ifgram AND
# 2) there is template input
Expand Down Expand Up @@ -178,19 +187,13 @@ def read_template2inps(template_file, inps):
tmp = [i.strip() for i in value.split(',')]
sub_y = sorted(int(i.strip()) for i in tmp[0].split(':'))
sub_x = sorted(int(i.strip()) for i in tmp[1].split(':'))
inps.aoi_pix_box = (sub_x[0], sub_y[0], sub_x[1], sub_y[1])
inps.aoiYX = (sub_x[0], sub_y[0], sub_x[1], sub_y[1])

elif key == 'aoiLALO':
tmp = [i.strip() for i in value.split(',')]
sub_lat = sorted(float(i.strip()) for i in tmp[0].split(':'))
sub_lon = sorted(float(i.strip()) for i in tmp[1].split(':'))
inps.aoi_geo_box = (sub_lon[0], sub_lat[1], sub_lon[1], sub_lat[0])

# Check lookup file
if not inps.lookupFile:
print(f'Warning: NO lookup table file found! Can not use {key} option without it.')
print('Skip this option.')
inps.aoi_pix_box = None
inps.aoiLALO = (sub_lon[0], sub_lat[1], sub_lon[1], sub_lat[0])

elif key in ['startDate', 'endDate']:
iDict[key] = ptime.yyyymmdd(value)
Expand Down
4 changes: 2 additions & 2 deletions src/mintpy/modify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_date12_to_drop(inps):
print('use coherence-based network modification')

# get area of interest for coherence calculation
pix_box = get_aoi_pix_box(obj.metadata, inps.lookupFile, inps.aoi_pix_box, inps.aoi_geo_box)
pix_box = get_aoi_pix_box(obj.metadata, inps.lookupFile, inps.aoiYX, inps.aoiLALO)

# calculate spatial average coherence
cohList = ut.spatial_average(inps.file,
Expand Down Expand Up @@ -263,7 +263,7 @@ def get_date12_to_drop(inps):
print('use area-ratio-based network modification')

# get area of interest for coherence calculation
pix_box = get_aoi_pix_box(obj.metadata, inps.lookupFile, inps.aoi_pix_box, inps.aoi_geo_box)
pix_box = get_aoi_pix_box(obj.metadata, inps.lookupFile, inps.aoiYX, inps.aoiLALO)

# calculate average coherence in masked out areas as threshold
meanMaskCoh = np.nanmean(ut.spatial_average(inps.file,
Expand Down

0 comments on commit 4ac8ad6

Please sign in to comment.