-
Notifications
You must be signed in to change notification settings - Fork 262
ENH: Add manual value limits to OrthoSlicer3D/SpatialImages.orthoview #491
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ class OrthoSlicer3D(object): | |
""" | ||
# Skip doctest above b/c not all systems have mpl installed | ||
|
||
def __init__(self, data, affine=None, axes=None, title=None): | ||
def __init__(self, data, affine=None, axes=None, title=None, vlim=None): | ||
""" | ||
Parameters | ||
---------- | ||
|
@@ -61,6 +61,10 @@ def __init__(self, data, affine=None, axes=None, title=None): | |
title : str or None, optional | ||
The title to display. Can be None (default) to display no | ||
title. | ||
vlim : array-like or None, optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of also allowing strings like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That works for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha. I see there's a heuristic for the colorbar around line 205 - is that what you mean? How about throwing that away and just using the data limits as set by
etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the purpose of that heuristic is so that the time-series is guaranteed to fit in the pane, with a slight buffer on top and bottom for visibility. If we set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't that be true for any not-default limits that we set? I mean, don't we need to apply the heuristic for any limits? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I fully understand this comment. The three use-cases I see, myself, are (1) exploration, (2) comparison, (3) figure-generation. I think the existing default behavior is good for (1). I think the proposed changes are good for (2)+(3), where consistency/predictability is more valuable than smart estimates. The problem I see in your proposed change is that you're changing the default behavior to something a little less friendly by setting Apologies if I'm not making much sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure - I agree that the For example - I guess that people will want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @effigies - any comments here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @matthew-brett. Sorry, busy times. To clarify my usage when I was working on this: I would have multiple files with different ranges. By setting However, if what we want is a separate What do you think? |
||
Value limits to display image and time series. Can be None | ||
(default) to derive limits from data. Bounds can be of the | ||
form ``'x%'`` to use the ``x`` percentile of the data. | ||
""" | ||
# Use these late imports of matplotlib so that we have some hope that | ||
# the test functions are the first to set the matplotlib backend. The | ||
|
@@ -79,6 +83,13 @@ def __init__(self, data, affine=None, axes=None, title=None): | |
affine = np.array(affine, float) if affine is not None else np.eye(4) | ||
if affine.shape != (4, 4): | ||
raise ValueError('affine must be a 4x4 matrix') | ||
|
||
if vlim is not None: | ||
percentiles = all(isinstance(lim, str) and lim[-1] == '%' | ||
for lim in vlim) | ||
if percentiles: | ||
vlim = np.percentile(data, [float(lim[:-1]) for lim in vlim]) | ||
|
||
# determine our orientation | ||
self._affine = affine | ||
codes = axcodes2ornt(aff2axcodes(self._affine)) | ||
|
@@ -91,7 +102,7 @@ def __init__(self, data, affine=None, axes=None, title=None): | |
self._volume_dims = data.shape[3:] | ||
self._current_vol_data = data[:, :, :, 0] if data.ndim > 3 else data | ||
self._data = data | ||
self._clim = np.percentile(data, (1., 99.)) | ||
self._clim = np.percentile(data, (1., 99.)) if vlim is None else vlim | ||
del data | ||
|
||
if axes is None: # make the axes | ||
|
@@ -184,8 +195,11 @@ def __init__(self, data, affine=None, axes=None, title=None): | |
ax.set_xticks(np.unique(np.linspace(0, self.n_volumes - 1, | ||
5).astype(int))) | ||
ax.set_xlim(x[0], x[-1]) | ||
yl = [self._data.min(), self._data.max()] | ||
yl = [l + s * np.diff(lims)[0] for l, s in zip(yl, [-1.01, 1.01])] | ||
if vlim is None: | ||
yl = [self._data.min(), self._data.max()] | ||
yl = [l + s * np.diff(lims)[0] for l, s in zip(yl, [-1.01, 1.01])] | ||
else: | ||
yl = vlim | ||
patch = mpl_patch.Rectangle([-0.5, yl[0]], 1., np.diff(yl)[0], | ||
fill=True, facecolor=(0, 1, 0), | ||
edgecolor=(0, 1, 0), alpha=0.25) | ||
|
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.
Copy
vlim
docstring entry from OrthoSlicer3D?