diff --git a/api/common/data_handlers/compounds/download.py b/api/common/data_handlers/compounds/download.py index 088b9ac..dc6b285 100644 --- a/api/common/data_handlers/compounds/download.py +++ b/api/common/data_handlers/compounds/download.py @@ -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 @@ -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: @@ -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: diff --git a/api/server/compounds/download.py b/api/server/compounds/download.py index b70cffd..74dfb09 100644 --- a/api/server/compounds/download.py +++ b/api/server/compounds/download.py @@ -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: diff --git a/requirements/siibra.txt b/requirements/siibra.txt index 3823163..8e64888 100644 --- a/requirements/siibra.txt +++ b/requirements/siibra.txt @@ -1,2 +1,2 @@ -siibra==0.4a78 +siibra==0.4a80 plotly