Skip to content

Commit

Permalink
Merge pull request #11 from a3sha2/master
Browse files Browse the repository at this point in the history
step plot for scoreindex
  • Loading branch information
a3sha2 authored Jun 3, 2020
2 parents ea26a6d + 9540ba2 commit 09d1c93
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 7 deletions.
2 changes: 1 addition & 1 deletion aslprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def get_parser():
g_conf.add_argument('--smooth_kernel', action='store', default=5, type=int,
help='smoothing kernel for M0')
g_conf.add_argument(
'--dummy-vols', required=False, action='store', default=None, type=int,
'--dummy-vols', required=False, action='store', default=0, type=int,
help='Number of first n vol to ingnore.')

# ANTs options
Expand Down
6 changes: 3 additions & 3 deletions aslprep/data/reports-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sections:
reportlets:
- bids: {datatype: asl, desc: summary, suffix: asl}
- bids: {datatype: asl, desc: validation, suffix: asl}
- bids: {datatype: asl, desc: fieldmap, suffix: asl}
- bids: {datatype: asl, desc: fieldmap, suffix: bold}
caption: The estimated fieldmap was aligned to the corresponding ASL reference
with a rigid-registration process of the magintude part of the fieldmap,
using <code>antsRegistration</code>.
Expand All @@ -42,12 +42,12 @@ sections:
orders of magnitude above or below the minimum of blue colors.)
static: false
subtitle: Estimated fieldmap and alignment to the corresponding ASL reference
- bids: {datatype: asl, desc: sdc, suffix: asl}
- bids: {datatype: asl, desc: sdc, suffix: bold}
caption: Results of performing susceptibility distortion correction (SDC) on the
ASL
static: false
subtitle: Susceptibility distortion correction
- bids: {datatype: asl, desc: forcedsyn, suffix: asl}
- bids: {datatype: asl, desc: forcedsyn, suffix: bold}
caption: The dataset contained some fieldmap information, but the argument <code>--force-syn</code>
was used. The higher-priority SDC method was used. Here, we show the results
of performing SyN-based SDC on the EPI for comparison.
Expand Down
138 changes: 137 additions & 1 deletion aslprep/niworkflows/viz/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def plot(self, figure=None):

for i, (name, kwargs) in enumerate(self.fd_file.items()):
tseries = kwargs.pop('values')
confoundplot(
confoundplotx(
tseries, grid[grid_id], tr=self.tr, color=palette[i],
name=name, **kwargs)
grid_id += 1
Expand Down Expand Up @@ -673,6 +673,141 @@ def confoundplot(tseries, gs_ts, gs_dist=None, name=None,
'lw': 0, 'alpha': 0.8}
)

# Annotate percentile 95
ax_ts.plot((0, ntsteps - 1), [p95] * 2, linewidth=.1, color='lightgray')
ax_ts.annotate(
'%.2f' % p95, xy=(0, p95), xytext=(-1, 0),
textcoords='offset points', va='center', ha='right',
color='lightgray', size=3)

if cutoff is None:
cutoff = []

for i, thr in enumerate(cutoff):
ax_ts.plot((0, ntsteps - 1), [thr] * 2,
linewidth=.2, color='dimgray')

ax_ts.annotate(
'%.2f' % thr, xy=(0, thr), xytext=(-1, 0),
textcoords='offset points', va='center', ha='right',
color='dimgray', size=3)

ax_ts.plot(tseries, color=color, linewidth=.8)
ax_ts.set_xlim((0, ntsteps - 1))
#ax_ts.step(range(0,ntsteps),tseries,color=color)
#ax_ts.set_xlim((0, ntsteps - 1))
if gs_dist is not None:
ax_dist = plt.subplot(gs_dist)
sns.displot(tseries, vertical=True, ax=ax_dist)
ax_dist.set_xlabel('Timesteps')
ax_dist.set_ylim(ax_ts.get_ylim())
ax_dist.set_yticklabels([])

return [ax_ts, ax_dist], gs
return ax_ts, gs

def confoundplotx(tseries, gs_ts, gs_dist=None, name=None,
units=None, tr=None, hide_x=True, color='b', nskip=0,
cutoff=None, ylims=None):

# Define TR and number of frames
notr = False
if tr is None:
notr = True
tr = 1.
ntsteps = len(tseries)
tseries = np.array(tseries)

# Define nested GridSpec
gs = mgs.GridSpecFromSubplotSpec(1, 2, subplot_spec=gs_ts,
width_ratios=[1, 100], wspace=0.0)

ax_ts = plt.subplot(gs[1])
ax_ts.grid(False)

