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 issue with plotting negative-sum images #562

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

ncullen93
Copy link
Member

@ncullen93 ncullen93 commented Mar 12, 2024

If an image has a sum less than zero, then ants.plot rejects it. This is due to code that incorrectly identifies whether an image is all-zero.

This should work:

import ants
img = ants.image_read(ants.get_ants_data('r16'))
img2 = (img - img.mean()) / img.std()
img2.plot()

@ncullen93 ncullen93 changed the title fix issue with plotting z-scored images fix issue with plotting negative-sum images Mar 12, 2024
@ncullen93 ncullen93 merged commit 0ad546f into master Mar 12, 2024
5 of 18 checks passed
@ncullen93 ncullen93 deleted the plot-std-img branch March 12, 2024 14:12
@stnava
Copy link
Member

stnava commented Mar 12, 2024

thanks for working on this - it has been on my todo list for several years

@@ -228,7 +228,7 @@ def reorient_slice(x, axis):
if not isinstance(image, iio.ANTsImage):
raise ValueError("image argument must be an ANTsImage")

if not image.sum() > 0:
if sum(sum(image != 0)) == 0:
Copy link
Member

Choose a reason for hiding this comment

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

This causes CI tests to fail, try

np.all(np.equal(image.numpy(), 0.0))

Copy link
Member

Choose a reason for hiding this comment

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

Running viz tests
E
======================================================================
ERROR: test_plot_example (__main__.TestModule_plot)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/ANTsPy/ANTsPy/tests/test_viz.py", line 33, in test_plot_example
    ants.plot(img, filename=filename)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ants/viz/plot.py", line 231, in plot
    if sum(sum(image != 0)) == 0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

@stnava
Copy link
Member

stnava commented Mar 12, 2024

also - I dont this this should raise an error but instead fail "gracefully"

@cookpa
Copy link
Member

cookpa commented Mar 12, 2024

@stnava you changed it to output a warning instead, which I think is the right call. #562 is just improving the test. It just needs to reduce to a scalar true / false to avoid ambiguity

@stnava
Copy link
Member

stnava commented Mar 12, 2024

ok

@cookpa
Copy link
Member

cookpa commented Mar 12, 2024

@ncullen93 I can fix this real quick, now it looks like all the other runners are done

@cookpa
Copy link
Member

cookpa commented Mar 12, 2024

#566

@ncullen93
Copy link
Member Author

Yes, thanks. Can you consider reducing the number of python versions tested in the CI to 1 or 2 instead of 5? It takes so long otherwise and doesn't add much. I will try to wait for it to finish going forward though.

@cookpa
Copy link
Member

cookpa commented Mar 12, 2024

Yeah, it can get painful when there's a lot of activity. I will have a think about how we can do better.

One option might be to put branch protection on master, and insist that all changes go through PR, and then build a couple of wheels in the PR. That would avoid duplication where PR builds pass and then the same wheels get built again on merge

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.

3 participants