Skip to content

Commit

Permalink
FIX: Fix Landsat L2 surface reflectance and temperature computation #99
Browse files Browse the repository at this point in the history
FIX: Test thermal bands in CI
  • Loading branch information
remi-braun committed Jul 20, 2023
1 parent 85549b8 commit 116fe4a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- FIX: Minor fix in RasterioError handling when reading bands
- FIX: Fix Landsat L2 surface reflectance and temperature computation ([#99](https://github.com/sertit/eoreader/issues/99))
- FIX: Test thermal bands in CI

## 0.20.2 (2023-06-22)

Expand Down
22 changes: 17 additions & 5 deletions CI/SCRIPTS/test_satellites.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SHADOWS,
SLOPE,
SWIR_2,
TIR_1,
VV,
VV_DSPK,
to_str,
Expand Down Expand Up @@ -67,7 +68,7 @@
"MERIT_DEM.vrt",
]

WRITE_ON_DISK = False
WRITE_ON_DISK = True


def set_dem(dem_path):
Expand Down Expand Up @@ -108,7 +109,7 @@ def _test_core_optical(pattern: str, dem_path=None, debug=False, **kwargs):
pattern (str): Pattern of the satellite
debug (bool): Debug option
"""
possible_bands = [RED, SWIR_2, HILLSHADE, CLOUDS]
possible_bands = [RED, SWIR_2, TIR_1, HILLSHADE, CLOUDS]
_test_core(pattern, opt_path(), possible_bands, dem_path, debug, **kwargs)


Expand Down Expand Up @@ -318,9 +319,20 @@ def _test_core(
ci.assert_val(stack.dtype, np.float32, "dtype")

# Check attributes
ci.assert_val(
stack.attrs["long_name"], " ".join(to_str(stack_bands)), "long_name"
)
try:
ci.assert_val(
stack.attrs["long_name"],
" ".join(to_str(stack_bands)),
"long_name",
)
except AssertionError:
# Just try the other way, it depends on the saved stack
ci.assert_val(
" ".join(stack.attrs["long_name"]),
" ".join(to_str(stack_bands)),
"long_name",
)

ci.assert_val(
stack.attrs["constellation"],
prod._get_constellation().value,
Expand Down
8 changes: 4 additions & 4 deletions eoreader/products/optical/landsat_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ def _to_tb(

band_arr = k2 / np.log(k1 / band_arr + 1)
elif self.product_type == LandsatProductType.L2:
c_mul_str = "TEMPERATURE_MULT_BAND_ST_" + band_name
c_add_str = "TEMPERATURE_ADD_BAND_ST_" + band_name
c_mul_str = "TEMPERATURE_MULT_BAND_ST_B" + band_name
c_add_str = "TEMPERATURE_ADD_BAND_ST_B" + band_name

# Get coeffs to convert DN to reflectance
c_mul = mtd.findtext(f".//{c_mul_str}")
Expand All @@ -1216,11 +1216,11 @@ def _to_tb(
try:
c_mul = float(c_mul)
except ValueError:
c_mul = 149.0
c_mul = 0.00341802
try:
c_add = float(c_add)
except ValueError:
c_add = 0.00341802
c_add = 149.0

# Compute the correct reflectance of the band and set no data to 0
band_arr = c_mul * band_arr + c_add # Already in float
Expand Down

0 comments on commit 116fe4a

Please sign in to comment.