siibra 1.0a1__1-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.
- siibra/VERSION +1 -0
- siibra/__init__.py +164 -0
- siibra/commons.py +823 -0
- siibra/configuration/__init__.py +17 -0
- siibra/configuration/configuration.py +189 -0
- siibra/configuration/factory.py +589 -0
- siibra/core/__init__.py +16 -0
- siibra/core/assignment.py +110 -0
- siibra/core/atlas.py +239 -0
- siibra/core/concept.py +308 -0
- siibra/core/parcellation.py +387 -0
- siibra/core/region.py +1223 -0
- siibra/core/space.py +131 -0
- siibra/core/structure.py +111 -0
- siibra/exceptions.py +63 -0
- siibra/experimental/__init__.py +19 -0
- siibra/experimental/contour.py +61 -0
- siibra/experimental/cortical_profile_sampler.py +57 -0
- siibra/experimental/patch.py +98 -0
- siibra/experimental/plane3d.py +256 -0
- siibra/explorer/__init__.py +17 -0
- siibra/explorer/url.py +222 -0
- siibra/explorer/util.py +87 -0
- siibra/features/__init__.py +117 -0
- siibra/features/anchor.py +224 -0
- siibra/features/connectivity/__init__.py +33 -0
- siibra/features/connectivity/functional_connectivity.py +57 -0
- siibra/features/connectivity/regional_connectivity.py +494 -0
- siibra/features/connectivity/streamline_counts.py +27 -0
- siibra/features/connectivity/streamline_lengths.py +27 -0
- siibra/features/connectivity/tracing_connectivity.py +30 -0
- siibra/features/dataset/__init__.py +17 -0
- siibra/features/dataset/ebrains.py +90 -0
- siibra/features/feature.py +970 -0
- siibra/features/image/__init__.py +27 -0
- siibra/features/image/image.py +115 -0
- siibra/features/image/sections.py +26 -0
- siibra/features/image/volume_of_interest.py +88 -0
- siibra/features/tabular/__init__.py +24 -0
- siibra/features/tabular/bigbrain_intensity_profile.py +77 -0
- siibra/features/tabular/cell_density_profile.py +298 -0
- siibra/features/tabular/cortical_profile.py +322 -0
- siibra/features/tabular/gene_expression.py +257 -0
- siibra/features/tabular/layerwise_bigbrain_intensities.py +62 -0
- siibra/features/tabular/layerwise_cell_density.py +95 -0
- siibra/features/tabular/receptor_density_fingerprint.py +192 -0
- siibra/features/tabular/receptor_density_profile.py +110 -0
- siibra/features/tabular/regional_timeseries_activity.py +294 -0
- siibra/features/tabular/tabular.py +139 -0
- siibra/livequeries/__init__.py +19 -0
- siibra/livequeries/allen.py +352 -0
- siibra/livequeries/bigbrain.py +197 -0
- siibra/livequeries/ebrains.py +145 -0
- siibra/livequeries/query.py +49 -0
- siibra/locations/__init__.py +91 -0
- siibra/locations/boundingbox.py +454 -0
- siibra/locations/location.py +115 -0
- siibra/locations/point.py +344 -0
- siibra/locations/pointcloud.py +349 -0
- siibra/retrieval/__init__.py +27 -0
- siibra/retrieval/cache.py +233 -0
- siibra/retrieval/datasets.py +389 -0
- siibra/retrieval/exceptions/__init__.py +27 -0
- siibra/retrieval/repositories.py +769 -0
- siibra/retrieval/requests.py +659 -0
- siibra/vocabularies/__init__.py +45 -0
- siibra/vocabularies/gene_names.json +29176 -0
- siibra/vocabularies/receptor_symbols.json +210 -0
- siibra/vocabularies/region_aliases.json +460 -0
- siibra/volumes/__init__.py +23 -0
- siibra/volumes/parcellationmap.py +1279 -0
- siibra/volumes/providers/__init__.py +20 -0
- siibra/volumes/providers/freesurfer.py +113 -0
- siibra/volumes/providers/gifti.py +165 -0
- siibra/volumes/providers/neuroglancer.py +736 -0
- siibra/volumes/providers/nifti.py +266 -0
- siibra/volumes/providers/provider.py +107 -0
- siibra/volumes/sparsemap.py +468 -0
- siibra/volumes/volume.py +892 -0
- siibra-1.0.0a1.dist-info/LICENSE +201 -0
- siibra-1.0.0a1.dist-info/METADATA +160 -0
- siibra-1.0.0a1.dist-info/RECORD +84 -0
- siibra-1.0.0a1.dist-info/WHEEL +5 -0
- siibra-1.0.0a1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2018-2024
|
|
2
|
+
# Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
|
|
3
|
+
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
"""Handles reconfiguration management and building instances"""
|
|
16
|
+
|
|
17
|
+
from .configuration import Configuration
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Copyright 2018-2024
|
|
2
|
+
# Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
|
|
3
|
+
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
from ..commons import logger, __version__, SIIBRA_USE_CONFIGURATION, siibra_tqdm
|
|
17
|
+
from ..retrieval.repositories import GitlabConnector, RepositoryConnector, GithubConnector
|
|
18
|
+
from ..retrieval.exceptions import NoSiibraConfigMirrorsAvailableException
|
|
19
|
+
from ..retrieval.requests import SiibraHttpRequestError
|
|
20
|
+
|
|
21
|
+
from typing import Union, List
|
|
22
|
+
from collections import defaultdict
|
|
23
|
+
from requests.exceptions import ConnectionError
|
|
24
|
+
from os import path
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Configuration:
|
|
28
|
+
"""
|
|
29
|
+
Provides access to siibra configurations stored in different places,
|
|
30
|
+
and on request builds preconfigured objects from selected subfolders
|
|
31
|
+
of the the configuration.
|
|
32
|
+
|
|
33
|
+
Configuration repositories and detected preconfiguration spec files
|
|
34
|
+
are stored globally as class variables and shared by Configuration instances.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
CONFIG_REPOS = [
|
|
38
|
+
(GithubConnector, "FZJ-INM1-BDA", "siibra-configurations"),
|
|
39
|
+
(GitlabConnector, "https://gitlab.ebrains.eu", 892)
|
|
40
|
+
]
|
|
41
|
+
CONFIG_CONNECTORS: List[RepositoryConnector] = [
|
|
42
|
+
conn(
|
|
43
|
+
server_or_owner,
|
|
44
|
+
project_or_repo,
|
|
45
|
+
reftag="siibra-{}".format(__version__),
|
|
46
|
+
skip_branchtest=True
|
|
47
|
+
)
|
|
48
|
+
for conn, server_or_owner, project_or_repo in CONFIG_REPOS
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
CONFIG_EXTENSIONS = []
|
|
52
|
+
|
|
53
|
+
_cleanup_funcs = []
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def get_folders(connector: RepositoryConnector):
|
|
57
|
+
return {
|
|
58
|
+
path.dirname(f)
|
|
59
|
+
for f in connector.search_files(suffix='.json', recursive=True)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def __init__(self):
|
|
63
|
+
|
|
64
|
+
# lists of loaders for json specification files
|
|
65
|
+
# found in the siibra configuration, stored per
|
|
66
|
+
# preconfigured class name. These files can
|
|
67
|
+
# loaded and fed to the Factory.from_json
|
|
68
|
+
# to produce the corresponding object.
|
|
69
|
+
self.spec_loaders = defaultdict(list)
|
|
70
|
+
|
|
71
|
+
# retrieve json spec loaders from the default configuration
|
|
72
|
+
for connector in self.CONFIG_CONNECTORS:
|
|
73
|
+
try:
|
|
74
|
+
for folder in self.get_folders(connector):
|
|
75
|
+
loaders = connector.get_loaders(folder, suffix='.json')
|
|
76
|
+
if len(loaders) > 0:
|
|
77
|
+
self.spec_loaders[folder] = loaders
|
|
78
|
+
break
|
|
79
|
+
except (ConnectionError, SiibraHttpRequestError):
|
|
80
|
+
logger.error(f"Cannot load configuration from {str(connector)}")
|
|
81
|
+
*_, last = self.CONFIG_CONNECTORS
|
|
82
|
+
if connector is last:
|
|
83
|
+
raise NoSiibraConfigMirrorsAvailableException(
|
|
84
|
+
"Tried all mirrors, none available."
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
raise RuntimeError("Cannot pull any default siibra configuration.")
|
|
88
|
+
|
|
89
|
+
# add additional spec loaders from extension configurations
|
|
90
|
+
for connector in self.CONFIG_EXTENSIONS:
|
|
91
|
+
try:
|
|
92
|
+
for folder in self.get_folders(connector):
|
|
93
|
+
self.spec_loaders[folder].extend(
|
|
94
|
+
connector.get_loaders(folder, suffix='json')
|
|
95
|
+
)
|
|
96
|
+
break
|
|
97
|
+
except ConnectionError:
|
|
98
|
+
logger.error(f"Cannot connect to configuration extension {str(connector)}")
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
logger.debug(
|
|
102
|
+
"Preconfigurations: "
|
|
103
|
+
+ " | ".join(f"{folder}: {len(L)}" for folder, L in self.spec_loaders.items())
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def folders(self):
|
|
108
|
+
return list(self.spec_loaders.keys())
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def use_configuration(cls, conn: Union[str, RepositoryConnector]):
|
|
112
|
+
if isinstance(conn, str):
|
|
113
|
+
conn = RepositoryConnector._from_url(conn)
|
|
114
|
+
if not isinstance(conn, RepositoryConnector):
|
|
115
|
+
raise RuntimeError("Configuration needs to be an instance of RepositoryConnector or a valid str")
|
|
116
|
+
logger.info(f"Using custom configuration from {str(conn)}")
|
|
117
|
+
cls.CONFIG_CONNECTORS = [conn]
|
|
118
|
+
# call registered cleanup functions
|
|
119
|
+
for func in cls._cleanup_funcs:
|
|
120
|
+
func()
|
|
121
|
+
|
|
122
|
+
@classmethod
|
|
123
|
+
def extend_configuration(cls, conn: Union[str, RepositoryConnector]):
|
|
124
|
+
if isinstance(conn, str):
|
|
125
|
+
conn = RepositoryConnector._from_url(conn)
|
|
126
|
+
if not isinstance(conn, RepositoryConnector):
|
|
127
|
+
raise RuntimeError("conn needs to be an instance of RepositoryConnector or a valid str")
|
|
128
|
+
if conn in cls.CONFIG_EXTENSIONS:
|
|
129
|
+
logger.warning(f"The configuration {str(conn)} is already registered.")
|
|
130
|
+
else:
|
|
131
|
+
logger.info(f"Extending configuration with {str(conn)}")
|
|
132
|
+
cls.CONFIG_EXTENSIONS.append(conn)
|
|
133
|
+
# call registered cleanup functions
|
|
134
|
+
for func in cls._cleanup_funcs:
|
|
135
|
+
func()
|
|
136
|
+
|
|
137
|
+
@classmethod
|
|
138
|
+
def register_cleanup(cls, func):
|
|
139
|
+
"""
|
|
140
|
+
Register an arbitrary function that should be executed when the
|
|
141
|
+
configuration is changed, e.g. with use_configuration().
|
|
142
|
+
"""
|
|
143
|
+
cls._cleanup_funcs.append(func)
|
|
144
|
+
|
|
145
|
+
def build_objects(self, folder: str, **kwargs):
|
|
146
|
+
"""
|
|
147
|
+
Build the preconfigured objects of the specified class, if any.
|
|
148
|
+
"""
|
|
149
|
+
result = []
|
|
150
|
+
|
|
151
|
+
if folder not in self.folders:
|
|
152
|
+
logger.warning(f"No configuration found for building from configuration folder {folder}.")
|
|
153
|
+
return result
|
|
154
|
+
|
|
155
|
+
from .factory import Factory
|
|
156
|
+
specloaders = self.spec_loaders.get(folder, [])
|
|
157
|
+
if len(specloaders) == 0: # no loaders found in this configuration folder!
|
|
158
|
+
return result
|
|
159
|
+
|
|
160
|
+
obj0 = Factory.from_json(
|
|
161
|
+
dict(
|
|
162
|
+
specloaders[0][1].data,
|
|
163
|
+
**{'filename': specloaders[0][0]}
|
|
164
|
+
)
|
|
165
|
+
)
|
|
166
|
+
obj_class = obj0[0].__class__.__name__ if isinstance(obj0, list) else obj0.__class__.__name__
|
|
167
|
+
|
|
168
|
+
for fname, loader in siibra_tqdm(
|
|
169
|
+
specloaders,
|
|
170
|
+
total=len(specloaders),
|
|
171
|
+
desc=f"Loading preconfigured {obj_class} instances",
|
|
172
|
+
unit=obj_class
|
|
173
|
+
):
|
|
174
|
+
# filename is added to allow Factory creating reasonable default object identifiers\
|
|
175
|
+
obj = Factory.from_json(dict(loader.data, **{'filename': fname}))
|
|
176
|
+
if isinstance(obj, list):
|
|
177
|
+
result.extend(obj)
|
|
178
|
+
else:
|
|
179
|
+
result.append(obj)
|
|
180
|
+
|
|
181
|
+
return result
|
|
182
|
+
|
|
183
|
+
def __getitem__(self, folder: str):
|
|
184
|
+
return self.build_objects(folder)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if SIIBRA_USE_CONFIGURATION:
|
|
188
|
+
logger.warning(f"config.SIIBRA_USE_CONFIGURATION defined, use configuration at {SIIBRA_USE_CONFIGURATION}")
|
|
189
|
+
Configuration.use_configuration(SIIBRA_USE_CONFIGURATION)
|