Skip to content

Commit b04fa74

Browse files
committed
Merge branch 'main' of github.com:FZJ-INM1-BDA/siibra-python
2 parents e589fa7 + 3b8e518 commit b04fa74

File tree

12 files changed

+72
-80
lines changed

12 files changed

+72
-80
lines changed

docs/developer.rst

+60-62
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
=======================
12
Developer documentation
23
=======================
34

45

56
Object instantiation
6-
--------------------
7+
====================
78

89
Since siibra creates many objects in a typical workflow, the creation of objects is following a clear structure.
910
There are two main approaches of object creation:
1011

1112
1. Preconfigured objects, via the configuration module. This happens automatically for
12-
- subclasses of `AtlasConcept`, if the class parameter `configuration_folder` points to a subfolder of siibra configuration repositories.
13+
- subclasses of :class:`AtlasConcept`, if the class parameter :attr:`configuration_folder` points to a subfolder of siibra configuration repositories.
1314
- subclasses of `Feature`, if the class parameter `configuration_folder` points to a subfolder of siibra configuration repositories.
1415
the implementation of these queries is centralized in `AtlasConcept.get_instances()` and `Feature.get_instances()`, respectively,
1516
and relies on the registrations done in `AtlasConcept.__init_subclass__()` and `Feature.__init_subclass__()`.
17+
1618
2. Live queries, via the livequery module. This applies to subclasses of `Feature`, and relies on subclasses of `LiveQuery`
1719
with the class parameter `FeatureType` set to the corresponding subclass of `Feature`. This triggers the query to be registered
1820
in the `Feature._live_queries` list via `LiveQuery.__init_subclass__()`. Any registered live queries will then automatically be called
@@ -25,12 +27,13 @@ Instances of `Feature` subclasses are just stored as a list at class level.
2527

2628

2729
Frequently used design patterns
28-
-------------------------------
30+
===============================
2931

3032
``siibra`` makes frequent use of some typical design patterns.
3133

3234

33-
**Importing local classes**
35+
Importing local classes
36+
-----------------------
3437

3538
Often, siibra implementations make use of classes from different siibra modules.
3639
It is common Python practice to do all imports at the start of a file, and not locally inside functions / classes.
@@ -64,7 +67,8 @@ and use module imports in other python files.
6467
However, this rule of thumb is not yet consistently implemented and verified in siibra.
6568

6669

67-
**Lazy loading via object properties.**
70+
Lazy loading via object properties
71+
----------------------------------
6872

