-
Notifications
You must be signed in to change notification settings - Fork 262
MRG: Slice viewer #404
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
Merged
Merged
MRG: Slice viewer #404
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
af43883
NF: add version of Paul Ivanov's slice viewer
matthew-brett 8bb7fb0
ENH: Add crosshairs, modify mode
larsoner 5097571
FIX: Minor fixes
larsoner 6fda4d8
ENH: Add set_indices method
larsoner e55a15e
ENH: Allow time dimension
larsoner f9c6ae0
ENH: Better tests
larsoner 11ff239
FIX: Update volume plot
larsoner bf54667
FIX: Remove monkey patching
larsoner 62bce40
WIP
larsoner e516932
WIP: Closer to correcting orientation
larsoner b58a5d1
WIP: Fixed ratio
larsoner e54b536
FIX: FIX time plot
larsoner 64aa849
FIX: Fix orientations and interactions
larsoner 4bf9d5c
FIX: Minor fixes
larsoner 8b3aaa9
FIX: Fix test
larsoner 9b18cd3
FIX: Better testing
larsoner 34cef80
STY: Remove dicts in favor of lists
larsoner 485ecda
FIX: Cleanup on close
larsoner 59cd10f
FIX: Better unlinking
larsoner f08525f
FIX: Minor fix
larsoner 416f784
ENH: Add +/- key support for incrementing/decrementing the volume for…
grlee77 4459cef
FIX: raise TypeError on complex input prior to figure creation
grlee77 ba1243e
FIX: Fix operators
larsoner 2a8a73c
FIX: Clean up code
larsoner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## | ||
# | ||
# See COPYING file distributed along with the NiBabel package for the | ||
# copyright and license terms. | ||
# | ||
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## | ||
|
||
import numpy as np | ||
from collections import namedtuple as nt | ||
|
||
|
||
from ..optpkg import optional_package | ||
from ..viewers import OrthoSlicer3D | ||
|
||
from numpy.testing.decorators import skipif | ||
from numpy.testing import assert_array_equal, assert_equal | ||
|
||
from nose.tools import assert_raises, assert_true | ||
|
||
matplotlib, has_mpl = optional_package('matplotlib')[:2] | ||
needs_mpl = skipif(not has_mpl, 'These tests need matplotlib') | ||
if has_mpl: | ||
matplotlib.use('Agg') | ||
|
||
|
||
@needs_mpl | ||
def test_viewer(): | ||
# Test viewer | ||
plt = optional_package('matplotlib.pyplot')[0] | ||
a = np.sin(np.linspace(0, np.pi, 20)) | ||
b = np.sin(np.linspace(0, np.pi*5, 30)) | ||
data = (np.outer(a, b)[..., np.newaxis] * a)[:, :, :, np.newaxis] | ||
data = data * np.array([1., 2.]) # give it a # of volumes > 1 | ||
v = OrthoSlicer3D(data) | ||
assert_array_equal(v.position, (0, 0, 0)) | ||
assert_true('OrthoSlicer3D' in repr(v)) | ||
|
||
# fake some events, inside and outside axes | ||
v._on_scroll(nt('event', 'button inaxes key')('up', None, None)) | ||
for ax in (v._axes[0], v._axes[3]): | ||
v._on_scroll(nt('event', 'button inaxes key')('up', ax, None)) | ||
v._on_scroll(nt('event', 'button inaxes key')('up', ax, 'shift')) | ||
# "click" outside axes, then once in each axis, then move without click | ||
v._on_mouse(nt('event', 'xdata ydata inaxes button')(0.5, 0.5, None, 1)) | ||
for ax in v._axes: | ||
v._on_mouse(nt('event', 'xdata ydata inaxes button')(0.5, 0.5, ax, 1)) | ||
v._on_mouse(nt('event', 'xdata ydata inaxes button')(0.5, 0.5, None, None)) | ||
v.set_volume_idx(1) | ||
v.cmap = 'hot' | ||
v.clim = (0, 3) | ||
assert_raises(ValueError, OrthoSlicer3D.clim.fset, v, (0.,)) # bad limits | ||
assert_raises(ValueError, OrthoSlicer3D.cmap.fset, v, 'foo') # wrong cmap | ||
|
||
# decrement/increment volume numbers via keypress | ||
v.set_volume_idx(1) # should just pass | ||
v._on_keypress(nt('event', 'key')('-')) # decrement | ||
assert_equal(v._data_idx[3], 0) | ||
v._on_keypress(nt('event', 'key')('+')) # increment | ||
assert_equal(v._data_idx[3], 1) | ||
v._on_keypress(nt('event', 'key')('-')) | ||
v._on_keypress(nt('event', 'key')('=')) # alternative increment key | ||
assert_equal(v._data_idx[3], 1) | ||
|
||
v.close() | ||
v._draw() # should be safe | ||
|
||
# non-multi-volume | ||
v = OrthoSlicer3D(data[:, :, :, 0]) | ||
v._on_scroll(nt('event', 'button inaxes key')('up', v._axes[0], 'shift')) | ||
v._on_keypress(nt('event', 'key')('escape')) | ||
v.close() | ||
|
||
# complex input should raise a TypeError prior to figure creation | ||
assert_raises(TypeError, OrthoSlicer3D, | ||
data[:, :, :, 0].astype(np.complex64)) | ||
|
||
# other cases | ||
fig, axes = plt.subplots(1, 4) | ||
plt.close(fig) | ||
v1 = OrthoSlicer3D(data, axes=axes) | ||
aff = np.array([[0, 1, 0, 3], [-1, 0, 0, 2], [0, 0, 2, 1], [0, 0, 0, 1]], | ||
float) | ||
v2 = OrthoSlicer3D(data, affine=aff, axes=axes[:3]) | ||
# bad data (not 3+ dim) | ||
assert_raises(ValueError, OrthoSlicer3D, data[:, :, 0, 0]) | ||
# bad affine (not 4x4) | ||
assert_raises(ValueError, OrthoSlicer3D, data, affine=np.eye(3)) | ||
assert_raises(TypeError, v2.link_to, 1) | ||
v2.link_to(v1) | ||
v2.link_to(v1) # shouldn't do anything | ||
v1.close() | ||
v2.close() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment to note error is because of affine not being 4, 4.