diff --git a/encoder.py b/encoder.py index 1f000a585d598bd4d9248097c1af0df8ee5a570f..810b632c3fb5df737e647369f7ac98517fa725b9 100644 --- a/encoder.py +++ b/encoder.py @@ -618,7 +618,8 @@ class EncoderAlgorithm(IAMAPAlgorithm): ] all_tiles = [f for f in all_tiles if not f.startswith("merged")] - dst_path = Path(os.path.join(self.output_subdir, f"{current}_merged_tmp.tif")) + # dst_path = Path(os.path.join(self.output_subdir, f"{current}_merged_tmp.tif")) + dst_path = Path(os.path.join(self.output_subdir, f"merged_tmp.tif")) try: merge_tiles( @@ -631,7 +632,7 @@ class EncoderAlgorithm(IAMAPAlgorithm): # overwritting merged_tmp.tif may be impossible in windows (e.g. if an antivirus is analysing the newly created data) # then, merging and cleaning is impossible except Exception as e : - feedback.pushWarning(f"Unable to clean temporary files ! Try to delete them latter at {self.output_subdir}") + feedback.pushWarning(f"Unable to clean temporary files ! Try to delete them latter at {self.output_subdir}\n{e}") self.all_encoding_done = True diff --git a/utils/geo.py b/utils/geo.py index 21202d36ec48c39f7ab74c5cd00b91f45cf28d4d..e21aab41da02984a3e8b8887edc216cd85197cc2 100644 --- a/utils/geo.py +++ b/utils/geo.py @@ -44,9 +44,8 @@ def merge_tiles( cf. https://amanbagrecha.github.io/posts/2022-07-31-merge-rasters-the-modern-way-using-python/index.html """ - # file_handler = [rasterio.open(ds) for ds in tiles] - # extents = [ds.bounds for ds in file_handler] - extents = get_extents(tiles) + file_handler = [rasterio.open(ds) for ds in tiles] + extents = [ds.bounds for ds in file_handler] # Extract individual bounds lefts, bottoms, rights, tops = zip(*extents) union_extent = ( @@ -59,20 +58,19 @@ def merge_tiles( if method == "average": method = custom_method_avg - # memfile = MemoryFile() merge( - # sources=file_handler, # list of dataset objects opened in 'r' mode - sources=tiles, # try without rasterio.open + sources=file_handler, # list of dataset objects opened in 'r' mode bounds=union_extent, # tuple nodata=nodata, # float dtype=dtype, # dtype - # resampling=Resampling.nearest, method=method, # strategy to combine overlapping rasters - # dst_path=memfile.name, # str or PathLike to save raster dst_path=dst_path, - # dst_kwds={'blockysize':512, 'blockxsize':512} # Dictionary ) + # close datasets + for ds in file_handler: + ds.close() + def get_mean_sd_by_band(path, force_compute=True, ignore_zeros=True, subset=1_000): """