From b15ff07c3e4f9a244b21be905d4b0e89cf5f5e82 Mon Sep 17 00:00:00 2001 From: Remi Cresson <remi.cresson@irstea.fr> Date: Thu, 2 Jun 2022 13:12:33 +0200 Subject: [PATCH] FIX, REFAC: use f-string and os.path.join() for paths concat --- decloud/analysis/crga_al_analysis.py | 5 +++-- decloud/analysis/orbits_analysis.py | 3 ++- decloud/analysis/patches_coverage.py | 5 +++-- decloud/analysis/tile_coverage.py | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/decloud/analysis/crga_al_analysis.py b/decloud/analysis/crga_al_analysis.py index 011e6e1..f32827d 100644 --- a/decloud/analysis/crga_al_analysis.py +++ b/decloud/analysis/crga_al_analysis.py @@ -26,6 +26,7 @@ This scripts summarizes the number of samples that we can get from an Acquisitio suited for single optical image reconstruction from date SAR/optical pair, for different parameters of the AcquisitionsLayout """ +import os import argparse import logging from decloud.acquisitions.sensing_layout import AcquisitionsLayout, S1Acquisition, S2Acquisition @@ -139,8 +140,8 @@ for max_s1s2_gap_hours in params.maxgaps1s2_list: np_counts[pos[0], pos[1]] += nb_samples_in_patch # Export - out_fn = "count_gap{}_range{}-{}_{}.tif".format(max_s1s2_gap_hours, int_radius, ext_radius, tile_name) - out_fn = system.pathify(params.out_dir) + out_fn + out_fn = f"count_gap{max_s1s2_gap_hours}_range{int_radius}-{ext_radius}_{tile_name}.tif" + out_fn = os.path.join(params.out_dir, out_fn) logging.info("Saving %s", out_fn) raster.save_numpy_array_as_raster(ref_fn=ref_fn, np_arr=np_counts, out_fn=out_fn, scale=scale) diff --git a/decloud/analysis/orbits_analysis.py b/decloud/analysis/orbits_analysis.py index bc3bf05..8223e57 100644 --- a/decloud/analysis/orbits_analysis.py +++ b/decloud/analysis/orbits_analysis.py @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. """ Analyze the S1 and S2 orbits """ +import os import argparse import numpy as np import logging @@ -80,5 +81,5 @@ for tile_name, tile_handler in th.items(): # Export with pyotb out = np.add(initialized_raster, histo_array) # this is a pyotb object - out_fn = system.pathify(params.out_dir) + "{}_s1s2gap_hist.tif".format(tile_name) + out_fn = os.path.join(params.out_dir, f"{tile_name}_s1s2gap_hist.tif") out.write(out_fn) diff --git a/decloud/analysis/patches_coverage.py b/decloud/analysis/patches_coverage.py index fe8b423..c81347c 100644 --- a/decloud/analysis/patches_coverage.py +++ b/decloud/analysis/patches_coverage.py @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. """ Compute the number of S1 and S2 images used for each patch. """ +import os import argparse import logging import numpy as np @@ -59,7 +60,7 @@ scale = float(params.patch_size) / float(constants.PATCHSIZE_REF) for al_bname, al in als: for tile_name, tile_handler in th.items(): # Output files prefix - out_prefix = system.pathify(params.out_dir) + tile_name + "_" + al_bname + out_prefix = os.join(params.out_dir, tile_name + "_" + al_bname) # Reference raster grid ref_fn = tile_handler.s2_images[0].clouds_stats_fn @@ -94,6 +95,6 @@ for al_bname, al in als: # Export for key in ["s1", "s2"]: - out_fn = "{}_{}_freq.tif".format(out_prefix, key) + out_fn = f"{out_prefix}_{key}_freq.tif" logging.info("Saving %s", out_fn) raster.save_numpy_array_as_raster(ref_fn=ref_fn, np_arr=np_counts[key], out_fn=out_fn, scale=scale) diff --git a/decloud/analysis/tile_coverage.py b/decloud/analysis/tile_coverage.py index 2e81d0c..d362185 100644 --- a/decloud/analysis/tile_coverage.py +++ b/decloud/analysis/tile_coverage.py @@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE. """ Compute cloud coverage and pixel validity from an input set of tiles """ +import os import argparse import logging import numpy as np @@ -46,7 +47,7 @@ def compute_stats(tile_name, tile_handler): :param tile_handler: Tile handler instance """ ref_fn = tile_handler.s2_images[0].clouds_stats_fn - out_prefix = system.pathify(params.out_dir) + tile_name + out_prefix = os.path.join(params.out_dir, tile_name) # Statistics cloud_cov = np.sum(np.multiply(tile_handler.s2_images_validity, tile_handler.s2_images_cloud_coverage), axis=0) -- GitLab