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

Bugfix: Horizon image's dtype validation #3031

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

maharshi-gor
Copy link
Member

This PR resolves the issue #2789 about checking dtype of the passed image arrays.

Current behavior

  • When horizon is invoked from either we do not check the type of the data passed in the images. It is implicitly assumed to be an appropriate numerical type supported by horizon.
  • This causes issues when users are using the horizon from the python code as the type is not verified.

Proposed behavior

All the images will be checked for dtype and the following cases can be the result.

  1. Data is of type int32 or float32 or float64, data will be added to the valid images.
  2. Data is of a different integer subtype than int32, data will be cast to int32 and then will be added to the valid images. There will be a warning provided.
  3. Data is of a different floating subtype than float32 or float64, data will be cast to float64 and hen will be added to the valid images. There will be a warning provided.
  4. Data is of non-numeric type, a warning will be provided and data will not be added to the valid images.

Copy link

codecov bot commented Jan 6, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (8caa6c5) 82.08% compared to head (b0bc09b) 82.11%.
Report is 9 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3031      +/-   ##
==========================================
+ Coverage   82.08%   82.11%   +0.02%     
==========================================
  Files         146      146              
  Lines       20467    20495      +28     
  Branches     3261     3268       +7     
==========================================
+ Hits        16800    16829      +29     
+ Misses       2856     2855       -1     
  Partials      811      811              
Files Coverage Δ
dipy/testing/__init__.py 91.22% <100.00%> (+1.03%) ⬆️
dipy/viz/horizon/app.py 45.84% <100.00%> (+0.14%) ⬆️
dipy/viz/horizon/util.py 96.66% <95.23%> (+18.88%) ⬆️
dipy/core/sphere.py 93.30% <82.35%> (ø)

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @maharshi-gor,

Looks good to me. See below a very small comment but this PR is ready to be merged.

Thanks!

Comment on lines 137 to 142
def check_for_warnings(warn_printed, w_msg):
selected_w = [w for w in warn_printed if issubclass(w.category,
UserWarning)]
assert len(selected_w) >= 1
msg = [str(m.message) for m in selected_w]
npt.assert_equal(w_msg in msg, True)
Copy link
Member

Choose a reason for hiding this comment

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

this function is duplicated.

Maybe you should moved this function in dipy.testing.__init__.py

Comment on lines 29 to 34
def check_for_warnings(warn_printed, w_msg):
selected_w = [w for w in warn_printed if issubclass(w.category,
UserWarning)]
assert len(selected_w) >= 1
msg = [str(m.message) for m in selected_w]
npt.assert_equal(w_msg in msg, True)
Copy link
Member

Choose a reason for hiding this comment

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

duplicated, to move somewhere else



def check_img_dtype(images):
"""Check for supported dtype. If not supported numerical type, fallback to
Copy link
Member

Choose a reason for hiding this comment

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

after the first . you should return to a new line. see here for an example

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Thank you for this @maharshi-gor.

It looks good. merging

@skoudoro skoudoro merged commit 824eb38 into dipy:master Jan 10, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants