Skip to content

Commit

Permalink
add tests and documentation for nltools.prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
ejolly committed Dec 15, 2022
1 parent 4a0bbad commit a610840
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 17 deletions.
48 changes: 47 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================================

Expand Down
13 changes: 7 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import os
import shlex
import time

sys.path.insert(0, os.path.abspath("sphinxext"))
import sphinx_gallery
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand All @@ -330,7 +331,7 @@
(
master_doc,
"nltools",
u"nltools Documentation",
"nltools Documentation",
author,
"nltools",
"One line description of project.",
Expand Down
1 change: 1 addition & 0 deletions nltools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"mask",
"prefs",
"external",
"prefs",
"__version__",
]

Expand Down
12 changes: 2 additions & 10 deletions nltools/prefs.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 11 additions & 0 deletions nltools/tests/test_prefs.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a610840

Please sign in to comment.