Skip to content

Commit 62bce40

Browse files
committed
WIP
1 parent bf54667 commit 62bce40

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

nibabel/spatialimages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,4 +677,4 @@ def plot(self):
677677
consider using viewer.show() (equivalently plt.show()) to show
678678
the figure.
679679
"""
680-
return OrthoSlicer3D(self.get_data())
680+
return OrthoSlicer3D(self.get_data(), self.get_affine())

nibabel/viewers.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99

1010
from .optpkg import optional_package
11+
from .orientations import aff2axcodes, axcodes2ornt
1112

1213
plt, _, _ = optional_package('matplotlib.pyplot')
1314
mpl_img, _, _ = optional_package('matplotlib.image')
@@ -33,41 +34,40 @@ class OrthoSlicer3D(object):
3334
>>> OrthoSlicer3D(data).show() # doctest: +SKIP
3435
"""
3536
# Skip doctest above b/c not all systems have mpl installed
36-
def __init__(self, data, axes=None, aspect_ratio=(1, 1, 1), affine=None,
37-
cmap='gray', pcnt_range=(1., 99.), figsize=(8, 8)):
37+
def __init__(self, data, affine=None, axes=None, cmap='gray',
38+
pcnt_range=(1., 99.), figsize=(8, 8)):
3839
"""
3940
Parameters
4041
----------
4142
data : ndarray
4243
The data that will be displayed by the slicer. Should have 3+
4344
dimensions.
44-
axes : tuple of mpl.Axes | None, optional
45-
3 or 4 axes instances for the X, Y, Z slices plus volumes,
46-
or None (default).
47-
aspect_ratio : array-like, optional
48-
Stretch factors for X, Y, Z directions.
4945
affine : array-like | None
5046
Affine transform for the data. This is used to determine
5147
how the data should be sliced for plotting into the X, Y,
52-
and Z view axes. If None, identity is assumed.
48+
and Z view axes. If None, identity is assumed. The aspect
49+
ratio of the data are inferred from the affine transform.
50+
axes : tuple of mpl.Axes | None, optional
51+
3 or 4 axes instances for the X, Y, Z slices plus volumes,
52+
or None (default).
5353
cmap : str | instance of cmap, optional
5454
String or cmap instance specifying colormap.
5555
pcnt_range : array-like, optional
5656
Percentile range over which to scale image for display.
5757
figsize : tuple
5858
Figure size (in inches) to use if axes are None.
5959
"""
60-
ar = np.array(aspect_ratio, float)
61-
if ar.shape != (3,) or np.any(ar <= 0):
62-
raise ValueError('aspect ratio must have exactly 3 elements >= 0')
63-
aspect_ratio = dict(x=ar[0], y=ar[1], z=ar[2])
6460
data = np.asanyarray(data)
6561
if data.ndim < 3:
6662
raise ValueError('data must have at least 3 dimensions')
6763
affine = np.array(affine, float) if affine is not None else np.eye(4)
6864
if affine.ndim != 2 or affine.shape != (4, 4):
6965
raise ValueError('affine must be a 4x4 matrix')
70-
self._affine = affine
66+
self._affine = affine.copy()
67+
self._codes = axcodes2ornt(aff2axcodes(self._affine)) # XXX USE FOR ORDERING
68+
print(self._codes)
69+
self._scalers = np.abs(self._affine).max(axis=0)[:3]
70+
self._inv_affine = np.linalg.inv(affine)
7171
self._volume_dims = data.shape[3:]
7272
self._current_vol_data = data[:, :, :, 0] if data.ndim > 3 else data
7373
self._data = data
@@ -122,7 +122,7 @@ def __init__(self, data, axes=None, aspect_ratio=(1, 1, 1), affine=None,
122122

123123
# set up axis crosshairs
124124
self._crosshairs = dict()
125-
for type_, i_1, i_2 in zip('zyx', 'xxy', 'yzz'):
125+
for type_, i_1, i_2 in zip('xyz', 'yxx', 'zzy'):
126126
ax, label = self._axes[type_], labels[type_]
127127
vert = ax.plot([self._idx[i_1]] * 2,
128128
[-0.5, self._sizes[i_2] - 0.5],
@@ -145,7 +145,7 @@ def __init__(self, data, axes=None, aspect_ratio=(1, 1, 1), affine=None,
145145
horizontalalignment=anchor[0],
146146
verticalalignment=anchor[1])
147147
ax.axis(lims)
148-
ax.set_aspect(aspect_ratio[type_])
148+
# ax.set_aspect(aspect_ratio[type_]) # XXX FIX
149149
ax.patch.set_visible(False)
150150
ax.set_frame_on(False)
151151
ax.axes.get_yaxis().set_visible(False)
@@ -206,7 +206,7 @@ def n_volumes(self):
206206
"""Number of volumes in the data"""
207207
return int(np.prod(self._volume_dims))
208208

209-
def set_indices(self, x=None, y=None, z=None, v=None):
209+
def set_position(self, x=None, y=None, z=None, v=None):
210210
"""Set current displayed slice indices
211211
212212
Parameters

0 commit comments

Comments
 (0)