Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

FIX add downloaded subjects to the cortex database #413

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

# force filestore reload
db._subjects = None
TomDLT marked this conversation as resolved.
Show resolved Hide resolved


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