Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generic tabular and image features #649

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion siibra/configuration/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
from ..commons import logger, Species
from ..features import anchor, connectivity
from ..features.tabular import (
tabular,
receptor_density_profile,
receptor_density_fingerprint,
cell_density_profile,
layerwise_cell_density,
regional_timeseries_activity,
)
from ..features.image import sections, volume_of_interest
from ..features.image import image, sections, volume_of_interest
from ..core import atlas, parcellation, space, region
from ..locations import point, pointcloud, boundingbox
from ..retrieval import datasets, repositories
Expand Down Expand Up @@ -391,6 +392,19 @@ def build_receptor_density_fingerprint(cls, spec):
prerelease=spec.get("prerelease", False),
)

@classmethod
@build_type("siibra/feature/tabular/v0.1")
def build_generic_tabular(cls, spec):
return tabular.Tabular(
file=spec["file"],
description=spec.get("description"),
modality=spec.get("modality"),
anchor=cls.extract_anchor(spec),
datasets=cls.extract_datasets(spec),
id=spec.get("@id", None),
prerelease=spec.get("prerelease", False),
)

@classmethod
@build_type("siibra/feature/fingerprint/celldensity/v0.1")
def build_cell_density_fingerprint(cls, spec):
Expand Down Expand Up @@ -492,6 +506,22 @@ def build_volume_of_interest(cls, spec):
f"No method for building image section feature type {modality}."
)

@classmethod
@build_type("siibra/feature/image/v0.1")
def build_generic_image_feature(cls, spec):
kwargs = {
"name": spec.get("name"),
"modality": spec.get("modality"),
"region": spec.get("region", None),
"space_spec": spec.get("space"),
"providers": cls.build_volumeproviders(spec.get("providers")),
"datasets": cls.extract_datasets(spec),
"bbox": cls.build_boundingbox(spec),
"id": spec.get("@id", None),
"prerelease": spec.get("prerelease", False),
}
return image.Image(**kwargs)

@classmethod
@build_type("siibra/feature/connectivitymatrix/v0.3")
def build_connectivity_matrix(cls, spec):
Expand Down
7 changes: 6 additions & 1 deletion siibra/features/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def __str__(self):
return f"Bounding box of image in {self.space.name}"


class Image(feature.Feature, _volume.Volume):
class Image(
feature.Feature,
_volume.Volume,
configuration_folder="features/images",
category="generic"
):

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion siibra/features/tabular/receptor_density_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def __init__(
description=self.DESCRIPTION,
modality="Neurotransmitter receptor density",
anchor=anchor,
file=tsvfile,
data=None, # lazy loading below
datasets=datasets,
id=id,
prerelease=prerelease,
)
self._loader = requests.HttpRequest(tsvfile)

@property
def unit(self) -> str:
Expand Down
17 changes: 14 additions & 3 deletions siibra/features/tabular/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from .. import feature
from .. import anchor as _anchor
from ...commons import logger
from ...retrieval import requests


class Tabular(feature.Feature):
class Tabular(feature.Feature, category="generic", configuration_folder="features/tabular"):
"""
Represents a table of different measures anchored to a brain location.

Expand All @@ -42,7 +43,8 @@ def __init__(
description: str,
modality: str,
anchor: _anchor.AnatomicalAnchor,
data: pd.DataFrame, # sample x feature dimension
file: str = None,
data: pd.DataFrame = None, # sample x feature dimension
datasets: list = [],
id: str = None,
prerelease: bool = False,
Expand All @@ -56,10 +58,19 @@ def __init__(
id=id,
prerelease=prerelease
)
self._data_cached = data
if data is None:
if file is not None:
self._loader = requests.HttpRequest(file)
else:
self._data_cached = data
else:
self._loader = None
self._data_cached = data

@property
def data(self):
if self._loader is not None:
self._data_cached = self._loader.get()
return self._data_cached.copy()

def _to_zip(self, fh: ZipFile):
Expand Down
Loading