6973
Since siibra pre-configures many objects, of which the user will typically only use a few
7074
(e.g. after filternig data features by brain regions), it is important that time and/or memory
@@ -89,64 +93,58 @@ following this scheme:
8993
9094
9195
The design of volumes and fetching mechanism
92-
--------------------------------------------
93-
94-
**Basic definitions and notes**
95-
96-
- Volume: is a complete 3D object, typically a complete brain.
97-
- Volume provider: is a resource that provides access to volumes. A volume can have multiple
98-
providers in different formats.
99-
- Variant: refers to alternative representations of the same volume. (e.g. inflated surface)
100-
- If the volume has variants, they need to be listed in the configuration file.
101-
- Fragments: are individually addressable components of a volume.
102-
- If a volume has fragments, either the user or the code needs to retrieve from multiple
103-
sources to access the complete volume.
104-
- Fragments need to be named (e.g. left and right hemisphere), because they inevitably
105-
split the whole object into distinct anatomical parts that require semantic labeling.
106-
- Brain regions (label): are structures mapped inside a specific volume or fragment.
107-
- The structure appears by interpreting the labels inside the volume listed in the
108-
configuration file.
109-
- In special cases, a brain region could be represented by the complete volume or
110-
fragment.
111-
- Volume index: the index of the volume in case there is more than one; typically used for
112-
probability maps, where each area has a different volume.
113-
- Z: for 4D volumes, it specifies the 4th coordinate identifying an actual 3D volume. It has
114-
a similar function as the volume index, only that the volumes are concatenated in one array and
115-
share the same affine transformation.
116-
- Source type (format): the format of the volume data.
117-
- See PREFERRED_FORMATS and SURFACE_FORMATS at volumes.volume.py for the currently
118-
supported formats.
119-
120-
**Fetching volumes**
96+
============================================
97+
98+
Basic definitions and notes
99+
---------------------------
100+
101+
**Volume:** is a complete 3D object, typically a complete brain.
102+
103+
**Volume provider:** is a resource that provides access to volumes. A volume can have multiple providers in different formats.
104+
105+
**Variant:** refers to alternative representations of the same volume. (e.g. inflated surface).
106+
107+
* If the volume has variants, they need to be listed in the configuration file.
108+
109+
**Fragments:** are individually addressable components of a volume.
110+
111+
* If a volume has fragments, either the user or the code needs to retrieve from multiple sources to access the complete volume.
112+
* Fragments need to be named (e.g. left and right hemisphere), because they inevitably split the whole object into distinct anatomical parts that require semantic labeling.
113+
114+
**Brain regions (label):** are structures mapped inside a specific volume or fragment.
115+
116+
* The structure appears by interpreting the labels inside the volume listed in the configuration file.
117+
* In special cases, a brain region could be represented by the complete volume or fragment.
118+
119+
**Volume index:** the index of the volume in case there is more than one; typically used for probability maps, where each area has a different volume.
120+
121+
**Z:** for 4D volumes, it specifies the 4th coordinate identifying an actual 3D volume. It has a similar function as the volume index, only that the volumes are concatenated in one array and share the same affine transformation.
122+
123+
**Source type (format):** the format of the volume data.
124+
125+
* See :data:`SUPPORTED_FORMATS` (:data:`IMAGE_FORMATS` and :data:`SURFACE_FORMATS`) at volumes.volume.py for the currently supported formats.
126+
127+
Fetching volumes
128+
----------------
121129

122130
Fetching volumes occurs in two main stages:
131+
123132
1) The determination of the volume by the user
124-
- The user sets the object they would like to fetch a volume from:
125-
i) a space template -> using get_template() which provides a volume template.
126-
ii) or a map -> getting the desired map by setting desired specs.
127-
- The user invokes fetch() method to retrieve the volume from the template or map.
128-
i) template directly access to volume.fetch()
129-
ii) fetch() first goes through map.fetch()
130-
2) Actual retrieval of the volume object by siibra after the user asks for the volume via
131-
`fetch()` method. When fetch() is invoked it accesses to corresponding volume provider
132-
based on the specifications given by volume index, fragment, z, label, variant, and format.
133-
According to the source type, the provider invokes the correct class and fetches the
134-
data accordingly.
135-
136-
Defaults:
137-
- Volume with several variants: the first variant listed in the configuration is fetched.
138-
The user is informed along with a list of possible variants.
139-
- Volume with several fragments: All fragments are retrieved and combined to provide
140-
the whole volume. (This may cause some array length issues on the user end so the user
141-
should be informed. Potentially, this may be changed to fetch only the first fragment
142-
along with info and a list of options.)
143-
144-
Implementation Notes:
145-
- When adjusting to a new type of data or special cases, it is highly encouraged to use
146-
one of the existing parameters.
147-
- Always inform a user when there are options available and the default is chosen.
133+
* The user sets the object they would like to fetch a volume from:
134+
- a space template -> using `get_template()`` which provides a volume template.
135+
- or a map -> getting the desired map by setting desired specs.
136+
* The user invokes `fetch()`` method to retrieve the volume from the template or map.
137+
* template directly access to `volume.fetch()`
138+
* `fetch()` first goes through `map.fetch()`
139+
2) Actual retrieval of the volume object by siibra after the user asks for the volume via `fetch()` method.
140+
When `fetch()` is invoked it accesses to corresponding volume provider based on the specifications given by volume index, fragment, z, label, variant, and format. According to the source type, the provider invokes the correct class and fetches the data accordingly.
141+
142+
**Defaults:**
143+
144+
- Volume with several variants: the first variant listed in the configuration is fetched. The user is informed along with a list of possible variants.
145+
- Volume with several fragments: All fragments are retrieved and combined to provide the whole volume. (This may cause some array length issues on the user end so the user should be informed. Potentially, this may be changed to fetch only the first fragment along with info and a list of options.)
148146

