diff --git a/docs/api.rst b/docs/api.rst index 206cb2ed..74859dfb 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -63,12 +63,58 @@ methods in the current release of Neurolearn. .. automodule:: nltools.file_reader :members: -:mod:`nltools.util`: Utilities +:mod:`nltools.utils`: Utilities ============================== .. automodule:: nltools.utils :members: +:mod:`nltools.prefs`: Preferences +================================ + +This module can be used to adjust the default MNI template settings that are used +internally by all `Brain_Data` operations. By default all operations are performed in +**MNI152 2mm space**. Thus any files loaded with be resampled to this space by default.You can control this on a per-file loading basis using the `mask` argument of `Brain_Data`, e.g. + +.. code-block:: + + from nltools.data import Brain_Data + + # my_brain will be resampled to 2mm + brain = Brain_Data('my_brain.nii.gz') + + # my_brain will now be resampled to the same space as my_mask + brain = Brain_Data('my_brain.nii.gz', mask='my_mask.nii.gz') # will be resampled + +Alternatively this module can be used to switch between 2mm or 3mm MNI spaces with and without ventricles: + +.. code-block:: + + from nltools.prefs import MNI_Template, resolve_mni_path + from nltools.data import Brain_Data + + MNI_Template['resolution'] = '3mm' + + # my_brain will be resampled to 3mm and future operation will be in 3mm space + brain = Brain_Data('my_brain.nii.gz') + + # get the template nifti files + resolve_mni_path(MNI_Template) + + # will print like: + { + 'resolution': '3mm', + 'mask_type': 'with_ventricles', + 'mask': '/Users/Esh/Documents/pypackages/nltools/nltools/resources/MNI152_T1_3mm_brain_mask.nii.gz', + 'plot': '/Users/Esh/Documents/pypackages/nltools/nltools/resources/MNI152_T1_3mm.nii.gz', + 'brain': + '/Users/Esh/Documents/pypackages/nltools/nltools/resources/MNI152_T1_3mm_brain.nii.gz' + } + +.. automodule:: nltools.prefs + :members: + :show-inheritance: + :mod:`nltools.plotting`: Plotting Tools ======================================= diff --git a/docs/conf.py b/docs/conf.py index b90f0ef2..200b6499 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,7 @@ import sys import os import shlex +import time sys.path.insert(0, os.path.abspath("sphinxext")) import sphinx_gallery @@ -76,9 +77,9 @@ master_doc = "index" # General information about the project. -project = u"nltools" -copyright = u"2020, Cosan Laboratory" -author = u"Cosan Laboratory" +project = "nltools" +copyright = f"{time.strftime('%Y')}, Cosan Laboratory" +author = "Cosan Laboratory" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -169,7 +170,7 @@ "bootstrap_version": "3", "globaltoc_includehidden": "true", "source_link_position": "footer", - "globaltoc_depth": 1, + "globaltoc_depth": 2, "navbar_pagenav_name": "TOC", "navbar_links": [ ("Installation", "install"), @@ -315,7 +316,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "nltools", u"nltools Documentation", [author], 1)] +man_pages = [(master_doc, "nltools", "nltools Documentation", [author], 1)] # If true, show URL addresses after external links. # man_show_urls = False @@ -330,7 +331,7 @@ ( master_doc, "nltools", - u"nltools Documentation", + "nltools Documentation", author, "nltools", "One line description of project.", diff --git a/nltools/__init__.py b/nltools/__init__.py index 4be0a1b7..acf5af8d 100644 --- a/nltools/__init__.py +++ b/nltools/__init__.py @@ -10,6 +10,7 @@ "mask", "prefs", "external", + "prefs", "__version__", ] diff --git a/nltools/prefs.py b/nltools/prefs.py index 6d1b2034..79b490b6 100644 --- a/nltools/prefs.py +++ b/nltools/prefs.py @@ -1,16 +1,8 @@ -""" -NeuroLearn Preferences -====================== - - -""" -__all__ = ["MNI_Template", "resolve_mni_path"] -__author__ = ["Luke Chang"] -__license__ = "MIT" - import os from nltools.utils import get_resource_path +__all__ = ["MNI_Template", "resolve_mni_path"] + MNI_Template = dict( resolution="2mm", mask_type="with_ventricles", diff --git a/nltools/tests/test_prefs.py b/nltools/tests/test_prefs.py new file mode 100644 index 00000000..197b6c50 --- /dev/null +++ b/nltools/tests/test_prefs.py @@ -0,0 +1,11 @@ +from nltools.prefs import MNI_Template +from nltools.data import Brain_Data + + +def test_change_mni_resolution(): + assert MNI_Template["resolution"] == "2mm" + brain = Brain_Data() + assert brain.mask.affine[1, 1] == 2.0 + MNI_Template["resolution"] = "3mm" + new_brain = Brain_Data() + assert new_brain.mask.affine[1, 1] == 3.0