Skip to content

Commit

Permalink
FIX: Add a fallback in case map-overlay.kml is not readable for `Se…
Browse files Browse the repository at this point in the history
…ntinel-1` data #180
  • Loading branch information
remi-braun committed Nov 29, 2024
1 parent 7301c12 commit d30d5aa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Release History

## 0.21.8 (2024-mm-dd)
- FIX: Fix stack save_as_int to use updated int values

- ENH: Add a new type (`BandsType`) for list of BandType
- FIX: Fix stack `save_as_int` to use updated int values - by @TabeaW
- FIX: Fixed PAZ Product Regex to properly indentify PAZ ST products as `PAZProduct` - by @guillemc23
- FIX: Fixed preprocessing graph paths in order to support relative paths in more complex environments or contexts - by @guillemc23
- 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/issues/180))
- 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: 6 additions & 0 deletions CI/SCRIPTS/test_satellites.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ def _test_core(
check_geometry(prod, "extent", tmp_dir)
check_geometry(prod, "footprint", tmp_dir)

if hasattr(prod, "wgs84_extent"):
prod.wgs84_extent()

if hasattr(prod, "_fallback_wgs84_extent"):
prod._fallback_wgs84_extent()

# Get the bands we want to stack / load
stack_bands = [band for band in possible_bands if prod.has_band(band)]
first_band = stack_bands[0]
Expand Down
15 changes: 5 additions & 10 deletions eoreader/products/sar/s1_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,12 @@ def wgs84_extent(self) -> gpd.GeoDataFrame:
# Open the KML file
extent_wgs84 = vectors.read(preview_overlay)
else:
raise InvalidProductError(
f"Impossible to find the map-overlay.kml in {self.path}"
)
# raise to be caught by fallback
raise InvalidProductError

if extent_wgs84.empty:
raise InvalidProductError(
f"Cannot determine the WGS84 extent of {self.name}"
)

except Exception as ex:
raise InvalidProductError(ex) from ex
except Exception:
# Sometimes, map-overlay.kml of S1 products cannot be read properly
extent_wgs84 = self._fallback_wgs84_extent("preview/map-overlay.kml")

return extent_wgs84

Expand Down
18 changes: 16 additions & 2 deletions eoreader/products/sar/sar_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,16 @@ def _to_repr_constellation_specific(self) -> list:
f"\torbit direction: {self.get_orbit_direction().value}",
]

def _fallback_wgs84_extent(self, extent_file_name: str):
def _fallback_wgs84_extent(self, extent_file_name: str = None) -> gpd.GeoDataFrame:
"""
Fallback for wgs84 extent (slower than to read a file, but should work in almsot any case)
Args:
extent_file_name (str): Extent file name, if existing
Returns:
gpd.GeoDataFrame: WGS84 extent
"""
with rasterio.open(self.get_raw_band_paths()[self.get_default_band()]) as ds:
if ds.crs is not None:
extent_wgs84 = gpd.GeoDataFrame(
Expand All @@ -1039,8 +1048,13 @@ def _fallback_wgs84_extent(self, extent_file_name: str):
)
extent_wgs84 = gpd.GeoDataFrame(geometry=[extent_poly], crs=crs)
else:
if extent_file_name:
name = f"({extent_file_name}) "
else:
name = ""

raise InvalidProductError(
f"Extent file ({extent_file_name}) not found in {self.path}. "
f"Extent file {name}not found in {self.path}. "
"Default band isn't georeferenced and have no GCPs. "
"It is therefore impossible to determine quickly the extent of this product. "
"Please write an issue on GitHub!"
Expand Down

0 comments on commit d30d5aa

Please sign in to comment.