Skip to content

Commit

Permalink
Merge pull request #635 from oesteban/fix/0.9.7-hotfixes
Browse files Browse the repository at this point in the history
[ENH] Hotfixes to 0.9.7
  • Loading branch information
oesteban committed Aug 28, 2017
2 parents 5fa37d9 + c8cd13f commit f510166
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .circleci/check_iqms.sh
Expand Up @@ -29,4 +29,4 @@ docker run -i -v $SCRATCH:/scratch -w /scratch \
--entrypoint="dfcheck" \
${DOCKER_IMAGE}:${DOCKER_TAG} \
-i /scratch/out/${MODALITY}.csv \
-r /root/src/mriqc/mriqc/data/testdata/${MODALITY}.csv
-r /usr/local/src/mriqc/mriqc/data/testdata/${MODALITY}.csv
4 changes: 2 additions & 2 deletions .circleci/participant.sh
Expand Up @@ -17,7 +17,7 @@ fi
exit_docs=0
if [ "$CIRCLE_NODE_INDEX" == "1" ]; then
mkdir -p ${SCRATCH}/docs
docker run -i --rm=false -v ${SCRATCH}:/scratch -w /root/src/mriqc/docs \
docker run -i --rm=false -v ${SCRATCH}:/scratch -w /usr/local/src/mriqc/docs \
--entrypoint=sphinx-build poldracklab/mriqc:latest -T -E -W -D language=en -b html source/ /scratch/docs 2>&1 \
| tee ${SCRATCH}/docs/builddocs.log
exit_docs=$( grep -qi "build succeeded." ${SCRATCH}/docs/builddocs.log; echo $? )
Expand Down Expand Up @@ -46,7 +46,7 @@ case $CIRCLE_NODE_INDEX in
--entrypoint="py.test" ${DOCKER_IMAGE}:${DOCKER_TAG} \
--ignore=src/ \
--junitxml=/scratch/tests.xml \
/root/src/mriqc && \
/usr/local/src/mriqc && \
${DOCKER_RUN} -m bold --testing --ica
exit $(( $? + $exit_docs ))
;;
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Expand Up @@ -101,9 +101,9 @@ ENV MKL_NUM_THREADS=1 \
OMP_NUM_THREADS=1

# Installing dev requirements (packages that are not in pypi)
WORKDIR /usr/local/src/mriqc
COPY requirements.txt requirements.txt
RUN pip uninstall -y scikit-learn && \
pip install -r requirements.txt && \
RUN pip install -r requirements.txt && \
rm -rf ~/.cache/pip

# Precaching atlases after niworkflows is available
Expand All @@ -112,10 +112,9 @@ ENV CRN_SHARED_DATA /niworkflows_data
RUN python -c 'from niworkflows.data.getters import get_mni_icbm152_nlin_asym_09c; get_mni_icbm152_nlin_asym_09c()'

# Installing MRIQC
COPY . /root/src/mriqc
COPY . /usr/local/src/mriqc
ARG VERSION
RUN cd /root/src/mriqc && \
echo "${VERSION}" > mriqc/VERSION && \
RUN echo "${VERSION}" > mriqc/VERSION && \
pip install .[all] && \
rm -rf ~/.cache/pip

Expand Down
10 changes: 4 additions & 6 deletions mriqc/__about__.py
Expand Up @@ -54,6 +54,7 @@
'numpy>=1.12.0',
'niworkflows>=0.1.4',
'pybids>=0.3.0',
'scikit-learn>=0.19.0',
'future',
'scipy',
'six',
Expand All @@ -72,11 +73,8 @@
'versioneer',
]

LINKS_REQUIRES = [
'https://github.com/scikit-learn/scikit-learn/tarball/master#scikit-learn-0.19.0-dev',
'https://github.com/poldracklab/niworkflows.git'
'@0a71b0f16acec10520b6eb824649d19519e65b59#egg=niworkflows-0.1.5-dev',
]
LINKS_REQUIRES = []


TESTS_REQUIRES = [
'mock',
Expand All @@ -89,7 +87,7 @@
'tests': TESTS_REQUIRES,
'duecredit': ['duecredit'],
'notebooks': ['ipython', 'jupyter'],
'classifier': ['scikit-learn', 'xgboost']
'classifier': ['xgboost']
}

