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

Fix dtype promotion in SunZenithReduction #2950

Merged
merged 4 commits into from
Nov 8, 2024

Conversation

pnuu
Copy link
Member

@pnuu pnuu commented Oct 24, 2024

The SunZenithReduction modifier used for example in the built-in FCI true_color composite has a division with np.log(2) that changes the float32 input data to float64. This PR is a simple fix for that.

The upcasting is hidden behind some other part of the code because even without this fix the completed product was float32.

  • Tests added

This small change also reduced the memory usage for my 12-composite set by roughly 800 MB.

With main:
Screenshot 2024-10-24 at 10-01-12 Bokeh Plot

With this PR:
Screenshot 2024-10-24 at 10-01-18 Bokeh Plot

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.08%. Comparing base (f36a096) to head (6193040).
Report is 28 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2950   +/-   ##
=======================================
  Coverage   96.08%   96.08%           
=======================================
  Files         377      377           
  Lines       55125    55144   +19     
=======================================
+ Hits        52967    52986   +19     
  Misses       2158     2158           
Flag Coverage Δ
behaviourtests 3.94% <0.00%> (-0.01%) ⬇️
unittests 96.18% <100.00%> (+<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.

@coveralls
Copy link

coveralls commented Oct 24, 2024

Pull Request Test Coverage Report for Build 11669217385

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

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.001%) to 96.192%

Files with Coverage Reduction New Missed Lines %
satpy/tests/writer_tests/test_cf.py 1 99.14%
Totals Coverage Status
Change from base Build 11634318306: 0.001%
Covered Lines: 53230
Relevant Lines: 55337

💛 - Coveralls

@pnuu
Copy link
Member Author

pnuu commented Oct 28, 2024

The other two things doing upcasting for True color composite that hid this one were fixed in the merged #2954 and #2956 PRs.

Copy link
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.

So this fixes some extra memory being used inside a dask task, but doesn't change the final dtype of the output of this "angles" step (which was correct), right?

Side note: Based on this math website, can't this equation be rewritten as log-base2 of reduction_factor + 1?

https://www.cuemath.com/algebra/log-rules/

change of base rule: loga b = (logc b) / (logc a)

@pnuu
Copy link
Member Author

pnuu commented Nov 4, 2024

With the current main float32 input data resulted in output of float64 because of np.log(2) promoting reduction_factor to float64 and finally causing the same to res. With this fix the output will also be float32. float64 input will still yield float64 result.

@pnuu
Copy link
Member Author

pnuu commented Nov 4, 2024

And well spotted, the log2 is much simpler in every way. Fixed in 6193040

@djhoese
Copy link
Member

djhoese commented Nov 4, 2024

And well spotted, the log2 is much simpler in every way. Fixed in 6193040

Hopefully that is still mathematically equivalent and I'm not misreading it.

@pnuu
Copy link
Member Author

pnuu commented Nov 4, 2024

And well spotted, the log2 is much simpler in every way. Fixed in 6193040

Hopefully that is still mathematically equivalent and I'm not misreading it.

It is, the tests pass (at least locally).

@pnuu
Copy link
Member Author

pnuu commented Nov 4, 2024

I restarted CI, MacOS tests failed on setup.

@mraspaud mraspaud merged commit 4fbc20c into pytroll:main Nov 8, 2024
16 of 18 checks passed
@pnuu pnuu deleted the bugfix-sunzenithreducer-dtype-promotion branch November 26, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants