siibra 1.0.1a1__py3-none-any.whl → 1.0.1a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of siibra might be problematic. Click here for more details.

Files changed (66) hide show
  1. siibra/VERSION +1 -1
  2. siibra/__init__.py +7 -16
  3. siibra/commons.py +9 -7
  4. siibra/configuration/configuration.py +5 -5
  5. siibra/configuration/factory.py +9 -8
  6. siibra/core/__init__.py +1 -1
  7. siibra/core/assignment.py +1 -0
  8. siibra/core/atlas.py +3 -3
  9. siibra/core/concept.py +4 -2
  10. siibra/core/parcellation.py +5 -5
  11. siibra/core/region.py +24 -25
  12. siibra/core/space.py +4 -6
  13. siibra/core/structure.py +2 -2
  14. siibra/features/anchor.py +2 -4
  15. siibra/features/connectivity/regional_connectivity.py +10 -13
  16. siibra/features/dataset/ebrains.py +1 -1
  17. siibra/features/feature.py +21 -18
  18. siibra/features/image/__init__.py +4 -2
  19. siibra/features/image/image.py +2 -4
  20. siibra/features/image/sections.py +81 -2
  21. siibra/features/image/volume_of_interest.py +0 -8
  22. siibra/features/tabular/__init__.py +1 -1
  23. siibra/features/tabular/bigbrain_intensity_profile.py +2 -1
  24. siibra/features/tabular/cell_density_profile.py +8 -9
  25. siibra/features/tabular/cortical_profile.py +6 -6
  26. siibra/features/tabular/gene_expression.py +6 -5
  27. siibra/features/tabular/layerwise_bigbrain_intensities.py +4 -3
  28. siibra/features/tabular/layerwise_cell_density.py +4 -6
  29. siibra/features/tabular/receptor_density_fingerprint.py +34 -9
  30. siibra/features/tabular/receptor_density_profile.py +1 -2
  31. siibra/features/tabular/regional_timeseries_activity.py +7 -7
  32. siibra/features/tabular/tabular.py +4 -5
  33. siibra/livequeries/allen.py +20 -22
  34. siibra/livequeries/bigbrain.py +239 -51
  35. siibra/livequeries/ebrains.py +13 -10
  36. siibra/livequeries/query.py +3 -3
  37. siibra/locations/__init__.py +17 -8
  38. siibra/locations/boundingbox.py +7 -6
  39. siibra/{experimental/plane3d.py → locations/experimental.py} +113 -13
  40. siibra/locations/location.py +10 -12
  41. siibra/locations/point.py +7 -16
  42. siibra/locations/pointcloud.py +51 -10
  43. siibra/retrieval/cache.py +1 -0
  44. siibra/retrieval/datasets.py +19 -13
  45. siibra/retrieval/repositories.py +10 -11
  46. siibra/retrieval/requests.py +26 -24
  47. siibra/vocabularies/__init__.py +1 -2
  48. siibra/volumes/__init__.py +4 -3
  49. siibra/volumes/parcellationmap.py +30 -16
  50. siibra/volumes/providers/freesurfer.py +4 -4
  51. siibra/volumes/providers/gifti.py +4 -4
  52. siibra/volumes/providers/neuroglancer.py +19 -22
  53. siibra/volumes/providers/nifti.py +6 -6
  54. siibra/volumes/providers/provider.py +3 -2
  55. siibra/volumes/sparsemap.py +7 -6
  56. siibra/volumes/volume.py +21 -28
  57. {siibra-1.0.1a1.dist-info → siibra-1.0.1a2.dist-info}/METADATA +10 -6
  58. siibra-1.0.1a2.dist-info/RECORD +80 -0
  59. {siibra-1.0.1a1.dist-info → siibra-1.0.1a2.dist-info}/WHEEL +1 -1
  60. siibra/experimental/__init__.py +0 -19
  61. siibra/experimental/contour.py +0 -61
  62. siibra/experimental/cortical_profile_sampler.py +0 -57
  63. siibra/experimental/patch.py +0 -98
  64. siibra-1.0.1a1.dist-info/RECORD +0 -84
  65. {siibra-1.0.1a1.dist-info → siibra-1.0.1a2.dist-info}/LICENSE +0 -0
  66. {siibra-1.0.1a1.dist-info → siibra-1.0.1a2.dist-info}/top_level.txt +0 -0
@@ -14,13 +14,92 @@
14
14
  # limitations under the License.
15
15
  """Multimodal data features in 2D section."""
16
16
 
17
+ from typing import TYPE_CHECKING
18
+
17
19
  from . import image
18
20
 
21
+ if TYPE_CHECKING:
22
+ from ...locations import AxisAlignedPatch, Contour
23
+ from ...features.anchor import AnatomicalAnchor
24
+
19
25
 
20
26
  class CellbodyStainedSection(
21
27
  image.Image,
22
- configuration_folder='features/images/sections/cellbody',
23
- category="cellular"
28
+ configuration_folder="features/images/sections/cellbody",
29
+ category="cellular",
24
30
  ):
25
31
  def __init__(self, **kwargs):
26
32
  image.Image.__init__(self, **kwargs, modality="cell body staining")
33
+
34
+
35
+ class BigBrain1MicronPatch(image.Image, category="cellular"):
36
+
37
+ _DESCRIPTION = """Sample approximately orthogonal cortical image patches
38
+ from BigBrain 1 micron sections, guided by an image volume
39
+ in a supported reference space providing. The image
40
+ volume is used as a weighted mask to extract patches
41
+ along the cortical midsurface with nonzero weights in the
42
+ input image.
43
+ An optional lower_threshold can be used to narrow down
44
+ the search. The weight is stored with the resulting features."""
45
+
46
+ def __init__(
47
+ self,
48
+ patch: "AxisAlignedPatch",
49
+ profile: "Contour",
50
+ section: CellbodyStainedSection,
51
+ vertex: int,
52
+ relevance: float,
53
+ anchor: "AnatomicalAnchor",
54
+ ):
55
+ self._patch = patch
56
+ self._profile = profile
57
+ self._section = section
58
+ self.vertex = vertex
59
+ self.relevance = relevance
60
+ image.Image.__init__(
61
+ self,
62
+ name=f"Cortical patch in {section.name}",
63
+ modality=section.modality,
64
+ space_spec=section._space_spec,
65
+ providers=list(section._providers.values()),
66
+ region=None,
67
+ datasets=section.datasets,
68
+ bbox=patch.boundingbox,
69
+ id=None,
70
+ )
71
+ self._anchor_cached = anchor
72
+ self._description_cached = self._DESCRIPTION
73
+
74
+ def __repr__(self):
75
+ return (
76
+ f"<{self.__class__.__name__}(space_spec={self._space_spec}, "
77
+ f"name='{self.name}', "
78
+ f"section='{self._section.get_boundingbox().minpoint.bigbrain_section()}', "
79
+ f"vertex='{self.vertex}', providers={self._providers})>"
80
+ )
81
+
82
+ @property
83
+ def section(self) -> CellbodyStainedSection:
84
+ return self._section
85
+
86
+ def get_boundingbox(self, **fetch_kwargs):
87
+ """Enforce that the bounding box spans the full section thickness."""
88
+ bbox_section = self._section.get_boundingbox(**fetch_kwargs)
89
+ bbox = self._patch.boundingbox
90
+ bbox.minpoint[1] = bbox_section.minpoint[1]
91
+ bbox.maxpoint[1] = bbox_section.maxpoint[1]
92
+ return bbox
93
+
94
+ @property
95
+ def profile(self) -> "Contour":
96
+ return self._profile
97
+
98
+ @property
99
+ def bigbrain_section(self):
100
+ return self.get_boundingbox().minpoint.bigbrain_section()
101
+
102
+ def fetch(self, flip: bool = False, resolution_mm: float = -1, **kwargs):
103
+ assert len(kwargs) == 0
104
+ p = self._patch.flip() if flip else self._patch
105
+ return p.extract_volume(self._section, resolution_mm=resolution_mm).fetch()
@@ -78,11 +78,3 @@ class LSFMVolumeOfInterest(
78
78
  ):