# Set 10 frame markers in X axis
interval = max((ntsteps // 10, ntsteps // 5, 1))
xticks = list(range(0, ntsteps)[::interval])
ax_ts.set_xticks(xticks)

if not hide_x:
if notr:
ax_ts.set_xlabel('time (frame #)')
else:
ax_ts.set_xlabel('time (s)')
labels = tr * np.array(xticks)
ax_ts.set_xticklabels(['%.02f' % t for t in labels.tolist()])
else:
ax_ts.set_xticklabels([])

if name is not None:
if units is not None:
name += ' [%s]' % units

ax_ts.annotate(
name, xy=(0.0, 0.7), xytext=(0, 0), xycoords='axes fraction',
textcoords='offset points', va='center', ha='left',
color=color, size=8,
bbox={'boxstyle': 'round', 'fc': 'w', 'ec': 'none',
'color': 'none', 'lw': 0, 'alpha': 0.8})

for side in ["top", "right"]:
ax_ts.spines[side].set_color('none')
ax_ts.spines[side].set_visible(False)

if not hide_x:
ax_ts.spines["bottom"].set_position(('outward', 20))
ax_ts.xaxis.set_ticks_position('bottom')
else:
ax_ts.spines["bottom"].set_color('none')
ax_ts.spines["bottom"].set_visible(False)

# ax_ts.spines["left"].set_position(('outward', 30))
ax_ts.spines["left"].set_color('none')
ax_ts.spines["left"].set_visible(False)
# ax_ts.yaxis.set_ticks_position('left')

ax_ts.set_yticks([])
ax_ts.set_yticklabels([])

nonnan = tseries[~np.isnan(tseries)]
if nonnan.size > 0:
# Calculate Y limits
valrange = (nonnan.max() - nonnan.min())
def_ylims = [nonnan.min() - 0.1 * valrange, nonnan.max() + 0.1 * valrange]
if ylims is not None:
if ylims[0] is not None:
def_ylims[0] = min([def_ylims[0], ylims[0]])
if ylims[1] is not None:
def_ylims[1] = max([def_ylims[1], ylims[1]])

# Add space for plot title and mean/SD annotation
def_ylims[0] -= 0.1 * (def_ylims[1] - def_ylims[0])

ax_ts.set_ylim(def_ylims)

# Annotate stats
maxv = nonnan.max()
mean = nonnan.mean()
stdv = nonnan.std()
p95 = np.percentile(nonnan, 95.0)
else:
maxv = 0
mean = 0
stdv = 0
p95 = 0

stats_label = (r'max: {max:.3f}{units} $\bullet$ mean: {mean:.3f}{units} '
r'$\bullet$ $\sigma$: {sigma:.3f}').format(
max=maxv, mean=mean, units=units or '', sigma=stdv)
ax_ts.annotate(
stats_label, xy=(0.98, 0.7), xycoords='axes fraction',
xytext=(0, 0), textcoords='offset points',
va='center', ha='right', color=color, size=4,
bbox={'boxstyle': 'round', 'fc': 'w', 'ec': 'none', 'color': 'none',
'lw': 0, 'alpha': 0.8}
)

# Annotate percentile 95
ax_ts.plot((0, ntsteps - 1), [p95] * 2, linewidth=.1, color='lightgray')
ax_ts.annotate(
Expand Down Expand Up @@ -707,6 +842,7 @@ def confoundplot(tseries, gs_ts, gs_dist=None, name=None,
return ax_ts, gs



def compcor_variance_plot(metadata_files, metadata_sources=None,
output_file=None, varexp_thresh=(0.5, 0.7, 0.9),
fig=None):
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from packaging import version as pver # Avoid distutils.LooseVersion which is deprecated
import sphinx


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath("sphinxext"))
sys.path.insert(0, os.path.abspath("../wrapper"))
sys.path.append(os.path.abspath('../..'))

from github_link import make_linkcode_resolve

Expand Down Expand Up @@ -54,13 +54,15 @@
"numpy",
"nitime",
"matplotlib",
"aslprep"
]

if pver.parse(sphinxversion) >= pver.parse("1.7.0"):
autodoc_mock_imports += [
"pandas",
"nilearn",
"seaborn",
"aslprep"
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
5 changes: 4 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. fmriprep documentation master file, created by
.. aslprep documentation master file, created by
sphinx-quickstart on Mon May 9 09:04:25 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Expand All @@ -11,6 +11,9 @@
Contents
--------

.. automodule:: aslprep
:members:

.. toctree::
:maxdepth: 3

Expand Down

0 comments on commit 09d1c93

Please sign in to comment.