Skip to content

Commit

Permalink
FIX: Don't throw an error in case of missing cloud coverage, only a w…
Browse files Browse the repository at this point in the history
…arning and set the cloud coverage to 0 #159
  • Loading branch information
remi-braun committed Dec 3, 2024
1 parent 5ab6742 commit 8020c5b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- FIX: Remove useless `_norm_diff` function `indices.py`
- FIX: Add a fallback in case `map-overlay.kml` is not readable for `Sentinel-1` data ([#180](https://github.com/sertit/eoreader/discussions/180),[#182](https://github.com/sertit/eoreader/issues/182))
- FIX: Remove warning about Dask's lock and client
- FIX: Don't throw an error in case of missing cloud coverage, only a warning and set the cloud coverage to 0 [#159](https://github.com/sertit/eoreader/issues/159)
- DOC: Update `conf.py` (remove useless hunks and set Sphinx 7 as base)
- DOC: Added the [PAZ product guide](https://earth.esa.int/eogateway/documents/20142/37627/PAZ-Image-Products-Guide.pdf) to the PAZ Product documentation instead of the TerraSAR-X one - by @guillemc23

Expand Down
6 changes: 3 additions & 3 deletions eoreader/products/optical/dimap_v2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,9 @@ def get_cloud_cover(self) -> float:
# Get the cloud cover
try:
cc = float(root.findtext(".//CLOUD_COVERAGE"))

except TypeError:
raise InvalidProductError("CLOUD_COVERAGE not found in metadata!")
except (InvalidProductError, TypeError):
LOGGER.warning("'CLOUD_COVERAGE' not found in metadata!")
cc = 0

return cc

Expand Down
6 changes: 3 additions & 3 deletions eoreader/products/optical/hls_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,9 @@ def get_cloud_cover(self) -> float:
# Get the cloud cover
try:
cc = float(root.findtext(".//cloud_coverage"))

except TypeError:
raise InvalidProductError("'cloud_coverage' not found in metadata!")
except (InvalidProductError, TypeError):
LOGGER.warning("'cloud_coverage' not found in metadata!")
cc = 0

return cc

Expand Down
6 changes: 3 additions & 3 deletions eoreader/products/optical/landsat_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ def get_cloud_cover(self) -> float:
# Get the cloud cover
try:
cc = float(root.findtext(".//CLOUD_COVER"))

except TypeError:
raise InvalidProductError("CLOUD_COVER not found in metadata!")
except (InvalidProductError, TypeError):
LOGGER.warning("'CLOUD_COVER' not found in metadata!")
cc = 0

return cc

Expand Down
5 changes: 3 additions & 2 deletions eoreader/products/optical/maxar_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,12 +1275,13 @@ def get_cloud_cover(self) -> float:
cc = float(root.findtext(".//CLOUDCOVER"))

except TypeError:
raise InvalidProductError("CLOUDCOVER not found in metadata!")
LOGGER.warning("'CLOUDCOVER' not found in metadata!")
cc = 0.0

# Manage the case with cloud_cover == -999.0
# i.e. 17APR05171409-M1BS_R1C1-000000010003_01_P001 (WV04)
if cc < 0.0:
cc = None
cc = 0.0

return cc

Expand Down
29 changes: 17 additions & 12 deletions eoreader/products/optical/planet_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,20 +1205,25 @@ def get_cloud_cover(self) -> float:
root, nsmap = self.read_mtd()

# Get the cloud cover
if self.constellation == Constellation.SKY:
try:
cc = float(root.findtext(".//cloud_percent"))
try:
if self.constellation == Constellation.SKY:
try:
cc = float(root.findtext(".//cloud_percent"))

except TypeError:
raise InvalidProductError("cloud_percent not found in metadata!")
else:
try:
cc = float(root.findtext(f".//{nsmap['opt']}cloudCoverPercentage"))
except TypeError:
raise InvalidProductError("'cloud_percent' not found in metadata!")
else:
try:
cc = float(root.findtext(f".//{nsmap['opt']}cloudCoverPercentage"))

except TypeError:
raise InvalidProductError(
"opt:cloudCoverPercentage not found in metadata!"
)
except TypeError:
raise InvalidProductError(
"'opt:cloudCoverPercentage' not found in metadata!"
)

except (InvalidProductError, TypeError) as ex:
LOGGER.warning(ex)
cc = 0

return cc

Expand Down
5 changes: 3 additions & 2 deletions eoreader/products/optical/s2_e84_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,9 @@ def get_cloud_cover(self) -> float:
"""
try:
cc = self.stac_mtd["properties"]["eo:cloud_cover"]
except IndexError:
raise InvalidProductError("cloud_cover not found in metadata!")
except (InvalidProductError, TypeError):
LOGGER.warning("'cloud_cover' not found in metadata!")
cc = 0

return cc

Expand Down
2 changes: 1 addition & 1 deletion eoreader/products/optical/s2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ def get_cloud_cover(self) -> float:
cc = float(root.findtext(".//CLOUDY_PIXEL_PERCENTAGE"))
except (InvalidProductError, TypeError):
LOGGER.warning(
"CLOUDY_PIXEL_PERCENTAGE not found in metadata! Cloud coverage set to 0."
"'CLOUDY_PIXEL_PERCENTAGE' not found in metadata! Cloud coverage set to 0."
)
cc = 0

Expand Down
8 changes: 4 additions & 4 deletions eoreader/products/optical/s2_theia_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,10 @@ def get_cloud_cover(self) -> float:
# Get the cloud cover
try:
cc = float(root.findtext(".//QUALITY_INDEX[@name='CloudPercent']"))

except TypeError:
raise InvalidProductError(
"QUALITY_INDEXQUALITY_INDEX name='CloudPercent' not found in metadata!"
except (InvalidProductError, TypeError):
LOGGER.warning(
"'QUALITY_INDEXQUALITY_INDEX name='CloudPercent'' not found in metadata!"
)
cc = 0

return cc

0 comments on commit 8020c5b

Please sign in to comment.