Skip to content

Commit

Permalink
FIX add downloaded subjects to the cortex database (#413)
Browse files Browse the repository at this point in the history
* FIX add downloaded subjects to the cortex database

* ENH add reload_subjects method
  • Loading branch information
TomDLT authored Dec 16, 2021
1 parent dd543a3 commit 94c1067
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cortex/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def subjects(self):
self._subjects = dict([(sname, SubjectDB(sname, filestore=self.filestore)) for sname in subjs])
return self._subjects

def reload_subjects(self):
"""Force the reload of the subject dictionary."""
self._subjects = None
self.subjects

def get_anat(self, subject, type='raw', xfmname=None, recache=False, order=1, **kwargs):
"""Return anatomical information from the filestore. Anatomical information is defined as
any volume-space anatomical information pertaining to the subject, such as T1 image,
Expand Down
12 changes: 12 additions & 0 deletions cortex/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import cortex

def test_download_subject():
# Test that newly downloaded subjects are added to the current database.

# remove fsaverage from the list of available subjects if present.
if "fsaverage" in cortex.db.subjects:
cortex.db._subjects.pop("fsaverage")

assert "fsaverage" not in cortex.db.subjects
cortex.utils.download_subject(subject_id='fsaverage')
assert "fsaverage" in cortex.db.subjects
9 changes: 6 additions & 3 deletions cortex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def download_subject(subject_id='fsaverage', url=None, pycortex_store=None,
to add more in the future. If provided, URL overrides `subject_id`
pycortex_store : string or None
Directory to which to put the new subject folder. If None, defaults to
the `filestore` variable specified in the pycortex config file.
current filestore in use (`cortex.db.filestore`).
download_again : bool
Download the data again even if the subject id is already present in
the pycortex's database.
Expand All @@ -1030,13 +1030,16 @@ def download_subject(subject_id='fsaverage', url=None, pycortex_store=None,
print('Downloaded subject {} to {}'.format(subject_id, tmp_dir))
# Un-tar to pycortex store
if pycortex_store is None:
# Default location is config file pycortex store.
pycortex_store = config.get('basic', 'filestore')
# Default location is current filestore in cortex.db
pycortex_store = db.filestore
pycortex_store = os.path.expanduser(pycortex_store)
with tarfile.open(os.path.join(tmp_dir, subject_id + '.tar.gz'), "r:gz") as tar:
print("Extracting subject {} to {}".format(subject_id, pycortex_store))
tar.extractall(path=pycortex_store)

# reload all subjects from the filestore
db.reload_subjects()


def rotate_flatmap(surf_id, theta, plot=False):
"""Rotate flatmap to be less V-shaped
Expand Down

0 comments on commit 94c1067

Please # to comment.