From 8f8b8c747f6d294d7e23d2d4474468c5bde18bb1 Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Tue, 3 Sep 2024 09:41:25 +0200 Subject: [PATCH] Fix logic errors after checking if the SAR data needs SNAP for pre-processing --- eoreader/__meta__.py | 2 +- eoreader/products/sar/capella_product.py | 33 ++++++++++----------- eoreader/products/sar/iceye_product.py | 12 ++------ eoreader/products/sar/rcm_product.py | 12 ++------ eoreader/products/sar/s1_rtc_asf_product.py | 14 ++------- eoreader/products/sar/s1_rtc_mpc_product.py | 14 ++------- eoreader/products/sar/sar_product.py | 6 ++-- 7 files changed, 31 insertions(+), 62 deletions(-) diff --git a/eoreader/__meta__.py b/eoreader/__meta__.py index f99f28bf..e81fba99 100644 --- a/eoreader/__meta__.py +++ b/eoreader/__meta__.py @@ -17,7 +17,7 @@ """ **EOReader** library """ -__version__ = "0.21.2" +__version__ = "0.21.3.dev0" __title__ = "eoreader" __description__ = ( "Remote-sensing opensource python library reading optical and SAR constellations, " diff --git a/eoreader/products/sar/capella_product.py b/eoreader/products/sar/capella_product.py index eabe8fec..534c7940 100644 --- a/eoreader/products/sar/capella_product.py +++ b/eoreader/products/sar/capella_product.py @@ -35,7 +35,7 @@ from sertit.vectors import WGS84 from shapely.geometry import Point, box -from eoreader import DATETIME_FMT, EOREADER_NAME, cache +from eoreader import DATETIME_FMT, EOREADER_NAME, cache, utils from eoreader.bands import SarBandNames as sab from eoreader.exceptions import InvalidProductError from eoreader.products import SarProduct, SarProductType @@ -197,34 +197,27 @@ def _pre_init(self, **kwargs) -> None: # Its original filename is its name self._use_filename = 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 - (setting product-type, band names and so on) - """ # Private attributes try: self.snap_filename = str(next(self.path.glob("*CAPELLA*.json")).name) except StopIteration: raise FileNotFoundError(f"Non existing file *CAPELLA*.json in {self.path}") + + # To be done in pre-init, but we don't have the product name here + name = self._get_name() try: - self._raw_band_regex = str(next(self.path.glob(f"{self.name}.tif")).name) + self._raw_band_regex = str(next(self.path.glob(f"{name}.tif")).name) except StopIteration: # For SICD and SIDD try: - self._raw_band_regex = str( - next(self.path.glob(f"{self.name}.ntf")).name - ) + self._raw_band_regex = str(next(self.path.glob(f"{name}.ntf")).name) except StopIteration: raise FileNotFoundError( - f"Non existing file {self.name}.tif or {self.name}.ntf in {self.path}" + f"Non existing file {name}.tif or {name}.ntf in {self.path}" ) - # Post init done by the super class - super()._post_init(**kwargs) + # Pre init done by the super class + super()._pre_init(**kwargs) @cache def wgs84_extent(self) -> gpd.GeoDataFrame: @@ -447,7 +440,13 @@ def get_raw_band_paths(self, **kwargs) -> dict: """ band_paths = {} try: - pol = sab.from_value(self.split_name[4]) + # To be used before post-init (name doesn't exist here) + if self.split_name is None: + split_name = utils.get_split_name(self._get_name()) + else: + split_name = self.split_name + + pol = sab.from_value(split_name[4]) band_paths[pol] = path.get_file_in_dir( self._band_folder, self._raw_band_regex, exact_name=True, get_list=False ) diff --git a/eoreader/products/sar/iceye_product.py b/eoreader/products/sar/iceye_product.py index 0a7defe9..d9368300 100644 --- a/eoreader/products/sar/iceye_product.py +++ b/eoreader/products/sar/iceye_product.py @@ -140,14 +140,6 @@ def _pre_init(self, **kwargs) -> None: # Its original filename is its name self._use_filename = 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 - (setting product-type, band names and so on) - """ # Private attributes try: if self._use_slc: @@ -161,8 +153,8 @@ def _post_init(self, **kwargs) -> None: f"Non existing file *ICEYE*SLC*.xml or *ICEYE*GRD*.xml in {self.path}" ) - # Post init done by the super class - super()._post_init(**kwargs) + # Pre init done by the super class + super()._pre_init(**kwargs) @cache def wgs84_extent(self) -> gpd.GeoDataFrame: diff --git a/eoreader/products/sar/rcm_product.py b/eoreader/products/sar/rcm_product.py index e3b76ef8..520f353a 100644 --- a/eoreader/products/sar/rcm_product.py +++ b/eoreader/products/sar/rcm_product.py @@ -168,21 +168,13 @@ def _pre_init(self, **kwargs) -> None: # Its original filename is its name self._use_filename = 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 - (setting product-type, band names and so on) - """ # Private attributes self._raw_band_regex = "*_{}.tif" self._band_folder = self.path / "imagery" self.snap_filename = "" - # Post init done by the super class - super()._post_init(**kwargs) + # Pre init done by the super class + super()._pre_init(**kwargs) @cache def wgs84_extent(self) -> gpd.GeoDataFrame: diff --git a/eoreader/products/sar/s1_rtc_asf_product.py b/eoreader/products/sar/s1_rtc_asf_product.py index ab194510..642f1fc2 100644 --- a/eoreader/products/sar/s1_rtc_asf_product.py +++ b/eoreader/products/sar/s1_rtc_asf_product.py @@ -101,6 +101,9 @@ def _pre_init(self, **kwargs) -> None: # Its original filename is its name self._use_filename = True + # Private attributes + self._raw_band_regex = "*_{}.tif" + # Pre init done by the super class super()._pre_init(**kwargs) @@ -108,17 +111,6 @@ def _get_constellation(self) -> Constellation: """Getter of the constellation: force S1.""" return Constellation.S1 - def _post_init(self, **kwargs) -> None: - """ - Function used to post_init the products - (setting product-type, band names and so on) - """ - # Private attributes - self._raw_band_regex = "*_{}.tif" - - # Post init done by the super class - super()._post_init(**kwargs) - @cache def extent(self) -> gpd.GeoDataFrame: """ diff --git a/eoreader/products/sar/s1_rtc_mpc_product.py b/eoreader/products/sar/s1_rtc_mpc_product.py index d7c9cc1b..e261b4f3 100644 --- a/eoreader/products/sar/s1_rtc_mpc_product.py +++ b/eoreader/products/sar/s1_rtc_mpc_product.py @@ -106,6 +106,9 @@ def _pre_init(self, **kwargs) -> None: # Its original filename is its name self._use_filename = True + # Private attributes + self._raw_band_regex = "*_{!l}.rtc.tiff" + # Pre init done by the super class super()._pre_init(**kwargs) @@ -113,17 +116,6 @@ def _get_constellation(self) -> Constellation: """Getter of the constellation: force S1.""" return Constellation.S1 - def _post_init(self, **kwargs) -> None: - """ - Function used to post_init the products - (setting product-type, band names and so on) - """ - # Private attributes - self._raw_band_regex = "*_{!l}.rtc.tiff" - - # Post init done by the super class - super()._post_init(**kwargs) - def get_raw_band_paths(self, **kwargs) -> dict: """ Return the existing band paths (as they come with the archived products). diff --git a/eoreader/products/sar/sar_product.py b/eoreader/products/sar/sar_product.py index f719b189..e6998cdc 100644 --- a/eoreader/products/sar/sar_product.py +++ b/eoreader/products/sar/sar_product.py @@ -272,13 +272,15 @@ def _has_snap_10_or_higher(self) -> bool: def _get_predictor(self) -> int: """ - Get LZW predictor to 1 in order SNAP < 10.0.0 to be able to read this GeoTiff (in dspk operations mostly). + Set LZW predictor to 1 in order SNAP < 10.0.0 to be able to read this GeoTiff (in despeckle operations mostly). + Else set to 3. Caused by: javax.imageio.IIOException: Illegal value for Predictor in TIFF file Leave it to None if SNAP is 10 or higher """ - return None if self._has_snap_10_or_higher() else 1 + # 3 for float if handled + return 3 if self._has_snap_10_or_higher() else 1 def _need_snap_to_pre_process(self): """This product needs SNAP for pre-process."""