Skip to content

Commit

Permalink
Merge pull request #7 from individual-brain-charting/fetch_mask
Browse files Browse the repository at this point in the history
Downloading mask files on public_analysis_code
  • Loading branch information
man-shu authored Sep 22, 2023
2 parents 4cc5015 + 4783e5b commit 2f6af28
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/ibc_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ def _create_root_dir(dir_path=None):
return dir_path


def download_gm_mask(resolution=1.5, save_to=None):
"""Download the grey matter mask
Parameters
----------
resolution : float, optional
resolution of the mask, by default 1.5
save_to : str, optional
where to save the mask, by default None
Returns
-------
save_as : str
path to the downloaded mask
"""

if resolution == 1.5:
mask = "gm_mask_1_5mm.nii.gz"
else:
mask = "gm_mask_3mm.nii.gz"

remote_file = "https://api.github.com/repos/individual-brain-charting/public_analysis_code/contents/ibc_data"
remote_file = os.path.join(remote_file, mask)
# save the database file
save_to = _create_root_dir(save_to)
save_as = os.path.join(save_to, mask)

# use curl with github api to download the file
os.system(
f"curl -s -S -L -H 'Accept: application/vnd.github.v4.raw' -H 'X-GitHub-Api-Version: 2022-11-28' {remote_file} -o '{save_as}'"
)

return save_as


def get_info(data_type="volume_maps", save_to=None, metadata=METADATA):
"""Fetch a csv file describing each file in a given IBC dataset on EBRAINS.
Expand Down

0 comments on commit 2f6af28

Please sign in to comment.