Skip to content

Commit

Permalink
fix: default arg for extra spec
Browse files Browse the repository at this point in the history
fix: allow sparsemap serialization
  • Loading branch information
xgui3783 committed Aug 26, 2024
1 parent e0c4ab6 commit 72cfc73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions api/server/volumes/parcellationmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_parcellation_labelled_map(parcellation_id: str, space_id: str, region_id
""")
@version(*FASTAPI_VERSION)
@router_decorator(ROLE, func=statistical_map_nii_gz)
def get_region_statistical_map(parcellation_id: str, space_id: str, region_id: str, *, func):
def get_region_statistical_map(parcellation_id: str, space_id: str, region_id: str, extra_spec: str="", *, func):
"""Get statistical map according to specification"""
if func is None:
raise HTTPException(500, f"func: None passsed")
Expand All @@ -94,7 +94,7 @@ def get_region_statistical_map(parcellation_id: str, space_id: str, region_id: s
"content-disposition": f'attachment; filename="statistical_map.nii.gz"'
}

full_filename, cache_flag = func(parcellation_id, region_id, space_id)
full_filename, cache_flag = func(parcellation_id, region_id, space_id, extra_spec)
if cache_flag:
headers[cache_header] = "hit"
assert os.path.isfile(full_filename), f"file saved incorrectly"
Expand All @@ -107,12 +107,12 @@ class StatisticModelInfo(BaseModel):
@router.get("/statistical_map.info.json", response_model=StatisticModelInfo, tags=TAGS)
@version(*FASTAPI_VERSION)
@router_decorator(ROLE, func=statistical_map_info_json)
def get_region_statistical_map_metadata(parcellation_id: str, space_id: str, region_id: str, *, func):
def get_region_statistical_map_metadata(parcellation_id: str, space_id: str, region_id: str, extra_spec: str="", *, func):
"""Get metadata of statistical map according to specification"""
if func is None:
raise HTTPException(500, f"func: None passsed")

data = func(parcellation_id, region_id, space_id)
data = func(parcellation_id, region_id, space_id, extra_spec)
return StatisticModelInfo(**data)

@router.get("/assign", response_model=DataFrameModel, tags=TAGS)
Expand Down
6 changes: 3 additions & 3 deletions new_api/v3/data_handlers/map/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def assign(parcellation_id: str, space_id: str, point: str, assignment_type: str
return instance_to_model(result, detail=True).dict()

@data_decorator(ROLE)
def get_map(parcellation_id: str, space_id: str, maptype: Union[MapType, str], extra_spec: str):
def get_map(parcellation_id: str, space_id: str, maptype: Union[MapType, str], extra_spec: str=""):
"""Get a map instance, based on specification
Args:
Expand Down Expand Up @@ -56,12 +56,12 @@ def get_map(parcellation_id: str, space_id: str, maptype: Union[MapType, str], e
return instance_to_model(returned_maps[0], detail=True).dict()

@data_decorator(ROLE)
def statistical_map_nii_gz(parcellation_id: str, space_id: str, region_id: str, extra_spec: str, *, no_cache: bool):
def statistical_map_nii_gz(parcellation_id: str, space_id: str, region_id: str, extra_spec: str="", *, no_cache: bool):
filename, return_cached, warningtext = cache_region_statistic_map(parcellation_id, region_id, space_id, extra_spec, no_cache=no_cache)
return filename, return_cached

@data_decorator(ROLE)
def statistical_map_info_json(parcellation_id: str, space_id: str, region_id: str, extra_spec: str, *, no_cache: bool):
def statistical_map_info_json(parcellation_id: str, space_id: str, region_id: str, extra_spec: str="", *, no_cache: bool):
filename, return_cached, warningtext = cache_region_statistic_map(parcellation_id, region_id, space_id, extra_spec, no_cache=no_cache)

import nibabel as nib
Expand Down
2 changes: 2 additions & 0 deletions new_api/v3/serialization/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from new_api.v3.models._retrieval.datasets import EbrainsDatasetModel, EbrainsDsPerson

from siibra.atlases.parcellationmap import Map
from siibra.atlases.sparsemap import SparseMap
from siibra.attributes.descriptions import Name, EbrainsRef
from siibra.attributes.dataitems.base import Archive
from siibra.attributes.dataitems.volume.base import Volume, MESH_FORMATS, IMAGE_FORMATS
Expand Down Expand Up @@ -43,6 +44,7 @@ def clear_name(name: str):
result = result.replace(search, repl)
return " ".join(w for w in result.split(" ") if len(w))

@serialize(SparseMap)
@serialize(Map)
def map_to_model(mp: Map, **kwargs):

Expand Down

0 comments on commit 72cfc73

Please sign in to comment.