-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: add compound feature serialization
maint: pin siibra-python version
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
siibra v0.5 introduced compound features. New serialization strategies and models need to be introduced in order to take full advantage of the introduction of compound features. | ||
|
||
## Import the new class | ||
|
||
`api.serialization.util.siibra` Serves as the one and single entrypoint to siibra package. To access the new class `CompoundFeature`, import it here. | ||
|
||
```python | ||
# in api.serialization.util.siibra | ||
|
||
# ... trimmed for brevity | ||
|
||
from siibra.feature.feature import CompoundFeature | ||
``` | ||
|
||
## Adding serialization model | ||
|
||
Next, we define the shape of serialized instances of `CompoundFeature`. | ||
|
||
Since `CompoundFeature` subclasses `Feature`, it is quite natural to have the model, `CompoundFeatureModel`, subclass `FeatureModel`. | ||
|
||
Here, we also added the property `subfeature_keys`, which is the additional property of `CompoundFeatureModel` compared to `FeatureModel` see [more detail](../api.models/#api.models._commons.ConfigBaseModel.__init_subclass__) | ||
|
||
```python | ||
# in api.models.features._basetypes.feature | ||
|
||
# ... trimmed for brevity | ||
|
||
class CompoundFeatureModel(_FeatureModel, type="compound_feature"): | ||
"""CompoundFeatureModel""" | ||
subfeature_keys: List[str] | ||
|
||
``` | ||
|
||
## Adding serialization strategy | ||
|
||
We then add the logic of serialization. | ||
|
||
```python | ||
# in api.serialization.features.feature | ||
|
||
from api.serialization.util.siibra import CompoundFeature | ||
from api.models.features._basetypes.feature import CompoundFeatureModel | ||
|
||
from api.serialization.util import ( | ||
serialize, | ||
instance_to_model | ||
) | ||
|
||
@serialize(CompoundFeature, pass_super_model=True) | ||
def serialize_cf(cf: CompoundFeature, detail=False, super_model_dict={}, **kwargs) -> CompoundFeatureModel: | ||
return CompoundFeatureModel( | ||
**super_model_dict, | ||
subfeature_keys=cf.subfeature_keys | ||
) | ||
|
||
``` | ||
|
||
## Testing the added feature | ||
|
||
[start the developer server](./develop.md), and try to fetch a new feature. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
siibra>=0.4a68 | ||
siibra==0.4a68 | ||
plotly |