diff --git a/CHANGES.md b/CHANGES.md index 39d5bc0d..72308ae3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ - FIX: Fix iceye product when extent file (*.kml) not found ([#135](https://github.com/sertit/eoreader/pull/135)) - FIX: Add missing `pystac[validation]` in setup.py - FIX: Handle RCM and RS2 products that doesn't bundle their extent in a KML file ([#155](https://github.com/sertit/eoreader/issues/155)) +- FIX: Fix error in looking for bands in Sentinel-2 L1C archived products ([#168](https://github.com/sertit/eoreader/issues/168)) - OPTIM: Search correctly nested metadata in the Reader (without accidentally using a recursive glob) - CI: Fix S3 endpoint management with `sertit>=1.37` diff --git a/eoreader/products/optical/s2_product.py b/eoreader/products/optical/s2_product.py index 44972536..1e26b79a 100644 --- a/eoreader/products/optical/s2_product.py +++ b/eoreader/products/optical/s2_product.py @@ -563,19 +563,24 @@ def _get_res_band_folder(self, band_list: list, pixel_size: float = None) -> dic dir_name = band_dir if self.is_archived: - # Open the zip file - with zipfile.ZipFile(self.path, "r") as zip_ds: - # Get the band folder (use dirname is the first of the list is a band) - band_path = [ - os.path.dirname(f.filename) - for f in zip_ds.filelist - if dir_name in f.filename - ][0] - - # Workaround for a bug involving some bad archives - if band_path.startswith("/"): - band_path = band_path[1:] - s2_bands_folder[band] = band_path + # Get the band folder (use dirname is the first of the list is a band) + band_path = os.path.dirname( + path.get_archived_rio_path( + self.path, f"{self._get_image_folder()}.*{dir_name}" + ) + ) + + # Workaround for a bug involving some bad archives + if band_path.startswith("/"): + band_path = band_path[1:] + + # Workaround for PEPS Sentinel-2 archives with incomplete manifest (without any directory) + if band_path.endswith(".jp2"): + band_path = os.path.dirname(band_path) + else: + band_path = os.path.basename(band_path) + + s2_bands_folder[band] = band_path else: # Search for the name of the folder into the S2 products try: