api.serialization
This module handles the serialization of siibra objects into pydantic models.
Processes import from this module will require siibra installed.
_common
mapindex_to_model(mapindex, **kwargs)
Serialize MapIndex instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mapindex |
MapIndex
|
instance to be serialized |
required |
Returns:
Type | Description |
---|---|
MapIndexModel
|
MapIndexModel |
Source code in api/serialization/_common.py
pddf_to_model(df, detail=False, **kwargs)
Serialize pandas dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame instance to be serialized |
required |
detail |
str
|
defailt flag. If not set, data attribute will not be populated. |
False
|
Returns:
Type | Description |
---|---|
DataFrameModel
|
DataFrameModel |
Source code in api/serialization/_common.py
pdseries_to_model(series, **kwargs)
Serialize pandas series.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series |
Series
|
Series instance to be serialized |
required |
Returns:
Type | Description |
---|---|
SeriesModel
|
SeriesModel |
Raises:
Type | Description |
---|---|
AssertionError
|
if dtype is not serializable |
Source code in api/serialization/_common.py
_retrieval
datasets
ebrains_dataset_to_model(ds, **kwargs)
Serialize ebrains dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds |
EbrainsBaseDataset
|
instance of EbrainsBaseDataset |
required |
Returns:
Type | Description |
---|---|
EbrainsDatasetModel
|
EbrainsDatasetModel |
Source code in api/serialization/_retrieval/datasets.py
generic_dataset_to_model(ds, **kwargs)
Serialize generic dataset
Source code in api/serialization/_retrieval/datasets.py
core
_concept
atlasconcept_to_model(concept, **kwargs)
Serialize base concept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concept |
AtlasConcept
|
AtlasConcept |
required |
Returns:
Type | Description |
---|---|
SiibraAtlasConcept
|
SiibraAtlasConcept |
Source code in api/serialization/core/_concept.py
atlas
atlas_to_model(atlas, *, detail=False, **kwargs)
Serializes an atlas into SiibraAtlasModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
atlas |
Atlas
|
Atlas |
required |
detail |
bool
|
detail flag |
False
|
Returns:
Type | Description |
---|---|
SiibraAtlasModel
|
SiibraAtlasModel |
Source code in api/serialization/core/atlas.py
get_species_data(species_str)
Translating string to SpeciesModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
species_str |
str
|
species string |
required |
Returns:
Type | Description |
---|---|
SpeciesModel
|
SpeciesModel |
Raises:
Type | Description |
---|---|
ValueError
|
If string does not decode |
Source code in api/serialization/core/atlas.py
parcellation
parcellation_to_model(parc, *, min_flag=False, **kwargs)
Serialize Parcellation into SiibraParcellationModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parc |
Parcellation
|
Parcellation |
required |
Returns:
Type | Description |
---|---|
SiibraParcellationModel
|
SiibraParcellationModel |
Source code in api/serialization/core/parcellation.py
parcversion_to_model(version, **kwargs)
Serialize ParcellationVersion into SiibraParcellationVersionModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
ParcellationVersion
|
ParcellationVersion |
required |
Returns:
Type | Description |
---|---|
SiibraParcellationVersionModel
|
SiibraParcellationVersionModel |
Source code in api/serialization/core/parcellation.py
region
region_to_model(region, *, min_flag=False, detail=False, space=None, **kwargs)
Serialize Region
Parameters:
Name | Type | Description | Default |
---|---|---|---|
region |
Region
|
Region object |
required |
detail |
bool
|
detail flag |
False
|
space |
Space
|
Space object |
None
|
Returns:
Type | Description |
---|---|
ParcellationEntityVersionModel
|
ParcellationEntityVersionModel |
Raises:
Type | Description |
---|---|
AssertionError
|
|
AssertionError
|
provided space is not of instance Space |
Source code in api/serialization/core/region.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
space
space_to_model(space, **kwargs)
Serialize space object into CommonCoordinateSpaceModel
Parameters:
Name | Type | Description | Default |
---|---|---|---|
space |
Space
|
space object to be serialized |
required |
Returns:
Type | Description |
---|---|
CommonCoordinateSpaceModel
|
CommonCoordinateSpaceModel |
Source code in api/serialization/core/space.py
features
_basetypes
cortical_profiles
cortical_profile_to_model(pr, detail=False, super_model_dict={}, **kwargs)
Serialize cortical profile into SiibraCorticalProfileModel.
As serialize.pass_super_model is set to true, the instance will first be serialized according to its superclass of CorticalProfile (Tabular),
and passed to this function as super_model_dict. User should not supply their own super_model_dict
kwarg, as it will be ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pr |
CorticalProfile
|
instance of CorticalProfile to be serialized |
required |
Returns:
Type | Description |
---|---|
SiibraCorticalProfileModel
|
SiibraCorticalProfileModel |
Source code in api/serialization/features/_basetypes/cortical_profiles.py
feature
feature_to_model(feat, detail=False, **kwargs)
Fallback serialize siibra Feature instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feat |
Feature
|
instance of Feature |
required |
detail |
bool
|
require detail flag. |
False
|
Returns:
Type | Description |
---|---|
FeatureModel
|
FeatureModel |
Source code in api/serialization/features/_basetypes/feature.py
regional_connectivity
regional_conn_to_model(conn, subject=None, detail=False, super_model_dict={}, **kwargs)
Serialize regional connectivity
As serialize.pass_super_model is set to true, the instance will first be serialized according to its superclass of RegionalConnectivity (Feature),
and passed to this function as super_model_dict. User should not supply their own super_model_dict
kwarg, as it will be ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
RegionalConnectivity
|
instance of RegionalConnnectivity |
required |
subject |
str
|
subject to be retrieved, passed directly to RegionalConnectivity.get_matrix. If not supplied, "_average" will be populated |
None
|
detail |
bool
|
detail flag. If not supplied, matrices attribute will not be populated |
False
|
Returns:
Type | Description |
---|---|
SiibraRegionalConnectivityModel
|
SiibraRegionalConnectivityModel |
Source code in api/serialization/features/_basetypes/regional_connectivity.py
tabular
tabular_to_model(tabular, detail=False, super_model_dict={}, **kwargs)
Fallback serialization of Tabular feature
As serialize.pass_super_model is set to true, the instance will first be serialized according to its superclass of Tabular (Feature),
and passed to this function as super_model_dict. User should not supply their own super_model_dict
kwarg, as it will be ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tabular |
Tabular
|
instance of tabular data |
required |
detail |
str
|
detail flag. If unset, will not populate |
False
|
Returns:
Type | Description |
---|---|
SiibraTabularModel
|
SiibraTabularModel |
Source code in api/serialization/features/_basetypes/tabular.py
volume_of_interest
voi_to_model(feat, **kwargs)
Serialize siibra Image instance
Serializing Image instance turns out to be rather complex, so doing it manually.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feat |
Image
|
instance of siibra Image |
required |
Returns:
Type | Description |
---|---|
SiibraVoiModel
|
SiibraVoiModel |
Source code in api/serialization/features/_basetypes/volume_of_interest.py
anchor
assignment_to_model(asgmt, detail=False, **kwargs)
Serialize AnatommicalAssignment instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asgmt |
AnatomicalAssignment
|
siibra AnatomicalAssignment instance |
required |
detail |
bool
|
detail flag. |
False
|
Returns:
Type | Description |
---|---|
SiibraAnatomicalAssignmentModel
|
SiibraAnatomicalAssignmentModel |
Source code in api/serialization/features/anchor.py
dataset
ebrains
ebrains_datafeature_to_model(feat, detail=False, super_model_dict={}, **kwargs)
Serialize instance of EbrainsDataFeature
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feat |
EbrainsDataFeature
|
instance of EbrainsDataFeature |
required |
detail |
str
|
detail flag. If unset, |
False
|
Returns:
Type | Description |
---|---|
SiibraEbrainsDataFeatureModel
|
SiibraEbrainsDataFeatureModel |
Source code in api/serialization/features/dataset/ebrains.py
locations
boundingbox
boundingbox_to_model(bbox, super_model_dict={}, **kwargs)
Serialize BoundingBox instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox |
BoundingBox
|
instance of bounding box |
required |
Returns:
Type | Description |
---|---|
BoundingBoxModel
|
BoundingBoxModel |
Source code in api/serialization/locations/boundingbox.py
location
location_to_model(location, **kwargs)
Fallback serialization of Location instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location |
Location
|
location instance |
required |
Returns: LocationModel
Source code in api/serialization/locations/location.py
point
point_to_model(point, **kwargs)
Serialization of Point instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point |
Point
|
Point instance to be serialized |
required |
Returns:
Type | Description |
---|---|
CoordinatePointModel
|
CoordinatePointModel |
Raises:
Type | Description |
---|---|
InvalidParameters
|
if point does not have space defined |
Source code in api/serialization/locations/point.py
util
instance_to_model(instance, *, use_class=None, skip_classes=[], **kwargs)
Serialize instance into model, according to register.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance |
Any
|
instance to be serialized |
required |
use_class |
Type
|
use registered method for this specific class for serialization |
None
|
skip_classes |
List[Type]
|
skip registered method for these classes |
[]
|
kwargs |
Dict[str, Any]
|
keyword arguements to be passed to downstream instance_to_model calls |
{}
|
Return
Serialized intances
Raises:
Type | Description |
---|---|
ClsNotRegisteredException
|
if |
ClsNotRegisteredException
|
if no suitable serialization can be found for |
NonStrKeyException
|
if instance contains a dictionary, which do not have str as keys |
Source code in api/serialization/util/__init__.py
serialize(Cls, pass_super_model=False, **kwargs)
Decorator function. Wrapping and registering serialization strategies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Cls |
Type[Any]
|
Class to be serialized |
required |
pass_super_model |
Dict[str, Any]
|
flag if the serialized super class should be provided via |
False
|
Source code in api/serialization/util/__init__.py
siibra
This module serves as the single import point of all siibra dependencies.
If siibra paths changes in the future, they only need to be updated here.
volumes
parcellationmap
map_to_model(map, super_model_dict={}, detail=False, **kwargs)
Serialize map instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map |
Map
|
Map instance |
required |
Returns:
Type | Description |
---|---|
MapModel
|
MapModel |
Source code in api/serialization/volumes/parcellationmap.py
volume
remap_provider(obj)
Mutate and remap providers.
n.b. will mutate provided dictionary. Use copy.copy to avoid unexpected behaviors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Dict[str, Union[dict, str]]
|
provider dictionary to be mutated |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in api/serialization/volumes/volume.py
volume_to_model(vol, **kwargs)
Serialize Volume instance.
If SIIBRA_API_REMAP_PROVIDERS
is provided in config, will remap the provider URLs accordingly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
Volume
|
Volume instance |
required |
Returns:
Type | Description |
---|---|
VolumeModel
|
VolumeModel |