.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_examples_quickflat_plot_thickness_nanmean.py:
===================================
Ignore NaN (not-a-number) values in thickness mapping
===================================
By default, pycortex quickshow averages across the thickness of the cortex
for each pixel in the resulting flatmap. If any of these layers contain a value
of NaN (not-a-number), then the result of the average will also be Nan. This
behavior might be undesirable. To avoid it, pass the argument `nanmean=True` to
`cortex.quickshow` (or `cortex.quickflat.make_figure`). This will only take the
mean of the non-NaN values when averaging across the thickness of cortex. A
pixel will only have the value NaN if every voxel between pia and white matter
has the value NaN.
.. rst-class:: sphx-glr-horizontal
*
.. image:: /auto_examples/quickflat/images/sphx_glr_plot_thickness_nanmean_001.png
:alt: plot thickness nanmean
:class: sphx-glr-multi-img
*
.. image:: /auto_examples/quickflat/images/sphx_glr_plot_thickness_nanmean_002.png
:alt: plot thickness nanmean
:class: sphx-glr-multi-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/home/travis/build/gallantlab/pycortex/cortex/quickflat/utils.py:93: RuntimeWarning: invalid value encountered in true_divide
nanmean_data = nonnan_sum / weights_on_nonnan
|
.. code-block:: default
import cortex
import numpy as np
from matplotlib import pyplot as plt
# create dataset with volume of all 1's
vol = cortex.Volume.empty('S1', 'fullhead', vmin=0, vmax=2) + 1
# set 20% of the values in the dataset to NaN
vol.data[np.random.rand(*vol.data.shape) > 0.8] = np.nan
# plot the volume with nanmean=False
# here a nan in ANY layer of the thickness mapping will result in a nan
# in the final image
# so this image should have many, many holes that show curvature
# and all the non-hole points should have value of 1
_ = cortex.quickshow(vol, nanmean=False, with_curvature=True)
plt.show()
# plot the volume with nanmean=True
# here there should only be a nan in the final image if EVERY layer of the
# thickness mapping has a nan for the given pixel
# so this image should have many fewer holes that show curvature
# and, again, all the non-hole points should have value of 1
_ = cortex.quickshow(vol, nanmean=True, with_curvature=True)
plt.show()
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 4.669 seconds)
.. _sphx_glr_download_auto_examples_quickflat_plot_thickness_nanmean.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_thickness_nanmean.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_thickness_nanmean.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_