Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
78894c3
Make sensor attribute a set
sfinkens May 4, 2026
dac0457
Use instrument instead of sensor attribute
sfinkens May 6, 2026
8ffb671
Add instrument attribute setter
sfinkens May 6, 2026
2d730ea
Reset ABI name
sfinkens May 6, 2026
180a040
Convert string type sensors to set for now
sfinkens May 6, 2026
46b08c2
Fix tests
sfinkens May 6, 2026
fe1d232
Update docstring
sfinkens May 6, 2026
32ee183
Restore accidental string replace
sfinkens May 6, 2026
bb04e29
Make sensor attribute a set
sfinkens May 4, 2026
fbb55cf
Use instrument instead of sensor attribute
sfinkens May 6, 2026
9633197
Add instrument attribute setter
sfinkens May 6, 2026
1d362c7
Reset ABI name
sfinkens May 6, 2026
ae1d8e7
Convert string type sensors to set for now
sfinkens May 6, 2026
d95a3f3
Fix tests
sfinkens May 6, 2026
2107f44
Update docstring
sfinkens May 6, 2026
78e0de9
Restore accidental string replace
sfinkens May 6, 2026
32a8e02
Replace direct attribute access with setter
sfinkens May 7, 2026
1e69183
Merge branch 'wmo-instruments-part1' of https://github.com/sfinkens/s…
sfinkens May 7, 2026
e4a53b6
Restore enhancer keyword arguments
sfinkens May 7, 2026
db7731d
Add deprecation warnings for sensor attribute
sfinkens May 7, 2026
8d50a8d
Add tests for instrument utilities
sfinkens May 7, 2026
f0970e3
Move instrument helpers to their own module
sfinkens May 8, 2026
9ca9b79
Remove explicit sensor usage in dependency tree
sfinkens May 8, 2026
6fa9743
Use better name for instruments module
sfinkens May 20, 2026
677a388
Choose better method names
sfinkens May 20, 2026
0f9c99c
Add internal to WMO conversion method
sfinkens May 20, 2026
5ecfa7f
Make scene.sensor_names return WMO names
sfinkens May 20, 2026
020a1d9
Convert WMO to internal in enhancer
sfinkens May 20, 2026
18744ea
Fix sensor_names expectations in tests
sfinkens May 20, 2026
98eaa15
Merge branch 'main' into wmo-instruments-part1
sfinkens May 20, 2026
8afd9f2
Wrap deprecation warning with v1.0 scissors
sfinkens May 22, 2026
bd2a355
Change scissor version to 1.1
sfinkens May 22, 2026
e0e76de
Add config switch for legacy sensor attribute
sfinkens May 22, 2026
f6a5fee
Update documentation
sfinkens May 22, 2026
02c455a
Change scissors again
sfinkens May 22, 2026
c147e09
Change scissors again
sfinkens May 22, 2026
e9e3e9f
Remove config switch
sfinkens May 22, 2026
bbe02e1
Merge branch 'wmo-instruments-part2-config-switch' into wmo-instrumen…
sfinkens May 22, 2026
831938d
Fix exceptions in sensor compatibility
sfinkens May 22, 2026
da4b460
Update documentation
sfinkens May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
- types-setuptools
- types-PyYAML
- types-requests
args: ["--python-version", "3.10", "--ignore-missing-imports"]
args: ["--python-version", "3.11", "--ignore-missing-imports"]
- repo: https://github.com/pycqa/isort
rev: 9.0.0a3
hooks:
Expand Down
2 changes: 1 addition & 1 deletion doc/source/dev_guide/custom_reader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ needs to implement a few methods:
successful, containing the data and :ref:`metadata <dataset_metadata>` of the
loaded dataset, or return None if the loading was unsuccessful. If the reader
is reading satellite data the returned xarray.DataArrays should also have the
attributes ``platform_name`` and ``sensor`` with names according to https://space.oscar.wmo.int/.
attributes ``platform_name`` and ``instruments`` with names according to https://space.oscar.wmo.int/.

The DataArray should at least have a ``y`` dimension. For data covering
a 2D region on the Earth, their should be at least a ``y`` and ``x``
Expand Down
4 changes: 2 additions & 2 deletions doc/source/dev_guide/xarray_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To create such an array, you can do for example

my_dataarray = xr.DataArray(my_data, dims=['y', 'x'],
coords={'x': np.arange(...)},
attrs={'sensor': 'olci'})
attrs={'instruments': {'OLCI'})

where ``my_data`` can be a regular numpy array, a numpy memmap, or, if you
want to keep things lazy, a dask array (more on dask later). Satpy uses dask
Expand Down Expand Up @@ -105,7 +105,7 @@ Some metadata that should always be present in our dataarrays:

- ``area`` the area of the dataset. This should be handled in the reader.
- ``start_time``, ``end_time``
- ``sensor``
- ``instruments``

Operations on DataArrays
************************
Expand Down
10 changes: 10 additions & 0 deletions doc/source/reading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ time etc. The following attributes are standardized across all readers:
* ``sensor``: The name of the sensor that recorded the data. For full support through Satpy this
should be all lowercase. If the dataset is the result of observations from multiple sensors a
``set`` object can be used to specify more than one sensor name.

.. deprecated:: 0.61.0

The ``sensor`` attribute will be replaced by ``instruments`` in Satpy v1.0.

* ``instruments``: Names of instruments that recorded the data, stored in a ``set`` object.
Instrument names follow the WMO OSCAR naming conventions.

.. versionadded:: 0.61.0

* ``reader``: The name of the Satpy reader that produced the dataset.
* ``orbital_parameters``: Dictionary of orbital parameters describing the satellite's position.
See the :ref:`orbital_parameters` section below for more information.
Expand Down
1 change: 1 addition & 0 deletions satpy/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"readers": {
"clip_negative_radiances": False,
},
"instruments_key": "sensor",
}

# Satpy main configuration object
Expand Down
177 changes: 177 additions & 0 deletions satpy/_instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Copyright (c) 2026 Satpy developers
#
# This file is part of satpy.
#
# satpy is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# satpy is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Helpers for accessing and modifying instrument attributes."""

import logging
import warnings
from enum import StrEnum
from typing import Any

import satpy

logger = logging.getLogger(__name__)

def get_instruments_from_attrs(attrs: dict[str,Any], to_internal: bool=False) -> set[str]:
"""Get instrument names from dataset attributes.

String type attributes are converted to set. This can be
removed once all file handlers provide instruments as a
set.
"""
instruments = attrs.get("instruments", set())
# 8< v1.0
sensor = attrs.get("sensor", set())
if sensor:
warnings.warn(
"Satpy will ignore the 'sensor' attribute as of v1.0. "
"Use the 'instruments' attribute instead.",
DeprecationWarning,
stacklevel=2
)
if not instruments:
instruments = sensor
if isinstance(instruments, str):
warnings.warn(
"Converting 'instruments' attribute from string to set. "
"This will result in an error in v1.0, when Satpy will require "
"set type instruments attributes.",
DeprecationWarning,
stacklevel=2
)
instruments = set([instruments])
# >8 v1.0
if to_internal:
return {
wmo_to_internal(inst) for inst in instruments
}
return instruments



def wmo_to_internal(instrument: str) -> str:
"""Convert WMO to internal instrument name."""
sep_map = {
"-": "-",
"(": "",
")": "",
" ": "_",
"/": "-"
}
sep_trans = str.maketrans(sep_map)
return instrument.translate(sep_trans).lower()


def get_one_instrument_from_attrs(attrs: dict[str,Any]) -> str:
"""Get a single instrument name from dataset attributes."""
instruments = get_instruments_from_attrs(attrs)
if not instruments:
raise KeyError("No 'instruments' in dataset attribute")
if len(instruments) > 1:
logger.warning(f"More than one instrument in dataset attributes, will use the first value: {instruments}")
return list(instruments)[0]


def get_pyspectral_instrument_name(instrument: str) -> str:
"""Get instrument name expected by pyspectral."""
return wmo_to_internal(instrument)


def join_instrument_names(instruments: set[str]) -> str:
"""Join a set of instrument names."""
return "-".join(sorted(instruments))


def set_instruments_attr(attrs: dict[str,Any], instruments: set[str]|str) -> None:
"""Set 'instruments' dataset atrribute."""
key = get_instruments_key()
attrs[key] = instruments


def get_instruments_key():
"""Get key for instruments in dataset attributes."""
return satpy.config.get("instruments_key")


class OSCAR(StrEnum):
"""WMO OSCAR instrument names."""
ABI = "ABI"
AHI = "AHI"
AMSR_2 = "AMSR2"
AMSU_A = "AMSU-A"
AMSU_B = "AMSU-B"
ATMS = "ATMS"
AVHRR = "AVHRR"
AVHRR_2 = "AVHRR/2"
AVHRR_3 = "AVHRR/3"
CRIS = "CrIS"
EPIC = "EPIC"
ETM_PLUS = "ETM+"
FCI = "FCI"
GLM = "GLM"
GMI = "GMI"
IASI = "IASI"
IASI_NG = "IASI-NG"
IMAGER_GOES_12_15 = "IMAGER (GOES 12-15)"
IMAGER_GOES_8_11 = "IMAGER (GOES 8-11)"
IMAGER_INSAT = "IMAGER (INSAT)"
IMAGER_MTSAT_2 = "IMAGER (MTSAT-2)"
JAMI = "JAMI"
LI = "LI"
MERIS = "MERIS"
MERSI_1 = "MERSI-1"
MERSI_2 = "MERSI-2"
MERSI_3 = "MERSI-3"
MERSI_LL = "MERSI-LL"
MERSI_RM = "MERSI-RM"
METIMAGE = "METimage"
MHS = "MHS"
MODIS = "MODIS"
MSS = "MSS"
MSU_GS = "MSU-GS"
MSU_GS_A = "MSU-GS/A"
MVIRI = "MVIRI"
# OSCAR lists "MWR (Sterna)", "MWR (AWS)" etc.
# But to avoid enhancement/composite duplication
# we just use "MWR".
MWR = "MWR"
OCI = "OCI"
OLCI = "OLCI"
OLI = "OLI"
SEAWIFS = "SeaWiFS"
SEVIRI = "SEVIRI"
SGLI = "SGLI"
SLSTR = "SLSTR"
SSMIS = "SSMIS"
TIRS = "TIRS"
TM = "TM"
VIIRS = "VIIRS"
VISSR = "VISSR"
VISSR_HIMAWARI_5 = "VISSR (Himawari-5)"


def enum_to_str(instruments: set[StrEnum]) -> set[str]:
"""Convert OSCAR enums to string."""
return {str(i) for i in instruments}


_INTERNAL_TO_WMO = {
wmo_to_internal(inst): str(inst)
for inst in OSCAR
}

def internal_to_wmo(instrument: str) -> str:
"""Convert internal to WMO instrument name."""
return _INTERNAL_TO_WMO.get(instrument, instrument)
3 changes: 2 additions & 1 deletion satpy/composites/aux_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os

import satpy
import satpy._instruments as inst_utils
from satpy.aux_download import DataDownloadMixin

from .core import GenericCompositor
Expand Down Expand Up @@ -156,7 +157,7 @@ def __call__(self, *args, **kwargs):
if self.area is None:
raise AttributeError("Area definition needs to be configured")
img.attrs["area"] = self.area
img.attrs["sensor"] = None
inst_utils.set_instruments_attr(img.attrs, set())
img.attrs["mode"] = "".join(img.bands.data)
img.attrs.pop("modifiers", None)
img.attrs.pop("calibration", None)
Expand Down
3 changes: 2 additions & 1 deletion satpy/composites/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from yaml import UnsafeLoader

import satpy
import satpy._instruments as inst_utils
from satpy import DataID, DataQuery
from satpy._config import config_search_paths, get_entry_points_config_dirs, glob_config
from satpy.dataset.dataid import minimal_default_keys_config
Expand Down Expand Up @@ -268,7 +269,7 @@ def load_compositor_configs_for_sensor(sensor_name: str) -> tuple[dict[str, dict
DataID key -> key properties

"""
config_filename = sensor_name + ".yaml"
config_filename = inst_utils.wmo_to_internal(sensor_name) + ".yaml"
logger.debug("Looking for composites config file %s", config_filename)
paths = get_entry_points_config_dirs("satpy.composites")
composite_configs = config_search_paths(
Expand Down
20 changes: 6 additions & 14 deletions satpy/composites/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import numpy as np
import xarray as xr

import satpy._instruments as inst_utils
from satpy.dataset import DataID, combine_metadata
from satpy.dataset.dataid import minimal_default_keys_config
from satpy.utils import unify_chunks
Expand Down Expand Up @@ -433,20 +434,11 @@ def _concat_datasets(self, projectables, mode):

return data

def _get_sensors(self, projectables):
sensor = set()
def _get_sensors(self, projectables) -> set[str]:
sensors = set()
for projectable in projectables:
current_sensor = projectable.attrs.get("sensor", None)
if current_sensor:
if isinstance(current_sensor, (str, bytes)):
sensor.add(current_sensor)
else:
sensor |= current_sensor
if len(sensor) == 0:
sensor = None
elif len(sensor) == 1:
sensor = list(sensor)[0]
return sensor
sensors.update(inst_utils.get_instruments_from_attrs(projectable.attrs))
return sensors

def __call__(
self,
Expand Down Expand Up @@ -512,7 +504,7 @@ def _get_updated_attrs(self, datasets, attrs, mode):
new_attrs.update(self.attrs)
if resolution is not None:
new_attrs["resolution"] = resolution
new_attrs["sensor"] = self._get_sensors(datasets)
inst_utils.set_instruments_attr(new_attrs, self._get_sensors(datasets))
new_attrs["mode"] = mode

return new_attrs
Expand Down
6 changes: 4 additions & 2 deletions satpy/composites/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import numpy as np
import xarray as xr

import satpy._instruments as inst_utils
from satpy.dataset import combine_metadata

from .core import (
Expand Down Expand Up @@ -406,9 +407,10 @@ def _combine_metadata_with_mode_and_sensor(self,
# 'mode' is no longer valid after we've remove the 'A'
# let the base class __call__ determine mode
attrs.pop("mode", None)
if attrs.get("sensor") is None:
if not inst_utils.get_instruments_from_attrs(attrs):
# sensor can be a set
attrs["sensor"] = self._get_sensors([foreground, background])
instruments = self._get_sensors([foreground, background])
inst_utils.set_instruments_attr(attrs, instruments)
return attrs

@staticmethod
Expand Down
5 changes: 2 additions & 3 deletions satpy/composites/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import xarray as xr

import satpy._instruments as inst_utils
from satpy.enhancements.enhancer import get_enhanced_image

from .core import GenericCompositor
Expand Down Expand Up @@ -96,9 +97,7 @@ def _update_attrs(self, new_data, background_layer, highlight_layer):
new_data.attrs = background_layer.attrs.copy()
new_data.attrs["units"] = 1
new_sensors = self._get_sensors((highlight_layer, background_layer))
new_data.attrs.update({
"sensor": new_sensors,
})
inst_utils.set_instruments_attr(new_data.attrs, new_sensors)

def __call__(self, projectables, optional_datasets=None, **attrs):
"""Create RGBA image with highlighted pixels."""
Expand Down
4 changes: 3 additions & 1 deletion satpy/dependency_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import numpy as np

import satpy._instruments as inst_utils
from satpy import DataID, DatasetDict
from satpy.dataset import ModifierTuple, create_filtered_query
from satpy.dataset.data_dict import TooManyResults, get_key
Expand Down Expand Up @@ -504,6 +505,7 @@ def get_compositor(self, key):
def get_modifier(self, comp_id):
"""Get a modifer."""
# create a DataID for the compositor we are generating
instr_key = inst_utils.get_instruments_key()
modifier = comp_id["modifiers"][-1]
for sensor_name in sorted(self.modifiers):
modifiers = self.modifiers[sensor_name]
Expand All @@ -514,7 +516,7 @@ def get_modifier(self, comp_id):
mloader, moptions = modifiers[modifier]
moptions = moptions.copy()
moptions.update(comp_id.to_dict())
moptions["sensor"] = sensor_name
moptions[instr_key] = sensor_name
compositors[comp_id] = mloader(_satpy_id=comp_id, **moptions)
return compositors[comp_id]

Expand Down
Loading
Loading