Skip to content

Commit

Permalink
Merge pull request #2779 from yukaribbba/convert_msi_name_to_lowercase
Browse files Browse the repository at this point in the history
Convert Sentinel-2 MSI sensor name to lowercase in the reader YAML config file and add support for "counts" calibration
  • Loading branch information
mraspaud authored Apr 17, 2024
2 parents 23af5d4 + 4faccbb commit e7ccaa0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
65 changes: 52 additions & 13 deletions satpy/etc/readers/msi_safe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ datasets:

B01:
name: B01
sensor: MSI
sensor: msi
wavelength: [0.415, 0.443, 0.470]
resolution: 60
calibration:
Expand All @@ -36,11 +36,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B02:
name: B02
sensor: MSI
sensor: msi
wavelength: [0.440, 0.490, 0.540]
resolution: 10
calibration:
Expand All @@ -50,11 +53,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B03:
name: B03
sensor: MSI
sensor: msi
wavelength: [0.540, 0.560, 0.580]
resolution: 10
calibration:
Expand All @@ -64,11 +70,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B04:
name: B04
sensor: MSI
sensor: msi
wavelength: [0.645, 0.665, 0.685]
resolution: 10
calibration:
Expand All @@ -78,11 +87,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B05:
name: B05
sensor: MSI
sensor: msi
wavelength: [0.695, 0.705, 0.715]
resolution: 20
calibration:
Expand All @@ -92,11 +104,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B06:
name: B06
sensor: MSI
sensor: msi
wavelength: [0.731, 0.740, 0.749]
resolution: 20
calibration:
Expand All @@ -106,11 +121,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B07:
name: B07
sensor: MSI
sensor: msi
wavelength: [0.764, 0.783, 0.802]
resolution: 20
calibration:
Expand All @@ -120,11 +138,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B08:
name: B08
sensor: MSI
sensor: msi
wavelength: [0.780, 0.842, 0.905]
resolution: 10
calibration:
Expand All @@ -134,11 +155,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B8A:
name: B8A
sensor: MSI
sensor: msi
wavelength: [0.855, 0.865, 0.875]
resolution: 20
calibration:
Expand All @@ -148,11 +172,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B09:
name: B09
sensor: MSI
sensor: msi
wavelength: [0.935, 0.945, 0.955]
resolution: 60
calibration:
Expand All @@ -162,11 +189,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B10:
name: B10
sensor: MSI
sensor: msi
wavelength: [1.365, 1.375, 1.385]
resolution: 60
calibration:
Expand All @@ -176,11 +206,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B11:
name: B11
sensor: MSI
sensor: msi
wavelength: [1.565, 1.610, 1.655]
resolution: 20
calibration:
Expand All @@ -190,11 +223,14 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule

B12:
name: B12
sensor: MSI
sensor: msi
wavelength: [2.100, 2.190, 2.280]
resolution: 20
calibration:
Expand All @@ -204,6 +240,9 @@ datasets:
radiance:
standard_name: toa_outgoing_radiance_per_unit_wavelength
units: W m-2 um-1 sr-1
counts:
standard_name: counts
units: "1"
file_type: safe_granule


Expand Down
2 changes: 2 additions & 0 deletions satpy/readers/msi_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def _read_from_file(self, key):
return self._mda.calibrate_to_reflectances(proj, self._channel)
if key["calibration"] == "radiance":
return self._mda.calibrate_to_radiances(proj, self._channel)
if key["calibration"] == "counts":
return self._mda._sanitize_data(proj)

@property
def start_time(self):
Expand Down
12 changes: 11 additions & 1 deletion satpy/tests/reader_tests/test_msi_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,15 @@ def test_xml_calibration(self):
np.testing.assert_allclose(result, [[[np.nan, 0.01 - 10, 0.02 - 10, 0.03 - 10],
[0.04 - 10, 0, 655.34 - 10, np.inf]]])

def test_xml_calibration_to_counts(self):
"""Test the calibration to counts."""
fake_data = xr.DataArray([[[0, 1, 2, 3],
[4, 1000, 65534, 65535]]],
dims=["band", "x", "y"])
result = self.xml_fh._sanitize_data(fake_data)
np.testing.assert_allclose(result, [[[np.nan, 1, 2, 3],
[4, 1000, 65534, np.inf]]])

def test_xml_calibration_unmasked_saturated(self):
"""Test the calibration with radiometric offset but unmasked saturated pixels."""
from satpy.readers.msi_safe import SAFEMSIMDXML
Expand Down Expand Up @@ -979,7 +988,8 @@ def setup_method(self):
@pytest.mark.parametrize(("mask_saturated", "calibration", "expected"),
[(True, "reflectance", [[np.nan, 0.01 - 10], [645.34, np.inf]]),
(False, "reflectance", [[np.nan, 0.01 - 10], [645.34, 645.35]]),
(True, "radiance", [[np.nan, -251.58426503], [16251.99095011, np.inf]])])
(True, "radiance", [[np.nan, -251.58426503], [16251.99095011, np.inf]]),
(False, "counts", [[np.nan, 1], [65534, 65535]])])
def test_calibration_and_masking(self, mask_saturated, calibration, expected):
"""Test that saturated is masked with inf when requested and that calibration is performed."""
from satpy.readers.msi_safe import SAFEMSIL1C, SAFEMSIMDXML
Expand Down

0 comments on commit e7ccaa0

Please sign in to comment.