Skip to content

Commit

Permalink
Add CompoundFeature serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Oct 24, 2023
1 parent 86bb8c7 commit a6b8966
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/common/data_handlers/compounds/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def download_all(space_id: str, parcellation_id: str, region_id: str=None, featu
try:
path_to_feature_export = Path(SIIBRA_API_SHARED_DIR, f"export-{feature_id}.zip")
if not path_to_feature_export.exists():
feature = siibra.features.Feature.get_instance_by_id(feature_id)
feature = siibra.features.Feature._get_instance_by_id(feature_id)
feature.export(path_to_feature_export)
zipfile.write(path_to_feature_export, f"export-{feature_id}.zip")
except Exception as e:
Expand Down
6 changes: 3 additions & 3 deletions api/common/data_handlers/features/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_single_feature_from_id(feature_id: str, **kwargs):
import siibra
from api.serialization.util import instance_to_model
try:
feature = siibra.features.Feature.get_instance_by_id(feature_id)
feature = siibra.features.Feature._get_instance_by_id(feature_id)
except Exception as e:
raise NotFound(str(e))
else:
Expand All @@ -53,7 +53,7 @@ def get_single_feature_plot_from_id(feature_id: str, template="plotly", **kwargs
import json

try:
feature = siibra.features.Feature.get_instance_by_id(feature_id)
feature = siibra.features.Feature._get_instance_by_id(feature_id)
except Exception as e:
raise NotFound from e

Expand All @@ -79,7 +79,7 @@ def get_single_feature_download_zip_path(feature_id: str, **kwargs):
return str(full_filename)
import siibra
try:
feat = siibra.features.Feature.get_instance_by_id(feature_id)
feat = siibra.features.Feature._get_instance_by_id(feature_id)
except Exception as e:
logger.error(f"Error finding single feature {feature_id=}, {str(e)}")
raise NotFound from e
Expand Down
5 changes: 5 additions & 0 deletions api/models/features/_basetypes/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ class _FeatureModel(ConfigBaseModel, ABC, type="feature"):
class FeatureModel(_FeatureModel):
"""FeatureModel"""
pass


class CompoundFeatureModel(_FeatureModel, type="compound_feature"):
"""CompoundFeatureModel"""
subfeature_keys: List[str]
16 changes: 16 additions & 0 deletions api/serialization/features/_basetypes/feature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from api.serialization.util.siibra import Feature
from api.serialization.util import serialize, instance_to_model
from api.models.features._basetypes.feature import FeatureModel
from api.serialization.util.siibra import CompoundFeature
from api.models.features._basetypes.feature import CompoundFeatureModel


@serialize(Feature)
def feature_to_model(feat: Feature, detail: bool=False, **kwargs) -> FeatureModel:
Expand All @@ -22,3 +25,16 @@ def feature_to_model(feat: Feature, detail: bool=False, **kwargs) -> FeatureMode
anchor=instance_to_model(feat.anchor, **kwargs) if detail else None,
datasets=[instance_to_model(ds, **kwargs) for ds in feat.datasets]
)


@serialize(CompoundFeature, pass_super_model=True)
def serialize_cf(
cf: CompoundFeature,
detail=False,
super_model_dict={},
**kwargs
) -> CompoundFeatureModel:
return CompoundFeatureModel(
**super_model_dict,
indices=cf.indices
)
1 change: 1 addition & 0 deletions api/serialization/util/siibra.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from siibra.retrieval.datasets import EbrainsBaseDataset, GenericDataset

from siibra.features.feature import Feature
from siibra.features.feature import CompoundFeature
from siibra.features.connectivity.regional_connectivity import RegionalConnectivity
from siibra.features.tabular.cortical_profile import CorticalProfile
from siibra.features.tabular.tabular import Tabular
Expand Down
2 changes: 2 additions & 0 deletions docs/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ uvicorn api.server:api --host 127.0.0.1 --port 5000 --reload
```

## With docker-compose
0) Delete if there is a siibra-api docker image.
1) Change the siibra requirement by chosing the new tag or install from a branch git+https://github.com/FZJ-INM1-BDA/siibra-python.git@BranchName
```sh
docker-compose -f ./docker-compose-dev.yml up
```
2 changes: 1 addition & 1 deletion requirements/siibra.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
siibra==0.4a74
git+https://github.com/FZJ-INM1-BDA/siibra-python.git@feat_compoundFeat
plotly

0 comments on commit a6b8966

Please sign in to comment.