diff --git a/new_api/data_handlers/maps.py b/new_api/data_handlers/maps.py index 75c6520..c6e81dc 100644 --- a/new_api/data_handlers/maps.py +++ b/new_api/data_handlers/maps.py @@ -36,8 +36,9 @@ def cache_region_statistic_map(parcellation_id: str, region_id: str, space_id: s if len(maps) > 1: warning_texts = f"Multiple ({len(maps)}) maps found" - - volume_data = maps[0].fetch(region=region_id) + map = maps[0] + vol = map.extract_regional_map(region=region_id) + volume_data = vol.get_data() error_text = f"{error_text}, with region_id '{region_id}'" assert isinstance(volume_data, nib.Nifti1Image), f"{error_text}, volume provided is not of type Nifti1Image" @@ -77,14 +78,14 @@ def cache_parcellation_labelled_map(parcellation_id: str, space_id: str, region_ import nibabel as nib error_text = f"Map with parc id '{parcellation_id}', space id '{space_id}'" + labelled_map = siibra.get_map(parcellation_id, space_id, "labelled") + assert labelled_map is not None, f"{error_text} returns None" volume_data = None if region_id is not None: - region = siibra.get_region(parcellation_id, region_id) - volume_data = region.fetch_regional_map(space_id, "labelled") + volprov = labelled_map.extract_regional_map(region_id) else: - labelled_map = siibra.get_map(parcellation_id, space_id, "labelled") - assert labelled_map is not None, f"{error_text} returns None" - volume_data = labelled_map.fetch() + volprov = labelled_map.extract_full_map() + volume_data = volprov.get_data() assert isinstance(volume_data, nib.Nifti1Image), f"{error_text}, volume provided is not of type Nifti1Image" diff --git a/new_api/v3/serialization/map.py b/new_api/v3/serialization/map.py index 5f4ffbe..e8112f4 100644 --- a/new_api/v3/serialization/map.py +++ b/new_api/v3/serialization/map.py @@ -15,8 +15,9 @@ 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 +from siibra.attributes.dataproviders.base import Archive +from siibra.attributes.dataproviders.volume.base import VolumeProvider +from siibra.operations.volume_fetcher.base import VolumeFormats from siibra.factory.livequery.ebrains import EbrainsQuery, DatasetVersion def parse_archive_options(archive: Union[Archive, None]): @@ -140,10 +141,14 @@ def dsv_id_to_model(id: str): species = mp.species # TODO fix datasets - all_volumes = mp._find(Volume) + all_volumes = mp._find(VolumeProvider) volumes: List[VolumeModel] = [] - for vol in all_volumes: + indices = defaultdict(list) + volume_name_to_idx = {} + + for idx, vol in enumerate(all_volumes): + volume_name_to_idx[vol.name] = idx vol_ds: List[EbrainsDatasetModel] = [] if vol.id: vol_ds = [dsv_id_to_model(dsv) @@ -154,8 +159,8 @@ def dsv_id_to_model(id: str): volumes.append( VolumeModel(name="", formats=[vol.format], - provides_mesh=vol.format in MESH_FORMATS, - provides_image=vol.format in IMAGE_FORMATS, + provides_mesh=vol.format in VolumeFormats.MESH_FORMATS, + provides_image=vol.format in VolumeFormats.IMAGE_FORMATS, fragments={}, variant=None, provided_volumes={ @@ -166,17 +171,19 @@ def dsv_id_to_model(id: str): }, datasets=vol_ds)) - indices = defaultdict(list) - for idx, vol in enumerate(all_volumes): - for regionname, value in vol.mapping.items(): + + for regionname, mappings in mp.region_mapping.items(): + for mapping in mappings: + target = mapping["target"] + assert target in volume_name_to_idx, f"target {target} not found in volume name {volume_name_to_idx}" new_index = { - "volume": idx + "volume": volume_name_to_idx[target] } - if value.get("label"): - new_index["label"] = value.get("label") + if mapping.get("label"): + new_index["label"] = mapping.get("label") indices[regionname].append(new_index) indices[clear_name(regionname)].append(new_index) - + if mp.space_id == FSA_ID: assert len(all_volumes) == 2, f"Expected fsaverage to have 2 volumes, but got {len(all_volumes)}" @@ -191,19 +198,18 @@ def dsv_id_to_model(id: str): formats = list({lh_vol.format, rh_vol.format}) assert len(formats) == 1, f"Expected only one type of format, but got {formats}" format = formats[0] - assert lh_vol.archive_options is None and rh_vol.archive_options is None, f"Expected neither volume has archive options" + # assert lh_vol.archive_options is None and rh_vol.archive_options is None, f"Expected neither volume has archive options" all_vol_ids = [vol.id for vol in all_volumes if vol.id] all_vol_ds = [dsv_id_to_model(dsv) for ref in mp._find(EbrainsRef) for dsv in ref._dataset_verion_ids if ref.annotates in all_vol_ids] - volumes = [ VolumeModel(name="", formats=[format], - provides_mesh=vol.format in MESH_FORMATS, - provides_image=vol.format in IMAGE_FORMATS, + provides_mesh=vol.format in VolumeFormats.MESH_FORMATS, + provides_image=vol.format in VolumeFormats.IMAGE_FORMATS, fragments={}, variant=None, provided_volumes={