Skip to content

Commit

Permalink
maint: serialize generic datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed Sep 29, 2023
1 parent 1f80062 commit 7514df5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion api/serialization/_retrieval/datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from api.serialization.util.siibra import EbrainsBaseDataset
from api.serialization.util.siibra import EbrainsBaseDataset, GenericDataset
from api.serialization.util import serialize
from api.models._retrieval.datasets import EbrainsDatasetModel, EbrainsDsPerson, EbrainsDsUrl
from hashlib import md5

@serialize(EbrainsBaseDataset)
def ebrains_dataset_to_model(ds: EbrainsBaseDataset, **kwargs) -> EbrainsDatasetModel:
Expand All @@ -21,3 +22,19 @@ def ebrains_dataset_to_model(ds: EbrainsBaseDataset, **kwargs) -> EbrainsDataset
ebrains_page=ds.ebrains_page,
custodians=[EbrainsDsPerson(**person) for person in ds.custodians]
)

@serialize(GenericDataset)
def generic_dataset_to_model(ds: GenericDataset, **kwargs) -> EbrainsDatasetModel:
"""Serialize generic dataset"""
return EbrainsDatasetModel(
id=md5(ds.name).hexdigest(),
name=ds.name,
urls=[EbrainsDsUrl(**url) for url in ds.urls],
description=ds.description,
contributors=[EbrainsDsPerson(id=person.get("name"),
identifier=person.get("name"),
shortName=person.get("name"),
name=person.get("name"))
for person in ds.contributors],
custodians=[],
)
2 changes: 1 addition & 1 deletion api/serialization/util/siibra.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from siibra.volumes.parcellationmap import Map
from siibra.volumes.volume import Volume

from siibra.retrieval.datasets import EbrainsBaseDataset
from siibra.retrieval.datasets import EbrainsBaseDataset, GenericDataset

from siibra.features.feature import Feature
from siibra.features.connectivity.regional_connectivity import RegionalConnectivity
Expand Down

0 comments on commit 7514df5

Please sign in to comment.