79
79
  def __init__(self, modality, **kwargs):
80
80
  image.Image.__init__(self, **kwargs, modality=modality)
81
-
82
- # class SegmentedVolumeOfInterest(
83
- # image.Image,
84
- # configuration_folder="features/images/vois/segmentation",
85
- # category="segmentation"
86
- # ):
87
- # def __init__(self, **kwargs):
88
- # image.Image.__init__(self, **kwargs, modality="segmentation")
@@ -15,7 +15,7 @@
15
15
  """Multimodal data features in tabular formats."""
16
16
 
17
17
  from .bigbrain_intensity_profile import BigBrainIntensityProfile
18
- from .cell_density_profile import CellDensityProfile
18
+ from .cell_density_profile import CellDensityProfile, cell_reader, layer_reader
19
19
  from .gene_expression import GeneExpressions
20
20
  from .layerwise_bigbrain_intensities import LayerwiseBigBrainIntensities
21
21
  from .layerwise_cell_density import LayerwiseCellDensity
@@ -13,9 +13,10 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ from typing import List, TYPE_CHECKING
17
+
16
18
  from . import cortical_profile
17
19
 
18
- from typing import List, TYPE_CHECKING
19
20
  if TYPE_CHECKING:
20
21
  from ...features.anchor import AnatomicalAnchor
21
22
 
@@ -13,19 +13,18 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from . import cortical_profile
17
-
18
- from .. import anchor as _anchor
19
- from ...commons import logger
20
- from ...retrieval import requests
16
+ from io import BytesIO
17
+ from typing import Union, Tuple, Iterable
21
18
 
22
- from skimage.draw import polygon
23
- from skimage.transform import resize
24
19
  import numpy as np
25
20
  import pandas as pd
21
+ from skimage.draw import polygon
22
+ from skimage.transform import resize
26
23
 
27
- from io import BytesIO
28
- from typing import Union, Tuple, Iterable
24
+ from . import cortical_profile
25
+ from .. import anchor as _anchor
26
+ from ...commons import logger
27
+ from ...retrieval import requests
29
28
 
30
29
 
31
30
  def cell_reader(bytes_buffer: bytes):
@@ -13,15 +13,15 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from . import tabular
17
- from ..feature import Compoundable
18
-
19
- from .. import anchor as _anchor
20
-
21
- import pandas as pd
22
16
  from typing import Union, Dict, Tuple, List
17
+
23
18
  from textwrap import wrap
24
19
  import numpy as np
20
+ import pandas as pd
21
+
22
+ from . import tabular
23
+ from .. import anchor as _anchor
24
+ from ..feature import Compoundable
25
25
 
26
26
 
27
27
  class CorticalProfile(tabular.Tabular, Compoundable):
@@ -13,11 +13,6 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from .. import anchor as _anchor
17
- from . import tabular
18
- from ...retrieval.datasets import GenericDataset
19
-
20
- import pandas as pd
21
16
  from textwrap import wrap
22
17
  from typing import List
23
18
  try:
@@ -25,6 +20,12 @@ try:
25
20
  except ImportError:
26
21
  from typing_extensions import TypedDict
27
22
 
23
+ import pandas as pd
24
+
25
+ from . import tabular
26
+ from .. import anchor as _anchor
27
+ from ...retrieval.datasets import GenericDataset
28
+
28
29
 
29
30
  class GeneExpressions(
30
31
  tabular.Tabular,
@@ -13,13 +13,14 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from . import cortical_profile
17
- from . import tabular
16
+ from typing import TYPE_CHECKING
18
17
 
19
18
  import pandas as pd
20
19
  import numpy as np
21
20
 
22
- from typing import TYPE_CHECKING
21
+ from . import tabular
22
+ from . import cortical_profile
23
+
23
24
  if TYPE_CHECKING:
24
25
  from ...features.anchor import AnatomicalAnchor
25
26
 
@@ -13,17 +13,15 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import numpy as np
17
+ import pandas as pd
18
+
16
19
  from . import cortical_profile
20
+ from . import tabular, cell_reader, layer_reader
17
21
  from .. import anchor as _anchor
18
- from . import tabular
19
- from ..tabular.cell_density_profile import cell_reader, layer_reader
20
-
21
22
  from ... import commons
22
23
  from ...retrieval import requests
23
24
 
24
- import pandas as pd
25
- import numpy as np
26
-
27
25
 
28
26
  class LayerwiseCellDensity(
29
27
  tabular.Tabular,
@@ -13,18 +13,18 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from .. import anchor as _anchor
17
- from . import tabular
16
+ from textwrap import wrap
17
+ from typing import List
18
+
19
+ import numpy as np
20
+ import pandas as pd
18
21
 
22
+ from . import tabular
23
+ from .. import anchor as _anchor
19
24
  from ...commons import logger
20
25
  from ...vocabularies import RECEPTOR_SYMBOLS
21
26
  from ...retrieval import requests
22
27
 
23
- import pandas as pd
24
- import numpy as np
25
- from textwrap import wrap
26
- from typing import List
27
-
28
28
 
29
29
  class ReceptorDensityFingerprint(
30
30
  tabular.Tabular,
@@ -190,6 +190,31 @@ class ReceptorDensityFingerprint(
190
190
  else:
191
191
  raise NotImplementedError
192
192
 
193
- def plot(self, *args, **kwargs):
193
+ def plot(
194
+ self,
195
+ *args,
196
+ receptors: List[str] = None,
197
+ backend: str = "matplotlib",
198
+ **kwargs
199
+ ):
200
+ """
201
+ Create a bar plot of receptor density fingerprint.
202
+
203
+ Parameters
204
+ ----------
205
+ receptors : List[str], optional
206
+ Plot a subset of receptors.
207
+ backend: str
208
+ "matplotlib", "plotly", or others supported by pandas DataFrame
209
+ plotting backend.
210
+ **kwargs
211
+ takes Matplotlib.pyplot keyword arguments
212
+ """
194
213
  kwargs['xlabel'] = ""
195
- return super().plot(*args, **kwargs)
214
+ kwargs["backend"] = backend
215
+ og_data = self.data
216
+ if receptors is not None:
217
+ self._data_cached = og_data.loc[receptors]
218
+ fig = super().plot(*args, **kwargs)
219
+ self._data_cached = og_data
220
+ return fig
@@ -13,9 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from .. import anchor as _anchor
17
16
  from . import cortical_profile
18
-
17
+ from .. import anchor as _anchor
19
18
  from ... import vocabularies
20
19
  from ...commons import create_key
21
20
  from ...retrieval import requests
@@ -13,19 +13,19 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ from typing import Callable, List, Union
17
+
18
+ import numpy as np
19
+ import pandas as pd
20
+
16
21
  from . import tabular
22
+ from .. import anchor as _anchor
17
23
  from ..feature import Compoundable
18
-
19
24
  from ...core import region as _region
20
- from .. import anchor as _anchor
21
25
  from ...commons import QUIET, siibra_tqdm
22
26
  from ...locations import pointcloud
23
- from ...retrieval.repositories import RepositoryConnector
24
27
  from ...retrieval.requests import HttpRequest
25
-
26
- from typing import Callable, List, Union
27
- import pandas as pd
28
- import numpy as np
28
+ from ...retrieval.repositories import RepositoryConnector
29
29
 
30
30
 
31
31
  class RegionalTimeseriesActivity(tabular.Tabular, Compoundable):
@@ -15,15 +15,14 @@
15
15
  """Base type of features in tabular formats."""
16
16
 
17
17
  from zipfile import ZipFile
18
- from .. import feature
19
-
20
- from .. import anchor as _anchor
21
-
22
- from ...commons import logger
23
18
 
24
19
  import pandas as pd
25
20
  from textwrap import wrap
26
21
 
22
+ from .. import feature
23
+ from .. import anchor as _anchor
24
+ from ...commons import logger
25
+
27
26
 
28
27
  class Tabular(feature.Feature):
29
28
  """
@@ -14,21 +14,21 @@
14
14
  # limitations under the License.
15
15
  """Query Allen Human Brain Atlas microarray data in specified volume."""
16
16
 
17
- from .query import LiveQuery
17
+ from typing import List
18
+ from xml.etree import ElementTree
19
+ import json
18
20
 
19
- from ..core import space as _space, structure
21
+ import numpy as np
22
+
23
+ from . import query as _query
24
+ from ..core import structure
20
25
  from ..features import anchor as _anchor
21
26
  from ..features.tabular.gene_expression import GeneExpressions
22
27
  from ..commons import logger, Species
23
- from ..locations import point, pointcloud
28
+ from ..locations import pointcloud
24
29
  from ..retrieval import HttpRequest
25
30
  from ..vocabularies import GENE_NAMES
26
31
 
27
- from typing import List
28
- from xml.etree import ElementTree
29
- import numpy as np
30
- import json
31
-
32
32
 
33
33
  BASE_URL = "http://api.brain-map.org/api/v2/data"
34
34
 
@@ -51,7 +51,7 @@ class InvalidAllenAPIResponseException(Exception):
51
51
  pass
52
52
 
53
53
 
54
- class AllenBrainAtlasQuery(LiveQuery, args=['gene'], FeatureType=GeneExpressions):
54
+ class AllenBrainAtlasQuery(_query.LiveQuery, args=['gene'], FeatureType=GeneExpressions):
55
55
  """
56
56
  Interface to Allen Human Brain Atlas microarray data.
57
57
 
@@ -117,7 +117,7 @@ class AllenBrainAtlasQuery(LiveQuery, args=['gene'], FeatureType=GeneExpressions
117
117
  will be tested against the region mask in ICBM space
118
118
  to produce a table of outputs.
119
119
  """
120
- LiveQuery.__init__(self, **kwargs)
120
+ _query.LiveQuery.__init__(self, **kwargs)
121
121
  gene = kwargs.get('gene')
122
122
 
123
123
  def parse_gene(spec):
@@ -144,27 +144,25 @@ class AllenBrainAtlasQuery(LiveQuery, args=['gene'], FeatureType=GeneExpressions
144
144
  'https://github.com/FZJ-INM1-BDA/siibra-python/issues/636.'
145
145
  )
146
146
 
147
- mnispace = _space.Space.registry().get('mni152')
148
-
149
147
  # Match the microarray probes to the query mask.
150
148
  # Record matched instances and their locations.
151
- measurements = []
152
- coordinates = []
153
- for measurement in self:
154
- pt = point.Point(measurement['mni_xyz'], space=mnispace, sigma_mm=LOCATION_PRECISION_MM)
155
- if pt in concept:
156
- measurements.append(measurement)
157
- coordinates.append(pt)
158
-
159
- if len(coordinates) == 0:
149
+ all_measurements = list(self)
150
+ all_mes_points = pointcloud.PointCloud(
151
+ [measurement['mni_xyz'] for measurement in all_measurements],
152
+ space='mni152',
153
+ sigma_mm=LOCATION_PRECISION_MM
154
+ )
155
+ intersecting_points = concept.intersection(all_mes_points)
156
+ if intersecting_points is None:
160
157
  logger.info(f"No probes found that lie within {concept}")
161
158
  return []
159
+ measurements = [all_measurements[index] for index in intersecting_points.labels]
162
160
 
163
161
  # Build the anatomical anchor and assignment to the query concept.
164
162
  # It will be attached to the returned feature, with the set of matched
165
163
  # MNI coordinates as anchor's location.
166
164
  anchor = _anchor.AnatomicalAnchor(
167
- location=pointcloud.from_points(coordinates),
165
+ location=intersecting_points,
168
166
  species=self.species
169
167
  )
170
168
  explanation = f"MNI coordinates of tissue samples were filtered using {concept}"