Skip to content

Commit

Permalink
Fix reflectance management for E84 and MPC S2 products
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Dec 4, 2023
1 parent 085066f commit 14a7f84
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions eoreader/products/optical/s2_e84_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,14 @@ def _to_reflectance(
Returns:
xr.DataArray: Band in reflectance
"""
band_mtd = self.stac_mtd["assets"][EOREADER_STAC_MAP[band].value][
"raster:bands"
][0]
return band_arr * band_mtd["scale"] + band_mtd["offset"]
# The offset is always applied for E84 products: https://github.com/sertit/eoreader/discussions/120#discussioncomment-7751885
# offset = 0
quantif_value = 10000.0

# Compute the correct radiometry of the band
band_arr = band_arr / quantif_value

return band_arr.astype(np.float32)

def _manage_invalid_pixels(
self, band_arr: xr.DataArray, band: BandNames, **kwargs
Expand Down Expand Up @@ -903,6 +907,8 @@ def __init__(
self.kwargs = kwargs
"""Custom kwargs"""

self._processing_baseline = None

# Copy the kwargs
super_kwargs = kwargs.copy()

Expand Down Expand Up @@ -944,6 +950,18 @@ def _pre_init(self, **kwargs) -> None:
# Pre init done by the super class
super(S2E84Product, self)._pre_init(**kwargs)

def _post_init(self, **kwargs) -> None:
"""
Function used to post_init the products
(setting sensor type, band names and so on)
"""
# Get processing baseline: N0213 -> 02.13
pr_baseline = float(self.split_name[3][1:]) / 100
self._processing_baseline = pr_baseline

# Pre init done by the super class
super(S2E84Product, self)._post_init(**kwargs)

def _get_name(self) -> str:
"""
Set product real name.
Expand Down Expand Up @@ -972,8 +990,11 @@ def _to_reflectance(
Returns:
xr.DataArray: Band in reflectance
"""
# TODO
offset = -1000.0
# TODO: use mtd for offset and quantif value
if self._processing_baseline < 4.0:
offset = 0.0
else:
offset = -1000.0
quantif_value = 10000.0

# Compute the correct radiometry of the band
Expand Down

0 comments on commit 14a7f84

Please sign in to comment.