From 47a945af312ff83785ff66cf424a68ee920f089b Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Thu, 30 Mar 2023 14:37:18 -0800 Subject: [PATCH 01/13] add phase_filter_threshold for AVO custom deployment --- hyp3_gamma/__main__.py | 13 +++++++++++++ hyp3_gamma/insar/ifm_sentinel.py | 12 +++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index 35d11884..6572a6c1 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -112,6 +112,17 @@ def rtc(): upload_file_to_s3(product_file, args.bucket, args.bucket_prefix) +def valid_range_float(x): + try: + x = float(x) + except ValueError: + raise argparse.ArgumentTypeError("%r not a floating-point literal" % (x,)) + + if x < 0.0 or x > 1.0: + raise argparse.ArgumentTypeError("%r not in range [0.0, 1.0]"%(x,)) + return x + + def insar(): parser = ArgumentParser() parser.add_argument('--username') @@ -126,6 +137,7 @@ def insar(): parser.add_argument('--include-inc-map', type=string_is_true, default=False) parser.add_argument('--apply-water-mask', type=string_is_true, default=False) parser.add_argument('--looks', choices=['20x4', '10x2'], default='20x4') + parser.add_argument('--phase-filter-threshold', type=valid_range_float, default=0.6) parser.add_argument('granules', type=str.split, nargs='+') args = parser.parse_args() @@ -160,6 +172,7 @@ def insar(): include_wrapped_phase=args.include_wrapped_phase, include_inc_map=args.include_inc_map, apply_water_mask=args.apply_water_mask, + phase_filter_threshold=args.phase_filter_threshold ) output_zip = make_archive(base_name=product_name, format='zip', base_dir=product_name) diff --git a/hyp3_gamma/insar/ifm_sentinel.py b/hyp3_gamma/insar/ifm_sentinel.py index 6c5b3a1e..577f96b8 100755 --- a/hyp3_gamma/insar/ifm_sentinel.py +++ b/hyp3_gamma/insar/ifm_sentinel.py @@ -233,7 +233,7 @@ def move_output_files(output, reference, prod_dir, long_output, include_displace "{}_unw_phase".format(os.path.join(prod_dir, long_output)), use_nn=True) -def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, coords, ref_point_info): +def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, phase_filter_threshold, dem_source, coords, ref_point_info): res = 20 * int(alooks) reference_date = mydir[:15] @@ -316,7 +316,7 @@ def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, f.write('Range looks: %s\n' % rlooks) f.write('Azimuth looks: %s\n' % alooks) f.write('INSAR phase filter: adf\n') - f.write('Phase filter parameter: 0.6\n') + f.write('Phase filter parameter: %s\n' % phase_filter_threshold) f.write('Resolution of output (m): %s\n' % res) f.write('Range bandpass filter: no\n') f.write('Azimuth bandpass filter: no\n') @@ -336,7 +336,7 @@ def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, include_look_vectors=False, include_displacement_maps=False, include_wrapped_phase=False, include_inc_map=False, - include_dem=False, apply_water_mask=False): + include_dem=False, apply_water_mask=False, phase_filter_threshold=0.6): log.info("\n\nSentinel-1 differential interferogram creation program\n") wrk = os.getcwd() @@ -419,7 +419,7 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in log.info("Starting phase unwrapping and geocoding") coords, ref_point_info = unwrapping_geocoding(reference, secondary, step="man", rlooks=rlooks, alooks=alooks, - apply_water_mask=apply_water_mask) + alpha=phase_filter_threshold, apply_water_mask=apply_water_mask) # Generate metadata log.info("Collecting metadata and output files") @@ -476,6 +476,8 @@ def main(): parser.add_argument("-s", action="store_true", help="Create both line of sight and vertical displacement files") parser.add_argument("-w", action="store_true", help="Create wrapped phase file") parser.add_argument("-m", action="store_true", help="Apply water mask") + parser.add_argument("-t", "--phase-filter-threshold", default=0.6, help="Threshold value for adf phase filter") + args = parser.parse_args() logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', @@ -484,7 +486,7 @@ def main(): insar_sentinel_gamma(args.reference, args.secondary, rlooks=args.rlooks, alooks=args.alooks, include_look_vectors=args.l, include_displacement_maps=args.s, include_wrapped_phase=args.w, include_inc_map=args.i, - include_dem=args.d, apply_water_mask=args.m) + include_dem=args.d, apply_water_mask=args.m, phase_filter_thrshold=args.t) if __name__ == "__main__": From 42d75c896a2997ed2bc425eba1a8ac1ae38b3760 Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Fri, 31 Mar 2023 07:27:14 -0800 Subject: [PATCH 02/13] modify ifm_sentinel.py --- hyp3_gamma/insar/ifm_sentinel.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hyp3_gamma/insar/ifm_sentinel.py b/hyp3_gamma/insar/ifm_sentinel.py index 577f96b8..487aeb2a 100755 --- a/hyp3_gamma/insar/ifm_sentinel.py +++ b/hyp3_gamma/insar/ifm_sentinel.py @@ -233,7 +233,8 @@ def move_output_files(output, reference, prod_dir, long_output, include_displace "{}_unw_phase".format(os.path.join(prod_dir, long_output)), use_nn=True) -def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, phase_filter_threshold, dem_source, coords, ref_point_info): +def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, coords, + ref_point_info, phase_filter_threshold): res = 20 * int(alooks) reference_date = mydir[:15] @@ -454,7 +455,7 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in execute(f"base_init {reference}.slc.par {secondary}.slc.par - - base > baseline.log", uselogging=True) make_parameter_file(igramName, f'{product_name}/{product_name}.txt', alooks, rlooks, - dem_source, coords, ref_point_info) + dem_source, coords, ref_point_info, phase_filter_threshold) log.info("Done!!!") return product_name From 1b4bbbe95919bd055b7ec29314d68a51aa12701c Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Fri, 31 Mar 2023 10:04:52 -0800 Subject: [PATCH 03/13] modify __main__.py --- hyp3_gamma/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index 6572a6c1..c97b691b 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -4,7 +4,7 @@ import logging import os import sys -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser +from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError from importlib.metadata import entry_points from pathlib import Path from shutil import make_archive @@ -116,10 +116,10 @@ def valid_range_float(x): try: x = float(x) except ValueError: - raise argparse.ArgumentTypeError("%r not a floating-point literal" % (x,)) + raise ArgumentTypeError("%r not a floating-point literal" % (x,)) if x < 0.0 or x > 1.0: - raise argparse.ArgumentTypeError("%r not in range [0.0, 1.0]"%(x,)) + raise ArgumentTypeError("%r not in range [0.0, 1.0]" % (x,)) return x From 0e6a763e2816995b07659e2a2dd5508213c25854 Mon Sep 17 00:00:00 2001 From: cirrusasf <62269400+cirrusasf@users.noreply.github.com> Date: Fri, 31 Mar 2023 11:41:43 -0800 Subject: [PATCH 04/13] Update hyp3_gamma/__main__.py Co-authored-by: Joseph H Kennedy --- hyp3_gamma/__main__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index c97b691b..113d74d9 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -113,14 +113,12 @@ def rtc(): def valid_range_float(x): - try: - x = float(x) - except ValueError: - raise ArgumentTypeError("%r not a floating-point literal" % (x,)) - - if x < 0.0 or x > 1.0: - raise ArgumentTypeError("%r not in range [0.0, 1.0]" % (x,)) - return x + x = float(x) + if 0.0 <= x <= 1.0: + return x + raise ValueError(f'{x} not in range [0.0, 1.0]') + + def insar(): From d35ee225bb3fb574a7c82bfb13bc524119ea3209 Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Fri, 31 Mar 2023 12:15:11 -0800 Subject: [PATCH 05/13] accept modification of valid_range_float in __main__.py --- hyp3_gamma/__main__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index 113d74d9..28640596 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -119,8 +119,6 @@ def valid_range_float(x): raise ValueError(f'{x} not in range [0.0, 1.0]') - - def insar(): parser = ArgumentParser() parser.add_argument('--username') From 4f7b0d9cf06e6b805074d537fc6a121bfe3d37e0 Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Fri, 31 Mar 2023 13:10:02 -0800 Subject: [PATCH 06/13] modify the __main__.py --- hyp3_gamma/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index 28640596..07ca18e2 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -4,7 +4,7 @@ import logging import os import sys -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError +from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from importlib.metadata import entry_points from pathlib import Path from shutil import make_archive From 122371507fe7cf2fc34b4adf1734f38ca6914e12 Mon Sep 17 00:00:00 2001 From: cirrusasf <62269400+cirrusasf@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:23:32 -0800 Subject: [PATCH 07/13] Update hyp3_gamma/insar/ifm_sentinel.py Co-authored-by: Joseph H Kennedy --- hyp3_gamma/insar/ifm_sentinel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyp3_gamma/insar/ifm_sentinel.py b/hyp3_gamma/insar/ifm_sentinel.py index 487aeb2a..1c10bced 100755 --- a/hyp3_gamma/insar/ifm_sentinel.py +++ b/hyp3_gamma/insar/ifm_sentinel.py @@ -487,7 +487,7 @@ def main(): insar_sentinel_gamma(args.reference, args.secondary, rlooks=args.rlooks, alooks=args.alooks, include_look_vectors=args.l, include_displacement_maps=args.s, include_wrapped_phase=args.w, include_inc_map=args.i, - include_dem=args.d, apply_water_mask=args.m, phase_filter_thrshold=args.t) + include_dem=args.d, apply_water_mask=args.m, phase_filter_thrshold=args.phase_filter_threshold) if __name__ == "__main__": From 7fb2ec9fd503dbe04c5200f6de3d5d12d0ff70af Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Tue, 4 Apr 2023 10:54:14 -0800 Subject: [PATCH 08/13] update the CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5079f558..13dd7e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [6.0.2] + +### Added +- `phase-filter-threshold` option for the processing of INSAR products + ## [6.0.1] ### Fixed From 021c10fd40de4033d5c2b090475d1b5f820e1ef7 Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Tue, 4 Apr 2023 11:20:30 -0800 Subject: [PATCH 09/13] correct one error of spelling phase_filter_threshold --- hyp3_gamma/insar/ifm_sentinel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hyp3_gamma/insar/ifm_sentinel.py b/hyp3_gamma/insar/ifm_sentinel.py index 1c10bced..c616b06c 100755 --- a/hyp3_gamma/insar/ifm_sentinel.py +++ b/hyp3_gamma/insar/ifm_sentinel.py @@ -487,7 +487,8 @@ def main(): insar_sentinel_gamma(args.reference, args.secondary, rlooks=args.rlooks, alooks=args.alooks, include_look_vectors=args.l, include_displacement_maps=args.s, include_wrapped_phase=args.w, include_inc_map=args.i, - include_dem=args.d, apply_water_mask=args.m, phase_filter_thrshold=args.phase_filter_threshold) + include_dem=args.d, apply_water_mask=args.m, + phase_filter_threshold=args.phase_filter_threshold) if __name__ == "__main__": From d784a6f8eafc18e3b82d97d70a2eccfbf2618e60 Mon Sep 17 00:00:00 2001 From: jiangzhu Date: Tue, 4 Apr 2023 11:22:59 -0800 Subject: [PATCH 10/13] change CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13dd7e4e..b2ae46df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [6.0.2] ### Added -- `phase-filter-threshold` option for the processing of INSAR products +- `phase_filter_threshold` option for the processing of INSAR products ## [6.0.1] From dd81941ec0704767ce9867248774fe60472cf48d Mon Sep 17 00:00:00 2001 From: cirrusasf <62269400+cirrusasf@users.noreply.github.com> Date: Tue, 4 Apr 2023 12:44:12 -0800 Subject: [PATCH 11/13] Apply suggestions from code review Co-authored-by: Joseph H Kennedy --- CHANGELOG.md | 2 +- hyp3_gamma/__main__.py | 6 +++--- hyp3_gamma/insar/ifm_sentinel.py | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ae46df..8bda4b90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [6.0.2] ### Added -- `phase_filter_threshold` option for the processing of INSAR products +- A `--phase-filter-paameter` option has been added to the `__main__` (HyP3) and `ifm_sentinel.py` entry points to specify the adaptive phase filter parameter used when processing InSAR products. The provided value is ultimately passed to the `alpha` argument of the `adf` GAMMA function, which uses the algorithm with a constant exponent as described in https://doi.org/10.1029/1998GL900033. ## [6.0.1] diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index 07ca18e2..b7bc5e37 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -112,7 +112,7 @@ def rtc(): upload_file_to_s3(product_file, args.bucket, args.bucket_prefix) -def valid_range_float(x): +def phase_filter_valid_range(x: str) -> float: x = float(x) if 0.0 <= x <= 1.0: return x @@ -133,7 +133,7 @@ def insar(): parser.add_argument('--include-inc-map', type=string_is_true, default=False) parser.add_argument('--apply-water-mask', type=string_is_true, default=False) parser.add_argument('--looks', choices=['20x4', '10x2'], default='20x4') - parser.add_argument('--phase-filter-threshold', type=valid_range_float, default=0.6) + parser.add_argument('--phase-filter-parameter', type=phase_filter_valid_range, default=0.6) parser.add_argument('granules', type=str.split, nargs='+') args = parser.parse_args() @@ -168,7 +168,7 @@ def insar(): include_wrapped_phase=args.include_wrapped_phase, include_inc_map=args.include_inc_map, apply_water_mask=args.apply_water_mask, - phase_filter_threshold=args.phase_filter_threshold + phase_filter_parameter=args.phase_filter_parameter ) output_zip = make_archive(base_name=product_name, format='zip', base_dir=product_name) diff --git a/hyp3_gamma/insar/ifm_sentinel.py b/hyp3_gamma/insar/ifm_sentinel.py index c616b06c..7ac025e5 100755 --- a/hyp3_gamma/insar/ifm_sentinel.py +++ b/hyp3_gamma/insar/ifm_sentinel.py @@ -234,7 +234,7 @@ def move_output_files(output, reference, prod_dir, long_output, include_displace def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, coords, - ref_point_info, phase_filter_threshold): + ref_point_info, phase_filter_parameter): res = 20 * int(alooks) reference_date = mydir[:15] @@ -317,7 +317,7 @@ def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, f.write('Range looks: %s\n' % rlooks) f.write('Azimuth looks: %s\n' % alooks) f.write('INSAR phase filter: adf\n') - f.write('Phase filter parameter: %s\n' % phase_filter_threshold) + f.write('Phase filter parameter: %s\n' % phase_filter_parameter) f.write('Resolution of output (m): %s\n' % res) f.write('Range bandpass filter: no\n') f.write('Azimuth bandpass filter: no\n') @@ -337,7 +337,7 @@ def make_parameter_file(mydir, parameter_file_name, alooks, rlooks, dem_source, def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, include_look_vectors=False, include_displacement_maps=False, include_wrapped_phase=False, include_inc_map=False, - include_dem=False, apply_water_mask=False, phase_filter_threshold=0.6): + include_dem=False, apply_water_mask=False, phase_filter_parameter=0.6): log.info("\n\nSentinel-1 differential interferogram creation program\n") wrk = os.getcwd() @@ -420,7 +420,7 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in log.info("Starting phase unwrapping and geocoding") coords, ref_point_info = unwrapping_geocoding(reference, secondary, step="man", rlooks=rlooks, alooks=alooks, - alpha=phase_filter_threshold, apply_water_mask=apply_water_mask) + alpha=phase_filter_parameter, apply_water_mask=apply_water_mask) # Generate metadata log.info("Collecting metadata and output files") @@ -455,7 +455,7 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in execute(f"base_init {reference}.slc.par {secondary}.slc.par - - base > baseline.log", uselogging=True) make_parameter_file(igramName, f'{product_name}/{product_name}.txt', alooks, rlooks, - dem_source, coords, ref_point_info, phase_filter_threshold) + dem_source, coords, ref_point_info, phase_filter_parameter) log.info("Done!!!") return product_name @@ -477,7 +477,7 @@ def main(): parser.add_argument("-s", action="store_true", help="Create both line of sight and vertical displacement files") parser.add_argument("-w", action="store_true", help="Create wrapped phase file") parser.add_argument("-m", action="store_true", help="Apply water mask") - parser.add_argument("-t", "--phase-filter-threshold", default=0.6, help="Threshold value for adf phase filter") + parser.add_argument("-p", "--phase-filter-parameter", default=0.6, help="Adaptive phase filter parameter") args = parser.parse_args() @@ -488,7 +488,7 @@ def main(): include_look_vectors=args.l, include_displacement_maps=args.s, include_wrapped_phase=args.w, include_inc_map=args.i, include_dem=args.d, apply_water_mask=args.m, - phase_filter_threshold=args.phase_filter_threshold) + phase_filter_parameter=args.phase_filter_parameter) if __name__ == "__main__": From 823c8efd44aa0c430aa7a66c2de0eb74425c6d6e Mon Sep 17 00:00:00 2001 From: cirrusasf <62269400+cirrusasf@users.noreply.github.com> Date: Tue, 4 Apr 2023 12:45:33 -0800 Subject: [PATCH 12/13] Apply suggestions from code review Co-authored-by: Joseph H Kennedy --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bda4b90..49449f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [6.0.2] +## [6.1.0] ### Added - A `--phase-filter-paameter` option has been added to the `__main__` (HyP3) and `ifm_sentinel.py` entry points to specify the adaptive phase filter parameter used when processing InSAR products. The provided value is ultimately passed to the `alpha` argument of the `adf` GAMMA function, which uses the algorithm with a constant exponent as described in https://doi.org/10.1029/1998GL900033. From c6f785fad56ba75b18a5695fe2e2a9175995b3f3 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 5 Apr 2023 15:20:34 -0800 Subject: [PATCH 13/13] Set phase filter parameter minumum to exclusive --- hyp3_gamma/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyp3_gamma/__main__.py b/hyp3_gamma/__main__.py index b7bc5e37..0f1710fc 100644 --- a/hyp3_gamma/__main__.py +++ b/hyp3_gamma/__main__.py @@ -114,9 +114,9 @@ def rtc(): def phase_filter_valid_range(x: str) -> float: x = float(x) - if 0.0 <= x <= 1.0: + if 0.0 < x <= 1.0: return x - raise ValueError(f'{x} not in range [0.0, 1.0]') + raise ValueError(f'{x} not in range (0.0, 1.0]') def insar():