From f52207cb99b986c63793fa8e4118597bcd324c23 Mon Sep 17 00:00:00 2001 From: "raffaele.gaetano" <raffaele.gaetano@cirad.fr> Date: Wed, 28 Jun 2023 15:50:18 +0200 Subject: [PATCH] ENH: updated cli tool for preprocessing of Sentinel-2. --- moringa.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/moringa.py b/moringa.py index 840250f..9b66d04 100755 --- a/moringa.py +++ b/moringa.py @@ -29,8 +29,9 @@ def preprocess_spot67(in_fld, out_fld, dem_fld, geoid_file, skip_ps, compress, sp.write_outputs(out_fld, compress=compress) return -def preprocess_s2(in_fld, out_fld, output_dates_file=None, roi=None, coregister_to=None, coregister_to_band=1, - coregister_using_band=3, provider='theia'): +def preprocess_s2(in_fld, out_fld, output_dates_file=None, roi=None, + align=False, align_to=None, align_to_band=3, align_using_band=3, + provider='theia'): S2Processor = None if provider == 'theia': S2Processor = s2theia.S2TheiaPipeline @@ -47,7 +48,9 @@ def preprocess_s2(in_fld, out_fld, output_dates_file=None, roi=None, coregister_ else: raise ValueError("Please provide path to a text file containing output dates.") - s2.extract_feature_set(out_fld, store_gapfill=True, mosaicking='vrt') + align_flag = align is not None + s2.extract_feature_set(out_fld, store_gapfill=True, mosaicking='vrt', align=align_flag, align_to=align_to, + align_to_band=align_to_band, align_using_band=align_using_band, output_aligned=align) return def main(args): @@ -60,9 +63,10 @@ def main(args): prepr.add_argument("out_folder", type=str, help="Path to the folder in which preprocessed stacks will be stored.") prepr.add_argument("--output_dates_file", type=str, default=None, help="Path to the text file containing output dates for temporal interpolation.") prepr.add_argument("--roi", type=str, default=None, help="Path to the ROI vector file.") - prepr.add_argument("--coregister_to", type=str, default=None, help="Path to a reference image to which the stacks must be coregistered.") - prepr.add_argument("--coregister_to_band", type=int, default=1, help="Band of reference image used for co-registration.") - prepr.add_argument("--coregister_using_band", type=int, default=3, help="Band of current stack used for co-registration.") + prepr.add_argument("--align", type=str, default=None, help="To perform within-series image alignment, set this as output path for the aligned series.") + prepr.add_argument("--align_to", type=str, default=None, help="Path to a (optional)) reference image to which the stacks must be aligned.") + prepr.add_argument("--align_to_band", type=int, default=1, help="Band of reference image used for alignment.") + prepr.add_argument("--align_using_band", type=int, default=3, help="Band of current stack used for alignment.") prepr.add_argument("--provider", type=str, default='theia', help="S2 image provider. Supported: 'theia', 'theial3a', 'sen2cor', 'planetary'") segmt = subpar.add_parser("segment", help="Performs (large scale Baatz-Shape) segmentation of an input image.", @@ -93,8 +97,6 @@ def main(args): vhrprep.add_argument("--skip_ps", help="Skip pansharpening step.", action='store_true') vhrprep.add_argument("--compress", help="Use lossless compression on outputs.", action='store_true') - - if len(args) == 1: parser.print_help() sys.exit(0) @@ -103,7 +105,8 @@ def main(args): if arg.cmd == "preprocess_s2": preprocess_s2(arg.in_folder, arg.out_folder, output_dates_file=arg.output_dates_file, roi=arg.roi, - coregister_to=arg.coregister_to, provider=arg.provider) + align=arg.align, align_to=arg.align_to, align_to_band=arg.align_to_band, + align_using_band=arg.align_using_band, provider=arg.provider) if arg.cmd == "segment": run_segmentation(arg.img, arg.threshold, arg.cw, arg.sw, arg.outimg, arg.n_first_iter, arg.tile_margin, -- GitLab