# Enable a handle to install all extra dependencies at once
Expand Down
42 changes: 24 additions & 18 deletions mriqc/qc/anatomical.py
Expand Up @@ -196,10 +196,11 @@
from builtins import zip, range, str, bytes # pylint: disable=W0622
from six import string_types

DIETRICH_FACTOR = 1.0 / sqrt(2/(4 - pi))
DIETRICH_FACTOR = 1.0 / sqrt(2 / (4 - pi))
FSL_FAST_LABELS = {'csf': 1, 'gm': 2, 'wm': 3, 'bg': 0}
PY3 = version_info[0] > 2


def snr(mu_fg, sigma_fg, n):
r"""
Calculate the :abbr:`SNR (Signal-to-Noise Ratio)`.
Expand All @@ -213,16 +214,16 @@ def snr(mu_fg, sigma_fg, n):
where :math:`\mu_F` is the mean intensity of the foreground and
:math:`\sigma_F` is the standard deviation of the same region.
:param numpy.ndarray img: input data
:param numpy.ndarray fgmask: input foreground mask or segmentation
:param bool erode: erode masks before computations.
:param str fglabel: foreground label in the segmentation data.
:param float mu_fg: mean of foreground.
:param float sigma_fg: standard deviation of foreground.
:param int n: number of voxels in foreground mask.
:return: the computed SNR for the foreground segmentation
:return: the computed SNR
"""
return float(mu_fg / (sigma_fg * sqrt(n / (n - 1))))


def snr_dietrich(mu_fg, sigma_air):
r"""
Calculate the :abbr:`SNR (Signal-to-Noise Ratio)`.
Expand All @@ -237,11 +238,8 @@ def snr_dietrich(mu_fg, sigma_air):
\text{SNR} = \frac{\mu_F}{\sqrt{\frac{2}{4-\pi}}\,\sigma_\text{air}}.
:param numpy.ndarray img: input data
:param numpy.ndarray smask: input foreground mask or segmentation
:param numpy.ndarray airmask: input background mask or segmentation
:param bool erode: erode masks before computations.
:param str fglabel: foreground label in the segmentation data.
:param float mu_fg: mean of foreground.
:param float sigma_air: standard deviation of the air surrounding the head ("hat" mask).
:return: the computed SNR for the foreground segmentation
Expand All @@ -253,6 +251,7 @@ def snr_dietrich(mu_fg, sigma_air):

return float(DIETRICH_FACTOR * mu_fg / sigma_air)


def cnr(mu_wm, mu_gm, sigma_air):
r"""
Calculate the :abbr:`CNR (Contrast-to-Noise Ratio)` [Magnota2006]_.
Expand All @@ -267,8 +266,10 @@ def cnr(mu_wm, mu_gm, sigma_air):
the air (background) mask.
:param numpy.ndarray img: input data
:param numpy.ndarray seg: input segmentation
:param float mu_wm: mean of signal within white-matter mask.
:param float mu_gm: mean of signal within gray-matter mask.
:param float sigma_air: standard deviation of the air surrounding the head ("hat" mask).
:return: the computed CNR
"""
Expand All @@ -287,9 +288,11 @@ def cjv(mu_wm, mu_gm, sigma_wm, sigma_gm):
\text{CJV} = \frac{\sigma_\text{WM} + \sigma_\text{GM}}{|\mu_\text{WM} - \mu_\text{GM}|}.
:param numpy.ndarray img: the input data
:param numpy.ndarray wmmask: the white matter mask
:param numpy.ndarray gmmask: the gray matter mask
:param float mu_wm: mean of signal within white-matter mask.
:param float mu_gm: mean of signal within gray-matter mask.
:param float sigma_wm: standard deviation of signal within white-matter mask.
:param float sigma_gm: standard deviation of signal within gray-matter mask.
:return: the computed CJV
Expand All @@ -309,7 +312,9 @@ def fber(img, headmask, rotmask=None):
:param numpy.ndarray img: input data
:param numpy.ndarray seg: input segmentation
:param numpy.ndarray headmask: a mask of the head (including skull, skin, etc.)
:param numpy.ndarray rotmask: a mask of empty voxels inserted after a rotation of
data
"""

Expand All @@ -325,7 +330,6 @@ def fber(img, headmask, rotmask=None):
return float(fg_mu / bg_mu)



