Skip to content

Commit

Permalink
Updates of regex argument to reflect sertit 1.44.1 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Dec 11, 2024
1 parent 280e14b commit 5fc7889
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 54 deletions.
2 changes: 1 addition & 1 deletion eoreader/products/optical/dimap_v2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=".*PREVIEW.*JPG"
regex=".*PREVIEW.*JPG"
)
else:
quicklook_path = next(self.path.glob("*PREVIEW*.JPG"))
Expand Down
4 changes: 1 addition & 3 deletions eoreader/products/optical/gs2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*QL\.png"
)
quicklook_path = self.path / self._get_archived_path(regex=r".*QL\.png")
else:
quicklook_path = str(next(self.path.glob("*QL.png")))
except (StopIteration, FileNotFoundError):
Expand Down
6 changes: 2 additions & 4 deletions eoreader/products/optical/hls_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def get_mean_sun_angles(self) -> (float, float):
(float, float): Mean Azimuth and Zenith angle
"""
# Retrieve angles
mtd_data, _ = self._read_mtd()
mtd_data, _ = self.read_mtd()
try:
azimuth_angle = float(mtd_data.findtext(".//MEAN_SUN_AZIMUTH_ANGLE"))
zenith_angle = float(mtd_data.findtext(".//MEAN_SUN_ZENITH_ANGLE"))
Expand Down Expand Up @@ -1030,9 +1030,7 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*.jpg"
)
quicklook_path = self.path / self._get_archived_path(regex=r".*.jpg")
else:
quicklook_path = str(next(self.path.glob("*.jpg")))
except (StopIteration, FileNotFoundError):
Expand Down
3 changes: 2 additions & 1 deletion eoreader/products/optical/landsat_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ def get_band_paths(

return band_paths

@cache
def _read_mtd(self, force_pd=False) -> (etree._Element, dict):
"""
Read Landsat metadata as:
Expand Down Expand Up @@ -1837,7 +1838,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*thumb_large\.jpeg"
regex=r".*thumb_large\.jpeg"
)
else:
quicklook_path = next(self.path.glob("*thumb_large.jpeg"))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/maxar_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*BROWSE\.JPG"
regex=r".*BROWSE\.JPG"
)
else:
quicklook_path = next(self.path.glob("*BROWSE.JPG"))
Expand Down
4 changes: 1 addition & 3 deletions eoreader/products/optical/re_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self._get_archived_rio_path(
file_regex=r".*_browse\.tif"
)
quicklook_path = self._get_archived_rio_path(regex=r".*_browse\.tif")
else:
quicklook_path = str(next(self.path.glob("**/*_browse.tif")))
except (StopIteration, FileNotFoundError):
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/s2_e84_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self._get_archived_path(file_regex=r".*.jpg")
quicklook_path = self._get_archived_path(regex=r".*.jpg")
else:
quicklook_path = str(next(self.path.glob("*.jpg")))
except (StopIteration, FileNotFoundError):
Expand Down
8 changes: 3 additions & 5 deletions eoreader/products/optical/s2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,16 +1641,14 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*ql\.jpg"
)
quicklook_path = self.path / self._get_archived_path(regex=r".*ql\.jpg")
else:
quicklook_path = next(self.path.glob("**/*ql.jpg"))
except (StopIteration, FileNotFoundError):
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*preview\.jpg"
regex=r".*preview\.jpg"
)
else:
quicklook_path = next(self.path.glob("**/preview.jpg"))
Expand All @@ -1659,7 +1657,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self._get_archived_rio_path(
file_regex=r".*PVI\.jp2"
regex=r".*PVI\.jp2"
)
else:
quicklook_path = next(self.path.glob("**/*PVI.jp2"))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/s2_theia_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*QKL_ALL\.jpg"
regex=r".*QKL_ALL\.jpg"
)
else:
quicklook_path = next(self.path.glob("**/*QKL_ALL.jpg"))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/s3_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def get_quicklook_path(self) -> str:
"""
try:
if self.is_archived:
quicklook_path = self._get_archived_path(file_regex=r".*.jpg")
quicklook_path = self._get_archived_path(regex=r".*.jpg")
else:
quicklook_path = str(next(self.path.glob("**/*.jpg")))
except (FileNotFoundError, StopIteration):
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/spot45_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*PREVIEW\.JPG"
regex=r".*PREVIEW\.JPG"
)
else:
quicklook_path = str(next(self.path.glob("*PREVIEW.JPG")))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/sv1_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*MUX\.jpg"
regex=r".*MUX\.jpg"
)
else:
quicklook_path = str(next(self.path.glob("*MUX.jpg")))
Expand Down
4 changes: 1 addition & 3 deletions eoreader/products/optical/vis1_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ def get_quicklook_path(self) -> str:
quicklook_path = None
try:
if self.is_archived:
quicklook_path = self._get_archived_rio_path(
file_regex=r".*Preview\.tif"
)
quicklook_path = self._get_archived_rio_path(regex=r".*Preview\.tif")
else:
quicklook_path = str(next(self.path.glob("*Preview.tif")))
except (StopIteration, FileNotFoundError):
Expand Down
42 changes: 23 additions & 19 deletions eoreader/products/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def _read_mtd_xml(
"""
try:
if self.is_archived:
root = self._read_archived_xml(xml_regex=f".*{mtd_archived}")
root = self._read_archived_xml(regex=f".*{mtd_archived}")
else:
try:
try:
Expand Down Expand Up @@ -2090,75 +2090,79 @@ def to_band(self, raw_bands: Union[list, BandNames, str, int]) -> list:

