Skip to content

Commit

Permalink
bugfix: extra_spec -> name
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed Oct 2, 2024
1 parent fd88739 commit eee077e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
13 changes: 6 additions & 7 deletions api/server/volumes/parcellationmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
@router.get("", response_model=MapModel)
@version(*FASTAPI_VERSION)
@router_decorator(ROLE, func=get_map)
def get_siibra_map(parcellation_id: str, space_id: str, map_type: MapType, extra_spec: str= "", *, func):
def get_siibra_map(parcellation_id: str, space_id: str, map_type: MapType, name: str= "", *, func):
"""Get map according to specification"""
if func is None:
raise HTTPException(500, f"func: None passsed")
return func(parcellation_id, space_id, map_type, extra_spec)
return func(parcellation_id, space_id, map_type, name)

@router.get("/resampled_template", response_class=FileResponse, tags=TAGS, description="""
Return a resampled template volume, based on labelled parcellation map.
Expand Down Expand Up @@ -83,7 +83,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, region_id: str, space_id: str, extra_spec: str="", *, func):
def get_region_statistical_map(parcellation_id: str, region_id: str, space_id: str, name: str="", *, func):
"""Get statistical map according to specification"""
if func is None:
raise HTTPException(500, f"func: None passsed")
Expand All @@ -92,8 +92,7 @@ def get_region_statistical_map(parcellation_id: str, region_id: str, space_id: s
"content-type": "application/octet-stream",
"content-disposition": f'attachment; filename="statistical_map.nii.gz"'
}

full_filename, cache_flag = func(parcellation_id=parcellation_id, region_id=region_id, space_id=space_id, extra_spec=extra_spec)
full_filename, cache_flag = func(parcellation_id=parcellation_id, region_id=region_id, space_id=space_id, name=name)
if cache_flag:
headers[cache_header] = "hit"
assert os.path.isfile(full_filename), f"file saved incorrectly"
Expand All @@ -106,12 +105,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, region_id: str, space_id: str, extra_spec: str="", *, func):
def get_region_statistical_map_metadata(parcellation_id: str, region_id: str, space_id: str, name: 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=parcellation_id, region_id=region_id, space_id=space_id, extra_spec=extra_spec)
data = func(parcellation_id=parcellation_id, region_id=region_id, space_id=space_id, name=name)
return StatisticModelInfo(**data)

@router.get("/assign", response_model=DataFrameModel, tags=TAGS)
Expand Down
4 changes: 2 additions & 2 deletions new_api/data_handlers/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from new_api.common import get_filename

def cache_region_statistic_map(parcellation_id: str, region_id: str, space_id: str, extra_spec: str= "", *, no_cache=False) -> Tuple[str, bool, str]:
def cache_region_statistic_map(parcellation_id: str, region_id: str, space_id: str, name: str= "", *, no_cache=False) -> Tuple[str, bool, str]:
"""Retrieve and save regional statistical map (if necessary), and then return the path of the map.
Args:
Expand All @@ -31,7 +31,7 @@ def cache_region_statistic_map(parcellation_id: str, region_id: str, space_id: s

error_text = f"Map with parc id '{parcellation_id}', space id '{space_id}'"

maps = siibra.find_maps(parcellation_id, space_id, "statistical", extra_spec)
maps = siibra.find_maps(parcellation_id, space_id, "statistical", name)
assert len(maps) > 0, f"{error_text} returns None"

if len(maps) > 1:
Expand Down
20 changes: 10 additions & 10 deletions new_api/v3/data_handlers/map/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
from new_api.warmup import register_warmup_fn

@data_decorator(ROLE)
def assign(parcellation_id: str, space_id: str, point: str, assignment_type: str=Literal["statistical", "labelled"], sigma_mm: float=0., extra_specs: str=""):
def assign(parcellation_id: str, space_id: str, point: str, assignment_type: str=Literal["statistical", "labelled"], sigma_mm: float=0., name: str=""):
import siibra
from siibra.attributes.locations.point import parse_coordinate, Point
coordinate = parse_coordinate(point)
point = Point(coordinate=coordinate, space_id=space_id, sigma=sigma_mm)
maps = siibra.find_maps(parcellation_id, space_id, assignment_type, extra_specs)
maps = siibra.find_maps(parcellation_id, space_id, assignment_type, name)
if len(maps) == 0:
raise NotFound(f"map with {parcellation_id=!r}, {space_id=!r}, {assignment_type=!r}, {extra_specs=!r} not found")
raise NotFound(f"map with {parcellation_id=!r}, {space_id=!r}, {assignment_type=!r}, {name=!r} not found")
mp = maps[0]
result = mp.lookup_points(point)
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], name: str=""):
"""Get a map instance, based on specification
Args:
Expand All @@ -49,20 +49,20 @@ def get_map(parcellation_id: str, space_id: str, maptype: Union[MapType, str], e
assert maptype is not None, f"maptype is neither MapType nor str"
maptype = maptype.lower()

returned_maps = siibra.find_maps(parcellation_id, space_id, maptype=maptype, extra_spec=extra_spec)
returned_maps = siibra.find_maps(parcellation_id, space_id, maptype=maptype, name=name)

if len(returned_maps) == 0:
raise NotFound(f"get_map with spec {parcellation_id=!r}, {space_id=!r}, {maptype=!r}, {extra_spec=!r} found no map.")
raise NotFound(f"get_map with spec {parcellation_id=!r}, {space_id=!r}, {maptype=!r}, {name=!r} found no map.")
return instance_to_model(returned_maps[0], detail=True).dict()

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

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

import nibabel as nib
import numpy as np
Expand Down

0 comments on commit eee077e

Please sign in to comment.