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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ants/viz/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

warnings.warn("Image must be non-zero. will not plot.")
return

Expand Down
Loading