Skip to content

WMO Instruments Part 1#3390

Open
sfinkens wants to merge 24 commits intopytroll:mainfrom
sfinkens:wmo-instruments-part1
Open

WMO Instruments Part 1#3390
sfinkens wants to merge 24 commits intopytroll:mainfrom
sfinkens:wmo-instruments-part1

Conversation

@sfinkens
Copy link
Copy Markdown
Member

@sfinkens sfinkens commented May 6, 2026

This is the first of 4 PRs for getting WMO instrument names.

  1. Change Satpy internals to use sets for instruments
  2. Update all file handlers to provide an instruments
    attribute and use that instead of sensor.
  3. Rename "sensor" to "instrument" in all method names and docstrings.
  4. Remove legacy sensor attribute (probably after v1.0 has been released)

I hope this way the changes are less painful to review. To achieve
that, helper methods were added for

  • Getting/setting instruments from dataset attributes
  • Serializing instrument names for filename generation
  • 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. Or maybe removed entirely.

Breaking Changes

To make the tests pass for the moment, the sensor attribute is converted to a set in
get_instruments_from_attrs. We don't want to have that in main and it will be removed
in PR2. So I'll do PR2 against this branch.

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 97.11286% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.32%. Comparing base (ab7f790) to head (9ca9b79).
⚠️ Report is 295 commits behind head on main.

Files with missing lines Patch % Lines
satpy/readers/omps_edr.py 89.24% 10 Missing ⚠️
satpy/tests/reader_tests/test_omps_edr.py 99.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3390      +/-   ##
==========================================
- Coverage   96.34%   96.32%   -0.02%     
==========================================
  Files         466      468       +2     
  Lines       59155    59164       +9     
==========================================
  Hits        56990    56990              
- Misses       2165     2174       +9     
Flag Coverage Δ
behaviourtests 3.64% <12.86%> (+0.05%) ⬆️
unittests 96.41% <97.11%> (-0.02%) ⬇️

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
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.15.9 → v0.15.12](astral-sh/ruff-pre-commit@v0.15.9...v0.15.12)
- [github.com/pre-commit/mirrors-mypy: v1.20.0 → v1.20.2](pre-commit/mirrors-mypy@v1.20.0...v1.20.2)
- [github.com/pycqa/isort: 8.0.1 → 9.0.0a3](PyCQA/isort@8.0.1...9.0.0a3)
@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
"reader",
"platform_name",
"sensor",
instr_key,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh...this is difficult. I wonder if we should have a deprecation cycle or this? Or accept both and display a warning if "sensor" is detected/used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, this is where the sensor key from enhancement yamls is actually used? And apparently users can provide their own enhancements, so I think accepting both + warning is a good idea 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That makes me think if we should do that everywhere. For example when checking attributes

def get_instruments_from_attrs(attrs):
    # simplified a bit
    legacy = attrs.get("sensor", {})
    if legacy:
        warnings.warn(...)
    return attrs.get("instruments", legacy)

and in the yaml reader.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh maybe. Like if the user is creating their own DataArray (either "by hand" or in custom compositor code)? That makes sense.

And yes, this list is what is considered "identifying" information for an enhancement section in an enhancement YAML. It is used, in order, to build up a decision tree to choose which enhancement to use for a particular DataArray.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've reverted this change in the enhancement decision tree, because I think it fits better into PR2 (together with the yaml reader update). But I've updated get_instruments_from_attrs as described above.

Comment thread satpy/writers/mitiff.py Outdated
Comment thread satpy/utils.py Outdated
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 25488772252

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage at 96.398% (no base build to compare)

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 58947
Covered Lines: 56824
Line Coverage: 96.4%
Coverage Strength: 3.84 hits per line

💛 - Coveralls

@sfinkens
Copy link
Copy Markdown
Member Author

sfinkens commented May 8, 2026

I also moved the instrument helpers to their own module.

Comment thread satpy/dependency_tree.py
moptions = moptions.copy()
moptions.update(comp_id.to_dict())
moptions["sensor"] = sensor_name
moptions[instr_key] = sensor_name
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here's another one. I first thought it was a keyword argument, but actualy it is added to dataset attributes here

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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants