Skip to content

Switch to WMO Instruments#3390

Open
sfinkens wants to merge 40 commits into
pytroll:mainfrom
sfinkens:wmo-instruments-part1
Open

Switch to WMO Instruments#3390
sfinkens wants to merge 40 commits into
pytroll:mainfrom
sfinkens:wmo-instruments-part1

Conversation

@sfinkens
Copy link
Copy Markdown
Member

@sfinkens sfinkens commented May 6, 2026

The Plan

This is the first of a series of PRs for switching to WMO instrument names (AVHRR/1) in user facing places, namely dataset attributes and scene.sensor_names. The internal representation (avhrr-1) remains the same.

Furthermore, we agreed to deprecate sensor: str|set[str] in favor of instruments: set[str]. For backwards compatibility, a config switch will be added to get the legacy sensor attribute back.

  1. (This PR) Change Satpy internals to use sets for instruments and prepare for the transition to instruments.
  2. Deprecate sensor in favor of instruments
    2.1 Enhancements: WMO Instruments Part 2.1: Enhancements sfinkens/satpy#2
    2.2 File Handlers: WMO Instruments Part 2.2: File Handlers sfinkens/satpy#3
  3. Rename enhancement/composite YAML files so that they match the internal representation of the WMO sensor name.
  4. Rename sensor to instrument in all method names and docstrings.

I hope this way the changes are less painful to review. PRs 2-4 are relative to this PR, which will be merged into main eventually.

Changes in this PR

  • Add satpy._instruments module containing
    • A StrEnum with all WMO instrument names. Members behave like strings, even in sets
      len({"ABI", OSCAR.ABI}) == 1
      Internally the enum values are used directly. Dataset attributes are still converted to plain strings because that's easier for users (no custom type, simpler string repr).
    • Helper methods for
      • Getting instruments from dataset attributes. Both sensor and instruments are supported, with a deprecation warning for sensor.
      • Setting instrument attributes
      • Converting instrument names WMO <-> internal
  • For backwards compatibility, add sensor attribute in scene.__getitem__ if it doesn't exist. To be removed in v1.0.
  • A temporary config switch instruments_key that controls which attribute Satpy is using. This is mostly for postponing the file handler changes to the second PR. Current default is sensor, will be changed to instruments once all file handlers provide an instruments attribute, and then removed.

Breaking Changes

None so far. For v1.0 we would have to remove compatibility methods and deprecation warnings wrapped in 8< v1.0. Then Satpy wouldn't support the sensor attribute anymore.

Notes

It would be nice to have a custom Attributes class with getters and setters for the instrument, but xarray converts it back to plain dicts internally.

  • Closes #xxxx
  • Tests added
  • Fully documented
  • Add your name to AUTHORS.md if not there already

@sfinkens sfinkens requested review from djhoese and mraspaud as code owners May 6, 2026 14:26
@sfinkens sfinkens mentioned this pull request May 6, 2026
4 tasks
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 99.58506% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.31%. Comparing base (18d7f60) to head (da4b460).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
satpy/_instruments.py 98.94% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3390    +/-   ##
========================================
  Coverage   96.30%   96.31%            
========================================
  Files         466      468     +2     
  Lines       59090    59264   +174     
========================================
+ Hits        56908    57081   +173     
- Misses       2182     2183     +1     
Flag Coverage Δ
behaviourtests 3.76% <46.47%> (+0.17%) ⬆️
unittests 96.40% <99.58%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sfinkens
Copy link
Copy Markdown
Member Author

sfinkens commented May 6, 2026

Would it make sense to move those instrument helper methods to a dedicated module _instrumenty.py?

Comment thread satpy/writers/mitiff.py Outdated
@djhoese djhoese added enhancement code enhancements, features, improvements documentation component:readers backwards-incompatibility Causes backwards incompatibility or introduces a deprecation labels May 6, 2026
@djhoese
Copy link
Copy Markdown
Member

djhoese commented May 6, 2026

I added the "backwards-incompatibility" label on this PR. Let me know if that isn't accurate. You should rebase this PR on main which now includes some fixes for CI.

Copy link
Copy Markdown
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. I had a couple questions inline. I think my biggest long term fear after seeing these changes is handling the "sensor" in the enhancement decision tree.

Comment thread satpy/composites/aux_data.py Outdated
Comment thread satpy/composites/glm.py Outdated
Comment thread satpy/enhancements/enhancer.py Outdated
Comment thread satpy/writers/mitiff.py Outdated
Comment thread satpy/utils.py Outdated
@sfinkens
Copy link
Copy Markdown
Member Author

sfinkens commented May 8, 2026

I also moved the instrument helpers to their own module.

@sfinkens sfinkens moved this to In progress in PCW Spring 2026 May 18, 2026
@sfinkens sfinkens moved this from In progress to In review in PCW Spring 2026 May 19, 2026
@sfinkens sfinkens changed the title WMO Instruments Part 1 Switch to WMO Instruments May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards-incompatibility Causes backwards incompatibility or introduces a deprecation component:readers documentation enhancement code enhancements, features, improvements

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants