-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path__init__.py
153 lines (126 loc) · 4.33 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2018-2021
# Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Jülich GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .commons import (
logger,
QUIET,
VERBOSE,
MapType,
MapIndex,
set_log_level,
__version__
)
from .core import (
atlas as _atlas,
parcellation as _parcellation,
space as _space
)
from .volumes import parcellationmap as _parcellationmap
from .retrieval.requests import (
EbrainsRequest as _EbrainsRequest,
CACHE as cache
)
from .retrieval.cache import Warmup, WarmupLevel
from . import configuration
from .configuration import factory
from . import features, livequeries
from siibra.locations import Point, PointSet
import os as _os
logger.info(f"Version: {__version__}")
logger.warning("This is a development release. Use at your own risk.")
logger.info(
"Please file bugs and issues at https://github.com/FZJ-INM1-BDA/siibra-python."
)
# forward access to some functions
set_ebrains_token = _EbrainsRequest.set_token
fetch_ebrains_token = _EbrainsRequest.fetch_token
find_regions = _parcellation.Parcellation.find_regions
from_json = factory.Factory.from_json
def __getattr__(attr: str):
# lazy loading of some classes for package-level functions.
if attr == 'atlases':
return _atlas.Atlas.registry()
elif attr == 'spaces':
return _space.Space.registry()
elif attr == 'parcellations':
return _parcellation.Parcellation.registry()
elif attr == 'maps':
return _parcellationmap.Map.registry()
elif attr == 'use_configuration':
return configuration.Configuration.use_configuration
elif attr == 'extend_configuration':
return configuration.Configuration.extend_configuration
else:
raise AttributeError(f"No such attribute: {__name__}.{attr}")
# convenient access to reference space templates
def get_template(space_spec: str, **kwargs):
return (
_space.Space
.get_instance(space_spec)
.get_template(**kwargs)
)
# convenient access to parcellation maps
def get_map(parcellation: str, space: str, maptype: MapType = MapType.LABELLED, **kwargs):
return (
_parcellation.Parcellation
.get_instance(parcellation)
.get_map(space=space, maptype=maptype, **kwargs)
)
# convenient access to regions of a parcellation
def get_region(parcellation: str, region: str):
return (
_parcellation.Parcellation
.get_instance(parcellation)
.get_region(region)
)
def set_feasible_download_size(maxsize_gbyte):
from .volumes import volume
volume.gbyte_feasible = maxsize_gbyte
logger.info(f"Set feasible download size to {maxsize_gbyte} GiB.")
def set_cache_size(maxsize_gbyte: int):
assert maxsize_gbyte >= 0
cache.SIZE_GIB = maxsize_gbyte
logger.info(f"Set cache size to {maxsize_gbyte} GiB.")
if "SIIBRA_CACHE_SIZE_GIB" in _os.environ:
set_cache_size(float(_os.environ.get("SIIBRA_CACHE_SIZE_GIB")))
def warm_cache(level=WarmupLevel.INSTANCE):
"""
Preload preconfigured siibra concepts.
Siibra relies on preconfigurations that simplify integrating various
concepts such as parcellations, refernce spaces, and multimodal data
features. By preloading the instances, siibra commits all preconfigurations
to the memory at once instead of commiting them when required.
"""
Warmup.warmup(level)
def __dir__():
return [
"atlases",
"spaces",
"parcellations",
"features",
"use_configuration",
"extend_configuration",
"get_region",
"find_regions",
"get_map",
"get_template",
"MapType",
"Point",
"PointSet",
"QUIET",
"VERBOSE",
"fetch_ebrains_token",
"set_ebrains_token",
"vocabularies",
"__version__",
"cache",
"warm_cache"
]