Skip to content
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

Add tropo_local_texture.py for tropo correction (Yang et al., 2024) #1291

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
78 changes: 78 additions & 0 deletions src/mintpy/cli/tropo_local_texture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
############################################################
# Program is part of MintPy #
# Copyright (c) 2013, Zhang Yunjun, Heresh Fattahi #
# Author: Yang Qingyue, Hu Changyang, 2024 #
############################################################

import argparse
import sys

from mintpy.utils.arg_utils import create_argument_parser

############################################################################
REFERENCE = """reference:
Yang, Q., Yunjun, Z., Wang, R. Y. Heterogeneous InSAR Tropospheric Correction
Based on Local Texture Correlation, IEEE Transactions on Geoscience and Remote Sensing, 62,
doi:10.1109/TGRS.2024.3356749.
"""
#TODO
EXAMPLE = """example:
tropo_local_texture.py timeseries_ramp_demErr.h5 -g inputs/geometryRadar.h5 -m maskTempCoh.h5
"""

def create_parser(subparsers=None):
#TODO
synopsis = 'Correct Topo-correlated Stratified tropospheric delay'
epilog = REFERENCE + '\n' + EXAMPLE
name = __name__.split('.')[-1]
parser = create_argument_parser(
name, synopsis=synopsis, description=synopsis, epilog=epilog, subparsers=subparsers)

parser.add_argument('timeseries_file', help='time-series file to be corrected')
parser.add_argument('-g', '--geometry', dest='geom_file', required=True,
help='DEM file used for correlation calculation.')
parser.add_argument('-m', '--mask', dest='mask_file', required=True,
help='mask file for pixels used for correlation calculation')

parser.add_argument('-w', '--windowsize', type=int, default=141,
help='window size (square window, must be odd number).')
parser.add_argument('-r', '--overlapratio', type=float, default=0.4,
help='overlap ratio for window filtering')

parser.add_argument('-o', '--outfile', help='output corrected timeseries file name')
return parser

def cmd_line_parse(iargs=None):
# parse
parser = create_parser()
inps = parser.parse_args(args=iargs)

# check: -r / --overlapration option (must be within [0,1])
if inps.overlapratio and (not 0.0 <= inps.overlapratio <= 1.0):
msg = f'overlap ratio {inps.overlapratio} is NOT within [0.0, 1.0]'
raise argparse.ArgumentTypeError(msg)

# check: -w / --windowsize option (must be odd number)
if inps.windowsize and (inps.windowsize % 2 == 0):
msg = f'window size {inps.windowsize} is NOT odd number'
raise argparse.ArgumentTypeError(msg)

return inps


############################################################################
def main(iargs=None):
# parse
inps = cmd_line_parse(iargs)

# import
from mintpy.tropo_local_texture import run_tropo_local_texture

# run
run_tropo_local_texture(inps)


############################################################################
if __name__ == '__main__':
main(sys.argv[1:])
7 changes: 6 additions & 1 deletion src/mintpy/defaults/smallbaselineApp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ mintpy.ionosphericDelay.excludeDate12 = auto #[20080520_20090817 / no], auto fo
## NARR - NARR from NOAA [need to install PyAPS from Caltech/EarthDef; recommended for N America]
## c. gacos - use GACOS with the iterative tropospheric decomposition model (Yu et al., 2018, JGR)
## need to manually download GACOS products at http://www.gacos.net for all acquisitions before running this step
mintpy.troposphericDelay.method = auto #[pyaps / height_correlation / gacos / no], auto for pyaps
## d. local_texture - use high-frequency texture to estimate the local slope to correct the tropospheric delay (Yang et al., 2024, IEEE-TGRS)
mintpy.troposphericDelay.method = auto #[pyaps / height_correlation / gacos / local_texture / no], auto for pyaps

## Notes for pyaps:
## a. GAM data latency: with the most recent SAR data, there will be GAM data missing, the correction
Expand All @@ -249,6 +250,10 @@ mintpy.troposphericDelay.minCorrelation = auto #[0.0-1.0], auto for 0
## Set the path below to directory that contains the downloaded *.ztd* files
mintpy.troposphericDelay.gacosDir = auto # [path2directory], auto for "./GACOS"

## Notes for local_texture:
## Set the path below to directory that contains the deformation velocity velocity.h5 files
mintpy.troposphericDelay.windowSize = auto #[int], auto for 141, window size, must be odd
mintpy.troposphericDelay.overlapRatio = auto #[float], auto for 0.4, overlap ratio

########## 9. deramp (optional)
## Estimate and remove a phase ramp for each acquisition based on the reliable pixels.
Expand Down
4 changes: 4 additions & 0 deletions src/mintpy/defaults/smallbaselineApp_auto.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ mintpy.troposphericDelay.minCorrelation = 0
## gacos
mintpy.troposphericDelay.gacosDir = ./GACOS

## local_texture
mintpy.troposphericDelay.windowSize = 141
mintpy.troposphericDelay.overlapRatio = 0.4


########## deramp
mintpy.deramp = no
Expand Down
18 changes: 18 additions & 0 deletions src/mintpy/smallbaselineApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def get_timeseries_filename(template, work_dir='./'):
work_dir = os.path.abspath(work_dir)
fname0 = os.path.join(work_dir, 'timeseries.h5')
fname1 = os.path.join(work_dir, 'timeseries.h5')
#fname0 = os.path.join(work_dir, 'timeseries_ramp_demErr.h5')
#fname1 = os.path.join(work_dir, 'timeseries_ramp_demErr.h5')
atr = readfile.read_attribute(fname0)

phase_correction_steps = [
Expand Down Expand Up @@ -505,6 +507,9 @@ def get_timeseries_filename(template, work_dir='./'):
elif method == 'pyaps':
fname1 = f'{os.path.splitext(fname0)[0]}_{model}.h5'

elif method == 'local_texture':
fname1 = f'{os.path.splitext(fname0)[0]}_tropolocaltexture.h5'

else:
msg = f'un-recognized tropospheric correction method: {method}'
raise ValueError(msg)
Expand Down Expand Up @@ -617,6 +622,9 @@ def run_tropospheric_delay_correction(self, step_name):
"""Correct tropospheric delays."""
geom_file = ut.check_loaded_dataset(self.workDir, print_msg=False)[1]
mask_file = os.path.join(self.workDir, 'maskTempCoh.h5')
#For test only
#geom_file = os.path.join(self.workDir, 'inputs/geometryGeo.h5')
#mask_file = os.path.join(self.workDir, 'temporalCoherence.h5')

fnames = self.get_timeseries_filename(self.template, self.workDir)[step_name]
in_file = fnames['input']
Expand Down Expand Up @@ -688,6 +696,16 @@ def get_dataset_size(fname):

else:
raise ValueError(f'un-recognized dataset name: {tropo_model}.')
# High-frequency Texture Correction (Yang et al., 2024)
elif method == 'local_texture':
window_size = self.template['mintpy.troposphericDelay.windowSize']
overlap_ratio = self.template['mintpy.troposphericDelay.overlapRatio']
iargs = [in_file, '-g', geom_file, '-m', mask_file, '-o', out_file, '-w' , window_size, '-r', overlap_ratio]
print('tropospheric delay correction with high frequency texture correlation approach')
print('\ntropo_local_texture.py', ' '.join(iargs))
if ut.run_or_skip(out_file=out_file, in_file=in_file) == 'run':
import mintpy.cli.tropo_local_texture
mintpy.cli.tropo_local_texture.main(iargs)

else:
print('No tropospheric delay correction.')
Expand Down
Loading