Skip to content

Commit

Permalink
feat: allow download of big brain voi
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed Jul 1, 2024
1 parent 2614def commit 4f136ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 18 additions & 2 deletions api/common/data_handlers/compounds/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from uuid import uuid4
from pathlib import Path
from datetime import datetime
import json
import math

BIGBRAIN_ID = "minds/core/referencespace/v1.0.0/a1655b99-82f1-420f-a3c2-fe80fd4c8588"
BIGBRAIN_SIZE_LIMIT = 2 * 1024 * 1024

README = """# Packaged Atlas Data
Expand Down Expand Up @@ -40,7 +45,7 @@
LICENSE = """Please check the respective citations regarding licenses to use these data."""

@data_decorator(ROLE)
def download_all(space_id: str, parcellation_id: str, region_id: str=None, feature_id: str=None) -> str:
def download_all(space_id: str, parcellation_id: str, region_id: str=None, feature_id: str=None, bbox=None) -> str:
"""Create a download bundle (zip) for the provided specification
Args:
Expand Down Expand Up @@ -101,7 +106,18 @@ def write_desc(filename, obj, **kwargs):
space_filename = f"{space.key}.nii.gz"

# this should fetch anything (surface, nifti, ng precomputed)
space_vol = space.get_template().fetch()
if space.id == BIGBRAIN_ID:
if bbox:
bounding_box = space.get_bounding_box(*json.loads(bbox))
value = BIGBRAIN_SIZE_LIMIT
for dim in bounding_box.maxpoint - bounding_box.minpoint:
value /= dim
cube_rooted = math.pow(value, 1/3)
space_vol = space.get_template().fetch(voi=bounding_box, resolution_mm=1/cube_rooted)
else:
raise RuntimeError(f"For big brain, bbox must be defined.")
else:
space_vol = space.get_template().fetch()
zipfile.writestr(space_filename, gzip.compress(space_vol.to_bytes()))
write_desc(f'{space_filename}.info.md', space)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions api/server/compounds/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def cleanup(filepath: Path):
@router.get("")
@version(*FASTAPI_VERSION)
@router_decorator(ROLE, func=download_all, queue_as_async=(ROLE=="server"))
def get_download_bundle(space_id: str, parcellation_id: str, region_id: str=None, feature_id: str=None, *, background: BackgroundTasks, func):
def get_download_bundle(space_id: str, parcellation_id: str, bbox=None, region_id: str=None, feature_id: str=None, *, background: BackgroundTasks, func):
"""Prepare the bundle. Given a specification, prepare/bundle according to the specification."""
returnval = func(space_id=space_id, parcellation_id=parcellation_id, region_id=region_id, feature_id=feature_id)
returnval = func(space_id=space_id, parcellation_id=parcellation_id, bbox=bbox, region_id=region_id, feature_id=feature_id)
try:
path_to_file = Path(returnval)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion requirements/siibra.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
siibra==0.4a78
siibra==0.4a80
plotly

0 comments on commit 4f136ca

Please sign in to comment.