Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic calibration coefficient selector #2811

Merged
merged 13 commits into from
Jul 19, 2024

Conversation

sfinkens
Copy link
Member

@sfinkens sfinkens commented Jun 12, 2024

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

  • channel 1 with “meirink”
  • channels 2/3 with “gsics”
  • channel 4 with custom coefficients
  • remaining channels with default (nominal) coefficients

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!

  • Tests added
  • Fully documented

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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 Coverage Δ
behaviourtests 4.04% <0.00%> (-0.01%) ⬇️
unittests 96.04% <100.00%> (+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.

@sfinkens sfinkens changed the title Add support for channel-specific calibration modes in SEVIRI readers Add generic calibration coefficient selector Jun 12, 2024
@sfinkens sfinkens marked this pull request as ready for review June 12, 2024 14:00
@sfinkens sfinkens requested a review from gerritholl June 12, 2024 14:00
@coveralls
Copy link

coveralls commented Jun 12, 2024

Pull Request Test Coverage Report for Build 9483973148

Details

  • 71 of 71 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 96.045%

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

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 12, 2024

Pull Request Test Coverage Report for Build 9485685926

Details

  • 59 of 59 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 96.044%

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

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9495737646

Details

  • 60 of 60 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 96.044%

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

💛 - Coveralls

@sfinkens sfinkens requested a review from simonrp84 June 13, 2024 12:47
@coveralls
Copy link

coveralls commented Jun 13, 2024

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

  • 104 of 104 (100.0%) changed or added relevant lines in 2 files are covered.
  • 42 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 96.048%

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

💛 - Coveralls

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Looks great! just a couple of minor suggestions

satpy/readers/utils.py Outdated Show resolved Hide resolved
satpy/readers/utils.py Outdated Show resolved Hide resolved
@sfinkens
Copy link
Member Author

I also renamed "selector" to "picker"

@coveralls
Copy link

coveralls commented Jun 14, 2024

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

  • 106 of 106 (100.0%) changed or added relevant lines in 2 files are covered.
  • 42 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 96.048%

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

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 14, 2024

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

  • 109 of 109 (100.0%) changed or added relevant lines in 2 files are covered.
  • 42 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 96.048%

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

💛 - Coveralls

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Great job, lgtm!

@mraspaud mraspaud merged commit 9e60671 into pytroll:main Jul 19, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants