siibra 0.5a2__py3-none-any.whl → 1.0.0a1__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 (83) hide show
  1. siibra/VERSION +1 -1
  2. siibra/__init__.py +20 -12
  3. siibra/commons.py +145 -90
  4. siibra/configuration/__init__.py +1 -1
  5. siibra/configuration/configuration.py +22 -17
  6. siibra/configuration/factory.py +177 -128
  7. siibra/core/__init__.py +1 -8
  8. siibra/core/{relation_qualification.py → assignment.py} +17 -14
  9. siibra/core/atlas.py +66 -35
  10. siibra/core/concept.py +81 -39
  11. siibra/core/parcellation.py +83 -67
  12. siibra/core/region.py +569 -263
  13. siibra/core/space.py +7 -39
  14. siibra/core/structure.py +111 -0
  15. siibra/exceptions.py +63 -0
  16. siibra/experimental/__init__.py +19 -0
  17. siibra/experimental/contour.py +61 -0
  18. siibra/experimental/cortical_profile_sampler.py +57 -0
  19. siibra/experimental/patch.py +98 -0
  20. siibra/experimental/plane3d.py +256 -0
  21. siibra/explorer/__init__.py +16 -0
  22. siibra/explorer/url.py +112 -52
  23. siibra/explorer/util.py +31 -9
  24. siibra/features/__init__.py +73 -8
  25. siibra/features/anchor.py +75 -196
  26. siibra/features/connectivity/__init__.py +1 -1
  27. siibra/features/connectivity/functional_connectivity.py +2 -2
  28. siibra/features/connectivity/regional_connectivity.py +99 -10
  29. siibra/features/connectivity/streamline_counts.py +1 -1
  30. siibra/features/connectivity/streamline_lengths.py +1 -1
  31. siibra/features/connectivity/tracing_connectivity.py +1 -1
  32. siibra/features/dataset/__init__.py +1 -1
  33. siibra/features/dataset/ebrains.py +3 -3
  34. siibra/features/feature.py +219 -110
  35. siibra/features/image/__init__.py +1 -1
  36. siibra/features/image/image.py +21 -13
  37. siibra/features/image/sections.py +1 -1
  38. siibra/features/image/volume_of_interest.py +1 -1
  39. siibra/features/tabular/__init__.py +1 -1
  40. siibra/features/tabular/bigbrain_intensity_profile.py +24 -13
  41. siibra/features/tabular/cell_density_profile.py +111 -69
  42. siibra/features/tabular/cortical_profile.py +82 -16
  43. siibra/features/tabular/gene_expression.py +117 -6
  44. siibra/features/tabular/layerwise_bigbrain_intensities.py +7 -9
  45. siibra/features/tabular/layerwise_cell_density.py +9 -24
  46. siibra/features/tabular/receptor_density_fingerprint.py +11 -6
  47. siibra/features/tabular/receptor_density_profile.py +12 -15
  48. siibra/features/tabular/regional_timeseries_activity.py +74 -18
  49. siibra/features/tabular/tabular.py +17 -8
  50. siibra/livequeries/__init__.py +1 -7
  51. siibra/livequeries/allen.py +139 -77
  52. siibra/livequeries/bigbrain.py +104 -128
  53. siibra/livequeries/ebrains.py +7 -4
  54. siibra/livequeries/query.py +1 -2
  55. siibra/locations/__init__.py +32 -25
  56. siibra/locations/boundingbox.py +153 -127
  57. siibra/locations/location.py +45 -80
  58. siibra/locations/point.py +97 -83
  59. siibra/locations/pointcloud.py +349 -0
  60. siibra/retrieval/__init__.py +1 -1
  61. siibra/retrieval/cache.py +107 -13
  62. siibra/retrieval/datasets.py +9 -14
  63. siibra/retrieval/exceptions/__init__.py +2 -1
  64. siibra/retrieval/repositories.py +147 -53
  65. siibra/retrieval/requests.py +64 -29
  66. siibra/vocabularies/__init__.py +2 -2
  67. siibra/volumes/__init__.py +7 -9
  68. siibra/volumes/parcellationmap.py +396 -253
  69. siibra/volumes/providers/__init__.py +20 -0
  70. siibra/volumes/providers/freesurfer.py +113 -0
  71. siibra/volumes/{gifti.py → providers/gifti.py} +29 -18
  72. siibra/volumes/{neuroglancer.py → providers/neuroglancer.py} +204 -92
  73. siibra/volumes/{nifti.py → providers/nifti.py} +64 -44
  74. siibra/volumes/providers/provider.py +107 -0
  75. siibra/volumes/sparsemap.py +159 -260
  76. siibra/volumes/volume.py +720 -152
  77. {siibra-0.5a2.dist-info → siibra-1.0.0a1.dist-info}/METADATA +25 -28
  78. siibra-1.0.0a1.dist-info/RECORD +84 -0
  79. {siibra-0.5a2.dist-info → siibra-1.0.0a1.dist-info}/WHEEL +1 -1
  80. siibra/locations/pointset.py +0 -198
  81. siibra-0.5a2.dist-info/RECORD +0 -74
  82. {siibra-0.5a2.dist-info → siibra-1.0.0a1.dist-info}/LICENSE +0 -0
  83. {siibra-0.5a2.dist-info → siibra-1.0.0a1.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,16 +19,16 @@ from ..tabular.tabular import Tabular
19
19
 
20
20
  from .. import anchor as _anchor
21
21
 
22
- from ...commons import logger, QUIET
22
+ from ...commons import logger, QUIET, siibra_tqdm
23
23
  from ...core import region as _region
24
- from ...locations import pointset
24
+ from ...locations import pointcloud
25
25
  from ...retrieval.repositories import RepositoryConnector
26
26
  from ...retrieval.requests import HttpRequest
27
27
 
28
28
 
29
29
  import pandas as pd
30
30
  import numpy as np
31
- from typing import Callable, Union, List
31
+ from typing import Callable, Union, List, Tuple, Iterator
32
32
 
33
33
  try:
34
34
  from typing import Literal
@@ -57,7 +57,9 @@ class RegionalConnectivity(Feature, Compoundable):
57
57
  description: str = "",
58
58
  datasets: list = [],
59
59
  subject: str = "average",
60
- feature: str = None
60
+ feature: str = None,
61
+ id: str = None,
62
+ prerelease: bool = False,
61
63
  ):
62
64
  """
63
65
  Construct a parcellation-averaged connectivity matrix.
@@ -91,6 +93,8 @@ class RegionalConnectivity(Feature, Compoundable):
91
93
  description=description,
92
94
  anchor=anchor,
93
95
  datasets=datasets,
96
+ id=id,
97
+ prerelease=prerelease
94
98
  )
95
99
  self.cohort = cohort.upper()
96
100
  if isinstance(connector, str) and connector:
@@ -116,7 +120,7 @@ class RegionalConnectivity(Feature, Compoundable):
116
120
 
117
121
  @property
118
122
  def name(self):
119
- return f"{super().name} with cohort {self.cohort} - {self.feature or self.subject}"
123
+ return f"{self.feature or self.subject} - " + super().name + f" cohort: {self.cohort}"
120
124
 
121
125
  @property
122
126
  def data(self) -> pd.DataFrame:
@@ -132,6 +136,45 @@ class RegionalConnectivity(Feature, Compoundable):
132
136
  self._load_matrix()
133
137
  return self._matrix.copy()
134
138
 
139
+ @classmethod
140
+ def _merge_elements(
141
+ cls,
142
+ elements: List["RegionalConnectivity"],
143
+ description: str,
144
+ modality: str,
145
+ anchor: _anchor.AnatomicalAnchor,
146
+ ):
147
+ assert len({f.cohort for f in elements}) == 1
148
+ merged = cls(
149
+ cohort=elements[0].cohort,
150
+ regions=elements[0].regions,
151
+ connector=elements[0]._connector,
152
+ decode_func=elements[0]._decode_func,
153
+ filename="",
154
+ subject="average",
155
+ feature="average",
156
+ description=description,
157
+ modality=modality,
158
+ anchor=anchor,
159
+ **{"paradigm": "averaged (by siibra)"} if getattr(elements[0], "paradigm", None) else {}
160
+ )
161
+ if isinstance(elements[0]._connector, HttpRequest):
162
+ getter = lambda elm: elm._connector.get()
163
+ else:
164
+ getter = lambda elm: elm._connector.get(elm._filename, decode_func=elm._decode_func)
165
+ all_arrays = [
166
+ getter(elm)
167
+ for elm in siibra_tqdm(
168
+ elements,
169
+ total=len(elements),
170
+ desc=f"Averaging {len(elements)} connectivity matrices"
171
+ )
172
+ ]
173
+ merged._matrix = elements[0]._arraylike_to_dataframe(
174
+ np.stack(all_arrays).mean(0)
175
+ )
176
+ return merged
177
+
135
178
  def _plot_matrix(
136
179
  self, regions: List[str] = None,
137
180
  logscale: bool = False, *args, backend="nilearn", **kwargs
@@ -179,6 +222,7 @@ class RegionalConnectivity(Feature, Compoundable):
179
222
  **kwargs
180
223
  )
181
224
  elif backend == "plotly":
225
+ kwargs["title"] = kwargs["title"].replace("\n", "<br>")
182
226
  from plotly.express import imshow
183
227
  return imshow(matrix, *args, x=regions, y=regions, **kwargs)
184
228
  else:
@@ -186,8 +230,8 @@ class RegionalConnectivity(Feature, Compoundable):
186
230
  f"Plotting connectivity matrices with {backend} is not supported."
187
231
  )
188
232
 
189
- def _export(self, fh: ZipFile):
190
- super()._export(fh)
233
+ def _to_zip(self, fh: ZipFile):
234
+ super()._to_zip(fh)
191
235
  if self.feature is None:
192
236
  fh.writestr(f"sub/{self._filename}/matrix.csv", self.data.to_csv())
193
237
  else:
@@ -208,7 +252,6 @@ class RegionalConnectivity(Feature, Compoundable):
208
252
  Parameters
209
253
  ----------
210
254
  region: str, Region
211
- subject: str, default: None
212
255
  min_connectivity: float, default: 0
213
256
  Regions with connectivity less than this value are discarded.
214
257
  max_rows: int, default: None
@@ -297,6 +340,7 @@ class RegionalConnectivity(Feature, Compoundable):
297
340
  kwargs["kind"] = kwargs.get("kind", "barh")
298
341
  if backend == "matplotlib":
299
342
  kwargs["logx"] = kwargs.get("logx", logscale)
343
+ return profile.data.plot(*args, backend=backend, **kwargs)
300
344
  elif backend == "plotly":
301
345
  kwargs.update({
302
346
  "color": kwargs.get("color", profile.data.columns[0]),
@@ -320,6 +364,51 @@ class RegionalConnectivity(Feature, Compoundable):
320
364
  else:
321
365
  return profile.data.plot(*args, backend=backend, **kwargs)
322
366
 
367
+ def get_profile_colorscale(
368
+ self,
369
+ region: Union[str, _region.Region],
370
+ min_connectivity: float = 0,
371
+ max_rows: int = None,
372
+ direction: Literal['column', 'row'] = 'column',
373
+ colorgradient: str = "jet"
374
+ ) -> Iterator[Tuple[_region.Region, Tuple[int, int, int]]]:
375
+ """
376
+ Extract the colorscale corresponding to the regional profile from the
377
+ matrix sorted by the values. See `get_profile` for further details.
378
+
379
+ Note:
380
+ -----
381
+ Requires `plotly`.
382
+
383
+ Parameters
384
+ ----------
385
+ region: str, Region
386
+ min_connectivity: float, default: 0
387
+ Regions with connectivity less than this value are discarded.
388
+ max_rows: int, default: None
389
+ Max number of regions with highest connectivity.
390
+ direction: str, default: 'column'
391
+ Choose the direction of profile extraction particularly for
392
+ non-symmetric matrices. ('column' or 'row')
393
+ colorgradient: str, default: 'jet'
394
+ The gradient used to extract colorscale.
395
+ Returns
396
+ -------
397
+ Iterator[Tuple[_region.Region, Tuple[int, int, int]]]
398
+ Color values are in RGB 255.
399
+ """
400
+ from plotly.express.colors import sample_colorscale
401
+ profile = self.get_profile(region, min_connectivity, max_rows, direction)
402
+ normalized = profile.data / profile.data.max()
403
+ colorscale = sample_colorscale(
404
+ colorgradient,
405
+ normalized.values.reshape(len(profile.data))
406
+ )
407
+ return zip(
408
+ profile.data.index.values,
409
+ [eval(c.removeprefix('rgb')) for c in colorscale]
410
+ )
411
+
323
412
  def __len__(self):
324
413
  return len(self._filename)
325
414
 
@@ -351,7 +440,7 @@ class RegionalConnectivity(Feature, Compoundable):
351
440
  found = [r for r in region if r.name in all_centroids]
352
441
  assert len(found) > 0
353
442
  result.append(
354
- tuple(pointset.PointSet(
443
+ tuple(pointcloud.PointCloud(
355
444
  [all_centroids[r.name] for r in found], space=space
356
445
  ).centroid)
357
446
  )
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
- # Copyright 2018-2021
1
+ # Copyright 2018-2024
2
2
  # Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -85,6 +85,6 @@ class EbrainsDataFeature(feature.Feature, category="other"):
85
85
  return False
86
86
  return self._dataset == o._dataset
87
87
 
88
- def _export(self, fh: ZipFile):
89
- super()._export(fh)
88
+ def _to_zip(self, fh: ZipFile):
89
+ super()._to_zip(fh)
90
90
  fh.writestr("doi.md", DOI_TMPL.format(doi=self.url))