From 7e8c26e03ec74521a5f21c37ac3a4f647ca2f66c Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Tue, 2 Apr 2024 14:01:43 +0200 Subject: [PATCH] ENH: Add a `is_stacked` parameters for EOReader's `Product` to document either its bands are delivered stacked or file by file. --- CHANGES.md | 1 + CI/SCRIPTS/test_satellites.py | 14 +++++++++++++- eoreader/products/custom_product.py | 4 ++++ eoreader/products/optical/planet_product.py | 3 +++ eoreader/products/optical/re_product.py | 2 +- eoreader/products/optical/s2_e84_product.py | 2 +- eoreader/products/optical/vhr_product.py | 13 ++++++++++++- eoreader/products/product.py | 3 +++ 8 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0bf68141..c2643646 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## 0.21.1 (2024-mm-dd) +- ENH: Add a `is_stacked` parameters for EOReader's `Product` to document either its bands are delivered stacked or file by file. - FIX: Correct `SWIR_CIRRUS` spectral band's enum value (to `SWIR_CIRRUS` instead of `CIRRUS`), avoiding shadowing cloud band `CIRRUS` ([#131](https://github.com/sertit/eoreader/issues/131)) - FIX: Raise proper exception (`UnhandledArchiveError`) for archived data that needs to be extracted before use. A warning wasn't enough. - FIX: Remove unused `pixel_spacing` for SAR Products diff --git a/CI/SCRIPTS/test_satellites.py b/CI/SCRIPTS/test_satellites.py index 60173565..f0705bc3 100644 --- a/CI/SCRIPTS/test_satellites.py +++ b/CI/SCRIPTS/test_satellites.py @@ -10,7 +10,7 @@ import xarray as xr from geopandas import gpd from matplotlib import pyplot as plt -from sertit import AnyPath, ci, path +from sertit import AnyPath, ci, misc, path from CI.scripts_utils import ( CI_EOREADER_S3, @@ -29,6 +29,7 @@ HH, HH_DSPK, HILLSHADE, + PAN, RED, SLOPE, SWIR_2, @@ -158,6 +159,17 @@ def check_prod(pattern_path: str) -> Product: # Instrument assert prod.instrument is not None + # Stacked product + if len(prod.get_raw_band_paths()) > 1: + raw_bands = prod.get_raw_band_paths() + # PAN is not considered here + raw_bands.pop(PAN) + ci.assert_val( + prod.is_stacked, + len(misc.unique(raw_bands.values())) == 1, + "Stacked product", + ) + return prod diff --git a/eoreader/products/custom_product.py b/eoreader/products/custom_product.py index b554f6e7..deda4781 100644 --- a/eoreader/products/custom_product.py +++ b/eoreader/products/custom_product.py @@ -102,6 +102,10 @@ def _pre_init(self, **kwargs) -> None: Function used to pre_init the products (setting needs_extraction and so on) """ + + # Custom products are stacked + self.is_stacked = True + self.needs_extraction = False # -- Parse the kwargs diff --git a/eoreader/products/optical/planet_product.py b/eoreader/products/optical/planet_product.py index caacf047..371a5d71 100644 --- a/eoreader/products/optical/planet_product.py +++ b/eoreader/products/optical/planet_product.py @@ -155,6 +155,9 @@ def _pre_init(self, **kwargs) -> None: Function used to pre_init the products (setting needs_extraction and so on) """ + # Planet products are stacked + self.is_stacked = True + # Update namespace map key (if needed) if self.constellation == Constellation.RE: self._nsmap_key = "re" diff --git a/eoreader/products/optical/re_product.py b/eoreader/products/optical/re_product.py index 062e7fdd..3d15f865 100644 --- a/eoreader/products/optical/re_product.py +++ b/eoreader/products/optical/re_product.py @@ -121,7 +121,7 @@ def _post_init(self, **kwargs) -> None: self._has_cloud_cover = True - # Pre init done by the super class + # Post init done by the super class super()._post_init(**kwargs) def _set_pixel_size(self) -> None: diff --git a/eoreader/products/optical/s2_e84_product.py b/eoreader/products/optical/s2_e84_product.py index c7b44db4..679cf536 100644 --- a/eoreader/products/optical/s2_e84_product.py +++ b/eoreader/products/optical/s2_e84_product.py @@ -118,7 +118,7 @@ def _post_init(self, **kwargs) -> None: """ self.tile_name = self._get_tile_name() - # Pre init done by the super class + # Post init done by the super class super()._post_init(**kwargs) def _get_constellation(self) -> Constellation: diff --git a/eoreader/products/optical/vhr_product.py b/eoreader/products/optical/vhr_product.py index 4c678833..78318430 100644 --- a/eoreader/products/optical/vhr_product.py +++ b/eoreader/products/optical/vhr_product.py @@ -90,6 +90,17 @@ def __init__( # Initialization from the super class super().__init__(product_path, archive_path, output_path, remove_tmp, **kwargs) + def _pre_init(self, **kwargs) -> None: + """ + Function used to pre_init the products + (setting needs_extraction and so on) + """ + # VHR products are stacked + self.is_stacked = True + + # Pre init done by the super class + super()._pre_init(**kwargs) + def _post_init(self, **kwargs) -> None: """ Function used to post_init the products @@ -98,7 +109,7 @@ def _post_init(self, **kwargs) -> None: # Job ID self._job_id = self._get_job_id() - # Pre init done by the super class + # Post init done by the super class super()._post_init(**kwargs) def get_default_band_path(self, **kwargs) -> AnyPathType: diff --git a/eoreader/products/product.py b/eoreader/products/product.py index 10f6f3af..58a7d8ea 100644 --- a/eoreader/products/product.py +++ b/eoreader/products/product.py @@ -224,6 +224,9 @@ def __init__( self.is_ortho = True """True if the images are orthorectified and the footprint is retrieved easily.""" + self.is_stacked = False + """True if the bands are stacked (like for VHR data).""" + self._stac = None # Manage output