From 76a9d18f8ce318fddd317529173065a71f736c05 Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Thu, 17 Oct 2024 13:59:25 +0200 Subject: [PATCH] FIX: Fix clean band path for Sentinel-3 SLSTR products --- CHANGES.md | 1 + eoreader/products/optical/s3_slstr_product.py | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a329a546..bec5d253 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## 0.21.5.post0 (2024-10-17) - FIX: Fix (really) window's name coming from a vector with an underscore after it +- FIX: Fix clean band path for Sentinel-3 SLSTR products ## 0.21.5 (2024-10-17) diff --git a/eoreader/products/optical/s3_slstr_product.py b/eoreader/products/optical/s3_slstr_product.py index 4dbbe2a3..a41d7d53 100644 --- a/eoreader/products/optical/s3_slstr_product.py +++ b/eoreader/products/optical/s3_slstr_product.py @@ -27,11 +27,12 @@ from functools import reduce from typing import Union +import geopandas as gpd import numpy as np import xarray as xr from rasterio import features from rasterio.enums import Resampling -from sertit import path, rasters, types +from sertit import files, path, rasters, types from sertit.misc import ListEnum from sertit.types import AnyPathStrType, AnyPathType @@ -58,7 +59,13 @@ to_str, ) from eoreader.exceptions import InvalidTypeError -from eoreader.keywords import CLEAN_OPTICAL, SLSTR_RAD_ADJUST, SLSTR_STRIPE, SLSTR_VIEW +from eoreader.keywords import ( + CLEAN_OPTICAL, + SLSTR_RAD_ADJUST, + SLSTR_STRIPE, + SLSTR_VIEW, + TO_REFLECTANCE, +) from eoreader.products import S3DataType, S3Product, S3ProductType from eoreader.products.optical.optical_product import DEF_CLEAN_METHOD, CleanMethod from eoreader.stac import ASSET_ROLE, BT, CENTER_WV, DESCRIPTION, FWHM, GSD, ID, NAME @@ -1162,6 +1169,24 @@ def _get_clean_band_path( suffix = self._get_suffix(band, **kwargs) res_str = self._pixel_size_to_str(pixel_size) + # Window name + window = kwargs.get("window") + + win_suffix = "" + if window is not None: + if path.is_path(window): + win_suffix = f"{path.get_filename(window)}" + elif isinstance(window, gpd.GeoDataFrame): + win_suffix = f"{window.attrs.get('name')}" + + if not win_suffix: + win_suffix = f"win{files.hash_file_content(str(window))}" + + win_suffix += "_" + + # Radiometric processing + rad_proc = "" if kwargs.get(TO_REFLECTANCE, True) else "_as_is" + return self._get_band_folder(writable).joinpath( - f"{self.condensed_name}_{band.name}_{suffix}_{res_str.replace('.', '-')}_{cleaning_method.value}.tif", + f"{self.condensed_name}_{band.name}_{suffix}_{res_str.replace('.', '-')}_{win_suffix}{cleaning_method.value}{rad_proc}.tif", )