pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.04k stars 287 forks source link

Add generic calibration coefficient selector #2811

Open sfinkens opened 2 weeks ago

sfinkens commented 2 weeks ago

As a first step towards channel-specific calibration modes (#2599), I added a generic calibration coefficient selector that can be used by all readers.

Example: Three sets of coefficients are available (nominal, meirink, gsics). A user wants to calibrate

The user would provide a wishlist via reader_kwargs:

calib_wishlist = {
    "ch1": "meirink",
    ("ch2", "ch3"): "gsics"
    "ch4": {"mygain": 123},
}
# Also possible: Same mode for all channels via
# calib_wishlist = "gsics"

Readers would compile a dictionary of coefficients

coefs = {
    "nominal": {
        "ch1": 1.0,
        "ch2": 2.0,
        "ch3": 3.0,
        "ch4": 4.0,
        "ch5": 5.0,
    },
    "meirink": {
        "ch1": 1.1,
    },
    "gsics": {
        "ch2": 2.2,
        # ch3 coefficients are missing
    }
}

and could then make queries to get the desired coefficients:

>>> from satpy.readers.utils import CalibrationCoefficientPicker
>>> picker = CalibrationCoefficientPicker(coefs, calib_wishlist)
>>> picker.get_coefs("ch1")
{"coefs": 1.0, "mode": "meirink"}
>>> picker.get_coefs("ch2")
{"coefs": 2.2, "mode": "gsics"}
>>> picker.get_coefs("ch3")
KeyError: 'No gsics calibration coefficients for ch3'
>>> picker.get_coefs("ch4")
{"coefs": {"mygain": 123}, "mode": "external"}
>>> picker.get_coefs("ch5")
{"coefs": 5.0, "mode": "nominal"}

Fallback to nominal coefficients for channel 3:

>>> picker = CalibrationCoefficientPicker(coefs, calib_wishlist, fallback="nominal")
>>> picker.get_coefs("ch3")
WARNING No gsics calibration coefficients for ch3. Falling back to nominal.
{"coefs": 3.0, "mode": "nominal"}

Let me know what you think!

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.94%. Comparing base (ab55c4a) to head (417c768). Report is 127 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2811 +/- ## ========================================== + Coverage 95.91% 95.94% +0.02% ========================================== Files 366 366 Lines 53504 53613 +109 ========================================== + Hits 51321 51441 +120 + Misses 2183 2172 -11 ``` | [Flag](https://app.codecov.io/gh/pytroll/satpy/pull/2811/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | Coverage Δ | | |---|---|---| | [behaviourtests](https://app.codecov.io/gh/pytroll/satpy/pull/2811/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `4.04% <0.00%> (-0.01%)` | :arrow_down: | | [unittests](https://app.codecov.io/gh/pytroll/satpy/pull/2811/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `96.04% <100.00%> (+0.02%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9483973148

Details


Totals Coverage Status
Change from base Build 9418285216: 0.005%
Covered Lines: 51632
Relevant Lines: 53758

💛 - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9485685926

Details


Totals Coverage Status
Change from base Build 9418285216: 0.004%
Covered Lines: 51620
Relevant Lines: 53746

💛 - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9495737646

Details


Totals Coverage Status
Change from base Build 9418285216: 0.004%
Covered Lines: 51621
Relevant Lines: 53747

💛 - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9499819988

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
satpy/resample.py 42 88.74%
<!-- Total: 42 -->
Totals Coverage Status
Change from base Build 9418285216: 0.008%
Covered Lines: 51665
Relevant Lines: 53791

💛 - Coveralls
sfinkens commented 2 weeks ago

I also renamed "selector" to "picker"

coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9512668046

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
satpy/resample.py 42 88.74%
<!-- Total: 42 -->
Totals Coverage Status
Change from base Build 9418285216: 0.008%
Covered Lines: 51667
Relevant Lines: 53793

💛 - Coveralls
coveralls commented 2 weeks ago

Pull Request Test Coverage Report for Build 9513296644

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
satpy/resample.py 42 88.74%
<!-- Total: 42 -->
Totals Coverage Status
Change from base Build 9418285216: 0.008%
Covered Lines: 51670
Relevant Lines: 53796

💛 - Coveralls