-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Australian-Imaging-Service/openneuro-download
Openneuro download
- Loading branch information
Showing
20 changed files
with
131 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...dicom/mri/dwi/siemens/skyra/syngo_d13c.py → ...dicom/mri/dwi/siemens/skyra/syngo_d13c.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ap/ge/discovery_mr888/dv26_0_r05_2008a.py → ...ap/ge/discovery_mr888/dv26_0_r05_2008a.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...icom/mri/fmap/siemens/skyra/syngo_d13c.py → ...icom/mri/fmap/siemens/skyra/syngo_d13c.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...dicom/mri/t1w/siemens/skyra/syngo_d13c.py → ...dicom/mri/t1w/siemens/skyra/syngo_d13c.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from medimages4tests import base_cache_dir | ||
from medimages4tests.utils import retrieve_from_openneuro, OpenneuroSpec | ||
|
||
|
||
cache_dir = base_cache_dir / "mri" / "neuro" / "t1w" | ||
|
||
|
||
SAMPLES = { | ||
"ds004130-ON01016": OpenneuroSpec( | ||
dataset="ds004130", | ||
tag="1.0.0", | ||
path="sub-ON01016/anat/sub-ON01016_acq-fspgr_run-01_T1w", | ||
) | ||
} | ||
|
||
|
||
def get_image(sample="ds004130-ON01016"): | ||
return retrieve_from_openneuro(SAMPLES[sample], cache_dir / sample) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from tempfile import mkdtemp | ||
import shutil | ||
from pathlib import Path | ||
import openneuro | ||
import attrs | ||
|
||
|
||
@attrs.define | ||
class OpenneuroSpec: | ||
|
||
dataset: str | ||
tag: str | ||
path: Path | ||
|
||
|
||
def retrieve_from_openneuro( | ||
sample, cache_path, suffixes=(".nii.gz", ".json"), force_download=False | ||
): | ||
if not cache_path.parent.exists(): | ||
cache_path.parent.mkdir(parents=True) | ||
out_path = cache_path.with_suffix(suffixes[0]) | ||
if not out_path.exists() or force_download: | ||
tmpdir = Path(mkdtemp()) | ||
openneuro.download( | ||
dataset=sample.dataset, | ||
tag=sample.tag, | ||
target_dir=tmpdir, | ||
include=[sample.path], | ||
) | ||
for ext in suffixes: | ||
shutil.copyfile( | ||
(tmpdir / sample.path).with_suffix(ext), cache_path.with_suffix(ext) | ||
) | ||
return out_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import nibabel as nb | ||
from medimages4tests.mri.neuro.t1w import get_image | ||
|
||
|
||
def test_openneuro_retrieve(): | ||
|
||
nifti_fpath = get_image() | ||
|
||
nifti = nb.load(nifti_fpath) | ||
|
||
assert nifti.shape == (204, 256, 256) |