def efc(img, framemask=None):
r"""
Calculate the :abbr:`EFC (Entropy Focus Criterion)` [Atkinson1997]_.
Expand All @@ -348,6 +352,8 @@ def efc(img, framemask=None):
\text{EFC} = \left( \frac{N}{\sqrt{N}} \, \log{\sqrt{N}^{-1}} \right) \text{E}
:param numpy.ndarray img: input data
:param numpy.ndarray framemask: a mask of empty voxels inserted after a rotation of
data
"""

Expand Down
24 changes: 13 additions & 11 deletions mriqc/viz/fmriplots.py
Expand Up @@ -17,7 +17,11 @@
from .utils import DINA4_LANDSCAPE
sns.set_style("whitegrid")


class fMRIPlot(object):
"""
Generates the fMRI Summary Plot
"""

def __init__(self, func, mask, seg=None, tr=None,
title=None, figsize=DINA4_LANDSCAPE):
Expand Down Expand Up @@ -124,8 +128,8 @@ def fmricarpetplot(func_data, segmentation, outer_gs, tr=None, nskip=0):
ax0.set_xticks([])

colors1 = plt.cm.summer(np.linspace(0., 1., len(cort_gm)))
colors2 = plt.cm.autumn(np.linspace(0., 1., len(deep_gm) + 1))[::-1,...]
colors3 = plt.cm.winter(np.linspace(0., .5, len(wm_csf)))[::-1,...]
colors2 = plt.cm.autumn(np.linspace(0., 1., len(deep_gm) + 1))[::-1, ...]
colors3 = plt.cm.winter(np.linspace(0., .5, len(wm_csf)))[::-1, ...]
cmap = LinearSegmentedColormap.from_list('my_colormap', np.vstack((colors1, colors2, colors3)))

ax0.imshow(newsegm[order, np.newaxis], interpolation='nearest', aspect='auto',
Expand All @@ -151,9 +155,8 @@ def fmricarpetplot(func_data, segmentation, outer_gs, tr=None, nskip=0):
ax1.set_yticklabels([])

# Set 10 frame markers in X axis
interval = int(data.shape[-1] + 1) // 10
xticks = list(
range(0, data.shape[-1])[::interval]) + [data.shape[-1]-1]
interval = max((int(data.shape[-1] + 1) // 10, int(data.shape[-1] + 1) // 5, 1))
xticks = list(range(0, data.shape[-1])[::interval])
ax1.set_xticks(xticks)

if notr:
Expand Down Expand Up @@ -195,7 +198,7 @@ def spikesplot(ts_z, outer_gs=None, tr=None, zscored=True, spike_thresh=6., titl
if ax is None:
ax = plt.gca()

if not outer_gs is None:
if outer_gs is not None:
gs = mgs.GridSpecFromSubplotSpec(1, 2, subplot_spec=outer_gs,
width_ratios=[1, 100], wspace=0.0)
ax = plt.subplot(gs[1])
Expand Down Expand Up @@ -279,7 +282,6 @@ def spikesplot(ts_z, outer_gs=None, tr=None, zscored=True, spike_thresh=6., titl
ax.plot((0, ntsteps - 1), (yticks[0], yticks[0]), 'k:')
ax.plot((0, ntsteps - 1), (yticks[-1], yticks[-1]), 'k:')


for side in ["top", "right"]:
ax.spines[side].set_color('none')
ax.spines[side].set_visible(False)
Expand Down Expand Up @@ -343,8 +345,8 @@ def confoundplot(tseries, gs_ts, gs_dist=None, name=None, normalize=True,
ax_ts.set_xlim((0, ntsteps - 1))

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

if not hide_x:
Expand All @@ -358,9 +360,9 @@ def confoundplot(tseries, gs_ts, gs_dist=None, name=None, normalize=True,
ax_ts.set_xticklabels([])

no_scale = notr or not normalize
if not name is None:
if name is not None:
var_label = name
if not units is None:
if units is not None:
var_label += (' [{}]' if no_scale else ' [{}/s]').format(units)
ax_ts.set_ylabel(var_label)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
@@ -1,3 +1,3 @@
numpy>=1.12.0
git+https://github.com/poldracklab/niworkflows.git@0a71b0f16acec10520b6eb824649d19519e65b59#egg=niworkflows-0.1.5-dev
git+https://github.com/scikit-learn/scikit-learn.git@master#egg=scikit-learn-0.19.0-dev
niworkflows>=0.1.6
scikit-learn>=0.19

0 comments on commit f510166

Please sign in to comment.