Skip to content

Commit

Permalink
Fix logic errors after checking if the SAR data needs SNAP for pre-pr…
Browse files Browse the repository at this point in the history
…ocessing
  • Loading branch information
remi-braun committed Sep 3, 2024
1 parent c0173cb commit 8f8b8c7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 62 deletions.
2 changes: 1 addition & 1 deletion eoreader/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
33 changes: 16 additions & 17 deletions eoreader/products/sar/capella_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
)
Expand Down
12 changes: 2 additions & 10 deletions eoreader/products/sar/iceye_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 2 additions & 10 deletions eoreader/products/sar/rcm_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 3 additions & 11 deletions eoreader/products/sar/s1_rtc_asf_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,16 @@ 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)

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:
"""
Expand Down
14 changes: 3 additions & 11 deletions eoreader/products/sar/s1_rtc_mpc_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,16 @@ 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)

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).
Expand Down
6 changes: 4 additions & 2 deletions eoreader/products/sar/sar_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 8f8b8c7

Please sign in to comment.