Skip to content

Commit 7d9ff5b

Browse files
committed
- FIX: Fix several issues with S2 STAC products:
- Add missing `_has_mask` method - Fix `get_mean_sun_angles` and imports for MPC products
1 parent e81dacf commit 7d9ff5b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- FIX: Get correct buffer for windows in geographic CRS when subsetting SAR data
99
- FIX: Fix SNAP fallback issue
1010
- FIX: Workaround for calibration polarisation issue: don't specify any polarisation in case of single-polarisation product.
11+
- FIX: Fix several issues with S2 STAC products:
12+
- Add missing `_has_mask` method
13+
- Fix `get_mean_sun_angles` and imports for MPC products
1114
- DOC: Update copyright to 2026
1215

1316
## 0.23.0 (2026-01-02)

eoreader/products/optical/s2_e84_product.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,27 @@ def _get_path(self, file_id: str, ext: str = "tif") -> AnyPathType:
236236
"""
237237
return self._glob(f"*{file_id}.{ext}", as_rio_path=True)
238238

239+
def _has_mask(self, mask: BandNames) -> bool:
240+
"""
241+
Can the specified mask be loaded from this product?
242+
243+
.. code-block:: python
244+
245+
>>> from eoreader.reader import Reader
246+
>>> from eoreader.bands import *
247+
>>> path = r"S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432.SAFE.zip"
248+
>>> prod = Reader().open(path)
249+
>>> prod.has_index(DETFOO)
250+
True
251+
252+
Args:
253+
mask (BandNames): Mask
254+
255+
Returns:
256+
bool: True if the specified mask is provided by the current product
257+
"""
258+
return False
259+
239260
def open_mask(
240261
self, pixel_size: float = None, size: list | tuple = None, **kwargs
241262
) -> xr.DataArray:

eoreader/products/optical/s2_mpc_product.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from eoreader import EOREADER_NAME, cache
2828
from eoreader.bands import BandNames
29+
from eoreader.exceptions import InvalidProductError
2930
from eoreader.products import S2E84Product
3031
from eoreader.products.optical.optical_product import RawUnits
3132
from eoreader.products.stac_product import StacProduct
@@ -188,3 +189,30 @@ def get_quicklook_path(self) -> str:
188189
str: Quicklook path
189190
"""
190191
return self._get_path("rendered_preview")
192+
193+
@cache
194+
def get_mean_sun_angles(self) -> (float, float):
195+
"""
196+
Get Mean Sun angles (Azimuth and Zenith angles)
197+
198+
.. code-block:: python
199+
200+
>>> from eoreader.reader import Reader
201+
>>> path = r"LC08_L1GT_023030_20200518_20200527_01_T2.SAFE.zip"
202+
>>> prod = Reader().open(path)
203+
>>> prod.get_mean_sun_angles()
204+
(140.80752656, 61.93065805)
205+
206+
Returns:
207+
(float, float): Mean Azimuth and Zenith angle
208+
"""
209+
# Retrieve angles
210+
try:
211+
azimuth_angle = self.stac_mtd["properties"]["s2:mean_solar_azimuth"]
212+
zenith_angle = self.stac_mtd["properties"]["s2:mean_solar_zenith"]
213+
except IndexError as exc:
214+
raise InvalidProductError(
215+
"mean_solar_azimuth or mean_solar_zenith not found in metadata!"
216+
) from exc
217+
218+
return azimuth_angle, zenith_angle

0 commit comments

Comments
 (0)