return bands

@cache
def _get_archived_file_list(self, archive_path=None):
"""
Overload of utils.read_archived_file to use the product's path as archive.
Return a tuple to make it hashable and therfore digestable by lru_cache.
See https://stackoverflow.com/questions/49210801/python3-pass-lists-to-function-with-functools-lru-cache
'"""

if archive_path is None:
archive_path = self.path

return utils.get_archived_file_list(archive_path)
return tuple(utils.get_archived_file_list(archive_path))

def _read_archived_file(self, regex, archive_path=None):
"""Overload of sertit.files.read_archived_file to handle the cached 'get_archived_file_list'"""
"""Overload of utils.read_archived_file to handle the cached 'get_archived_file_list'"""

if archive_path is None:
archive_path = self.path

return files.read_archived_file(
return utils.read_archived_file(
archive_path,
regex=regex,
file_list=self._get_archived_file_list(archive_path),
)

def _read_archived_xml(self, xml_regex, archive_path=None):
"""Overload of sertit.files.read_archived_xml to handle the cached 'get_archived_file_list'"""
def _read_archived_xml(self, regex, archive_path=None):
"""Overload of utils.read_archived_xml to handle the cached 'get_archived_file_list'"""

if archive_path is None:
archive_path = self.path

return files.read_archived_xml(
return utils.read_archived_xml(
archive_path,
xml_regex=xml_regex,
regex=regex,
file_list=self._get_archived_file_list(archive_path),
)

def _read_archived_html(self, regex, archive_path=None):
"""Overload of sertit.files.read_archived_html to handle the cached 'get_archived_file_list'"""
"""Overload of utils.read_archived_html to handle the cached 'get_archived_file_list'"""

if archive_path is None:
archive_path = self.path

return files.read_archived_html(
return utils.read_archived_html(
archive_path,
regex=regex,
file_list=self._get_archived_file_list(archive_path),
)

def _get_archived_path(
self, file_regex, as_list=False, case_sensitive=False, archive_path=None
self, regex, as_list=False, case_sensitive=False, archive_path=None
):
"""Overload of sertit.path.get_archived_path to handle the cached 'get_archived_file_list'"""
"""Overload of utils.get_archived_path to handle the cached 'get_archived_file_list'"""

if archive_path is None:
archive_path = self.path

return path.get_archived_path(
return utils.get_archived_path(
archive_path=archive_path,
file_regex=file_regex,
regex=regex,
as_list=as_list,
case_sensitive=case_sensitive,
file_list=self._get_archived_file_list(archive_path),
)

def _get_archived_rio_path(self, file_regex, as_list=False, archive_path=None):
"""Overload of sertit.path.get_archived_rio_path to handle the cached 'get_archived_file_list'"""
def _get_archived_rio_path(self, regex, as_list=False, archive_path=None):
"""Overload of utils.get_archived_rio_path to handle the cached 'get_archived_file_list'"""

if archive_path is None:
archive_path = self.path

return path.get_archived_rio_path(
return utils.get_archived_rio_path(
archive_path=archive_path,
file_regex=file_regex,
regex=regex,
as_list=as_list,
file_list=self._get_archived_file_list(archive_path),
)
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/sar/rs2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self._get_archived_rio_path(
file_regex=r".*BrowseImage\.tif"
regex=r".*BrowseImage\.tif"
)
else:
quicklook_path = str(next(self.path.glob("BrowseImage.tif")))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/sar/s1_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*preview.quick-look\.png"
regex=r".*preview.quick-look\.png"
)
else:
quicklook_path = next(self.path.glob("preview/quick-look.png"))
Expand Down
4 changes: 2 additions & 2 deletions eoreader/products/sar/s1_rtc_asf_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*_rgb\.png"
regex=r".*_rgb\.png"
)
else:
quicklook_path = next(self.path.glob("*_rgb.png"))
except (StopIteration, FileNotFoundError):
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*\.png"
regex=r".*\.png"
)
else:
quicklook_path = next(self.path.glob("*.png"))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/sar/s1_rtc_mpc_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def get_quicklook_path(self) -> str:
try:
if self.is_archived:
quicklook_path = self.path / self._get_archived_path(
file_regex=r".*preview\.png"
regex=r".*preview\.png"
)
else:
quicklook_path = next(self.path.glob("*preview.png"))
Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/sar/saocom_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def get_raw_band_paths(self, **kwargs) -> dict:
# Get as a list but keep only the first item (SLC with multiple swaths)
raw_paths = self._get_archived_rio_path(
archive_path=cuss_file,
file_regex=band_regex.replace("*", ".*"),
regex=band_regex.replace("*", ".*"),
as_list=True,
)

Expand Down
Loading

0 comments on commit 5fc7889

Please sign in to comment.