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 weighted mean std when infinite values #898

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

arnaudbore
Copy link
Contributor

Quick description

Email from Po-Jui:

Mario and I found an unexpected behavior with the function weighted_mean_std in scilpy. np.average is used inside that function to compute the weighted mean with the image saved in a numpy masked array. In this case, the voxels of invalid nan values would be considered in the denominator of the weighted mean computation. To compute the weighted average on a masked numpy array without the invalid voxels, np.ma.average should be used.
Another thing we would like to propose is to check infinity values in the image, in addition to checking nan values. The proposed modification is in blue

...

Type of change

Check the relevant options.

  • Bug fix (non-breaking change which fixes an issue)

Provide data, screenshots, command line to test (if relevant)

...

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (82b98a1) 65.92% compared to head (daf42c5) 65.92%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #898   +/-   ##
=======================================
  Coverage   65.92%   65.92%           
=======================================
  Files         384      384           
  Lines       21331    21331           
  Branches     3491     3491           
=======================================
  Hits        14063    14063           
  Misses       5664     5664           
  Partials     1604     1604           
Components Coverage Δ
Scripts ∅ <ø> (∅)
Library ∅ <ø> (∅)

Copy link
Contributor

@karanphil karanphil left a comment

Choose a reason for hiding this comment

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

Good to go. I tested it with toy arrays. Does not work with None, but with np.nan.

@arnaudbore arnaudbore merged commit 9381895 into scilus:master Feb 20, 2024
1 check passed
@arnaudbore arnaudbore deleted the fix_weighted_mean_std branch March 25, 2024 20:32
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.

2 participants