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

Enh patch sampling #644

Merged
merged 9 commits into from
Feb 20, 2025
29 changes: 29 additions & 0 deletions examples/tutorials/2025-paper-fig5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# %%
import siibra
assert siibra.__version__ >= "1.0.1"
import matplotlib.pyplot as plt

# %%
# 1: Retrieve probability map of a motor area in Julich-Brain
parc = siibra.parcellations.get('julich 3.1')
region = parc.get_region("4p right")
pmap = parc.get_map('mni152', 'statistical').get_volume(region)

# %%
# 2: Extract BigBrain 1 micron patches with high probability in this area
patches = siibra.features.get(pmap, "BigBrain1MicronPatch", lower_threshold=0.7)
print(f"Found {len(patches)} patches.")

# %%
# 3: Display highly rated samples, here further reduced to a predefined section
section = 3556
candidates = filter(lambda p: p.bigbrain_section == 3556, patches)
f, axs = plt.subplots(1, 3, figsize=(8, 24))
for patch, ax in zip(list(candidates)[:3], axs.ravel()):
patchdata = patch.fetch().get_fdata().squeeze()
ax.imshow(patchdata, cmap='gray', vmin=0, vmax=2**16)
ax.axis('off')
ax.set_title(f"#{section} - {patch.vertex}", fontsize=10)


# %%
4 changes: 2 additions & 2 deletions siibra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
from .retrieval.cache import Warmup, WarmupLevel

from . import configuration
from . import experimental
from .configuration import factory
from . import features, livequeries
from siibra.locations import Point, PointCloud
from siibra.locations import Point, PointCloud, Plane, BoundingBox

import os as _os
logger.info(f"Version: {__version__}")
Expand Down Expand Up @@ -151,6 +150,7 @@ def __dir__():
"MapType",
"Point",
"PointCloud",
"BoundingBox",
"QUIET",
"VERBOSE",
"fetch_ebrains_token",
Expand Down
19 changes: 0 additions & 19 deletions siibra/experimental/__init__.py

This file was deleted.

61 changes: 0 additions & 61 deletions siibra/experimental/contour.py

This file was deleted.

57 changes: 0 additions & 57 deletions siibra/experimental/cortical_profile_sampler.py

This file was deleted.

98 changes: 0 additions & 98 deletions siibra/experimental/patch.py

This file was deleted.

6 changes: 4 additions & 2 deletions siibra/features/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
XPCTVolumeOfInterest,
LSFMVolumeOfInterest,
DTIVolumeOfInterest
# SegmentedVolumeOfInterest
)
from .sections import CellbodyStainedSection
from .sections import (
CellbodyStainedSection,
BigBrain1MicronPatch
)
61 changes: 59 additions & 2 deletions siibra/features/image/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,69 @@
"""Multimodal data features in 2D section."""

from . import image
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ...locations import AxisAlignedPatch
from ...features.anchor import AnatomicalAnchor


class CellbodyStainedSection(
image.Image,
configuration_folder='features/images/sections/cellbody',
category="cellular"
configuration_folder="features/images/sections/cellbody",
category="cellular",
):
def __init__(self, **kwargs):
image.Image.__init__(self, **kwargs, modality="cell body staining")


class BigBrain1MicronPatch(image.Image, category="cellular"):
def __init__(
self,
patch: "AxisAlignedPatch",
section: CellbodyStainedSection,
vertex: int,
relevance: float,
anchor: "AnatomicalAnchor",
**kwargs
):
self._patch = patch
self._section = section
self.vertex = vertex
self.relevance = relevance
image.Image.__init__(
self,
name=f"Cortical patch in {section.name}",
modality=section.modality,
space_spec=section._space_spec,
providers=list(section._providers.values()),
region=None,
datasets=section.datasets,
bbox=patch.boundingbox,
id=None
)
self._anchor_cached = anchor

def __repr__(self):
return (
f"<{self.__class__.__name__}(space_spec={self._space_spec}, "
f"name='{self.name}', "
f"section='{self._section.get_boundingbox().minpoint.bigbrain_section()}', "
f"vertex='{self.vertex}', providers={self._providers})>"
)

@property
def bigbrain_section(self):
return self.get_boundingbox().minpoint.bigbrain_section()

def fetch(self, flip=False, **kwargs):
assert "voi" not in kwargs
res = kwargs.get("resolution_mm", -1)
if flip:
return self._patch.flip().extract_volume(
self._section, resolution_mm=res
).fetch()
else:
return self._patch.extract_volume(
self._section, resolution_mm=res
).fetch()
7 changes: 0 additions & 7 deletions siibra/features/image/volume_of_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,3 @@ class LSFMVolumeOfInterest(
def __init__(self, modality, **kwargs):
image.Image.__init__(self, **kwargs, modality=modality)

# class SegmentedVolumeOfInterest(
# image.Image,
# configuration_folder="features/images/vois/segmentation",
# category="segmentation"
# ):
# def __init__(self, **kwargs):
# image.Image.__init__(self, **kwargs, modality="segmentation")
Loading
Loading