149-
TO-DO:
150-
- Remove meshindex parameter from NGmesh and replace it with one of the other parameters.
151-
- Implement a default way to list the variants and fragments?
152-
- A new mesh_util module or a toolbox/extension to handle mesh-related computations?
147+
**Implementation Notes**
148+
149+
- When adjusting to a new type of data or special cases, it is highly encouraged to use one of the existing parameters.
150+
- Always inform a user when there are options available and the default is chosen.

examples/01_atlases_and_parcellations/000_accessing_atlases.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
# %%
30+
# sphinx_gallery_thumbnail_path = '_static/example_thumbnails/default_thumbnail.png'
3031
# We start by loading the library
3132
import siibra
3233

siibra/commons.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
"""Constants, functions, and classes used commonly across siibra."""
1616
import os
1717
import re
1818
from enum import Enum

siibra/core/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
"""
16-
:ref:`Main siibra concepts<mainconcepts>`
17-
"""
15+
""":ref:`Main siibra concepts<mainconcepts>`"""
1816
from . import atlas, parcellation, space

siibra/core/atlas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
"""Provides reference systems for brains."""
1616
from . import concept, space as _space, parcellation as _parcellation
1717

1818
from ..commons import MapType, logger, InstanceTable, Species

siibra/core/concept.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
16-
15+
"""Parent class to siibra main concepts."""
1716
from ..commons import create_key, clear_name, logger, InstanceTable, Species
1817

1918
import re

siibra/core/parcellation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
"""Hierarchal brain regions and metadata."""
1616
from . import region
1717

1818
from ..commons import logger, MapType, MapIndex, Species

siibra/core/region.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
"""Representation of a brain region."""
1616
from . import concept, space as _space, parcellation as _parcellation
1717

1818
from ..locations import boundingbox, point, pointset

siibra/core/space.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""A particular brain reference space."""
1516

1617

1718
from .concept import AtlasConcept
@@ -26,9 +27,6 @@
2627

2728

2829
class Space(AtlasConcept, configuration_folder="spaces"):
29-
"""
30-
A particular brain reference space.
31-
"""
3230

3331
def __init__(
3432
self,

siibra/volumes/parcellationmap.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
"""Parcellation maps and region maps are 3D volumes, providing spatial representations
16-
for their "semantic counterparts" `Parcellation` and `Region` in a particular
17-
reference space."""
15+
"""Provides spatial representations for parcellations and regions."""
1816

1917
from . import volume as _volume, nifti
2018
from .. import logger, QUIET

siibra/volumes/sparsemap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
15+
"""Represents lists of probabilistic brain region maps."""
1616
from . import parcellationmap, volume as _volume
1717

1818
from ..commons import MapIndex, logger

siibra/volumes/volume.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
"""Base volume class. A volume is a specific mesh or 3D array."""
15+
"""A specific mesh or 3D array."""
1616
from .. import logger
1717
from ..retrieval import requests
1818
from ..core import space
@@ -136,7 +136,7 @@ def fetch(
136136
starting with volumetric formats. You may explicitly specify:
137137
- 'surface' or 'mesh' to fetch a surface format
138138
- 'volumetric' or 'voxel' to fetch a volumetric format
139-
- supported format types, see Volume.PREFERRED_FORMATS. This includes:
139+
- supported format types, see :data:`Volume.SUPPORTED_FORMATS`. This includes:
140140
:class:`'nii'<siibra.volumes.nifti.NiftiProvider()>`,
141141
:class:`'zip/nii'<siibra.volumes.nifti.ZipContainedNiftiProvider()>`,
142142
:class:`'neuroglancer/precomputed'<siibra.volumes.neuroglancer.NeuroglancerProvider()>`,

0 commit comments

Comments
 (0)