Skip to content

Commit 18cd2a0

Browse files
authored
Merge pull request #646 from FZJ-INM1-BDA/maint_imports_and_packages
Maint imports and packages
2 parents cf6c006 + 36ccfc8 commit 18cd2a0

File tree

10 files changed

+62
-69
lines changed

10 files changed

+62
-69
lines changed

siibra/core/region.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
# limitations under the License.
1515
"""Representation of a brain region."""
1616

17-
from . import concept, structure, space as _space, parcellation as _parcellation
18-
from .assignment import Qualification, AnatomicalAssignment
19-
17+
from . import concept, structure, space as _space, parcellation as _parcellation, assignment
2018
from ..retrieval.cache import cache_user_fn
2119
from ..locations import location, pointcloud, boundingbox as _boundingbox
2220
from ..volumes import parcellationmap, volume
@@ -128,7 +126,7 @@ def get_related_regions(self) -> Iterable["RegionRelationAssessments"]:
128126
129127
Yields
130128
------
131-
Qualification
129+
assignment.Qualification
132130
133131
Example
134132
-------
@@ -595,7 +593,7 @@ def __contains__(self, other: Union[location.Location, 'Region']) -> bool:
595593
except NoMapAvailableError:
596594
return False
597595

598-
def assign(self, other: structure.BrainStructure) -> AnatomicalAssignment:
596+
def assign(self, other: structure.BrainStructure) -> assignment.AnatomicalAssignment:
599597
"""
600598
Compute assignment of a location to this region.
601599
@@ -609,8 +607,8 @@ def assign(self, other: structure.BrainStructure) -> AnatomicalAssignment:
609607
610608
Returns
611609
-------
612-
AnatomicalAssignment or None
613-
None if there is no Qualification found.
610+
assignment.AnatomicalAssignment or None
611+
None if there is no assignment.Qualification found.
614612
"""
615613
if (self, other) in self._ASSIGNMENT_CACHE:
616614
return self._ASSIGNMENT_CACHE[self, other]
@@ -659,17 +657,17 @@ def assign(self, other: structure.BrainStructure) -> AnatomicalAssignment:
659657
else: # other is a Region
660658
assert isinstance(other, Region)
661659
if self == other:
662-
qualification = Qualification.EXACT
660+
qualification = assignment.Qualification.EXACT
663661
elif self.__contains__(other):
664-
qualification = Qualification.CONTAINS
662+
qualification = assignment.Qualification.CONTAINS
665663
elif other.__contains__(self):
666-
qualification = Qualification.CONTAINED
664+
qualification = assignment.Qualification.CONTAINED
667665
else:
668666
qualification = None
669667
if qualification is None:
670668
self._ASSIGNMENT_CACHE[self, other] = None
671669
else:
672-
self._ASSIGNMENT_CACHE[self, other] = AnatomicalAssignment(self, other, qualification)
670+
self._ASSIGNMENT_CACHE[self, other] = assignment.AnatomicalAssignment(self, other, qualification)
673671
return self._ASSIGNMENT_CACHE[self, other]
674672

675673
def tree2str(self):
@@ -926,7 +924,7 @@ def get_related_regions(region: Region) -> Iterable["RegionRelationAssessments"]
926924
927925
Yields
928926
------
929-
Qualification
927+
assignment.Qualification
930928
931929
Example
932930
-------
@@ -968,7 +966,7 @@ def inner(*args, **kwargs):
968966
return outer
969967

970968

971-
class RegionRelationAssessments(AnatomicalAssignment[Region]):
969+
class RegionRelationAssessments(assignment.AnatomicalAssignment[Region]):
972970
"""
973971
A collection of methods on finding related regions and the quantification
974972
of the relationship.
@@ -1110,7 +1108,7 @@ def parse_relationship_assessment(cls, src: "Region", assessment):
11101108
yield cls(
11111109
query_structure=src,
11121110
assigned_structure=found_target,
1113-
qualification=Qualification.parse_relation_assessment(overlap)
1111+
qualification=assignment.Qualification.parse_relation_assessment(overlap)
11141112
)
11151113

11161114
if "https://openminds.ebrains.eu/sands/ParcellationEntity" in target.get("type"):
@@ -1124,7 +1122,7 @@ def parse_relationship_assessment(cls, src: "Region", assessment):
11241122
yield cls(
11251123
query_structure=src,
11261124
assigned_structure=reg,
1127-
qualification=Qualification.parse_relation_assessment(overlap)
1125+
qualification=assignment.Qualification.parse_relation_assessment(overlap)
11281126
)
11291127

11301128
@classmethod
@@ -1178,7 +1176,7 @@ def translate_pes(cls, src: "Region", _id: Union[str, List[str]]):
11781176
yield cls(
11791177
query_structure=src,
11801178
assigned_structure=region,
1181-
qualification=Qualification.OTHER_VERSION
1179+
qualification=assignment.Qualification.OTHER_VERSION
11821180
)
11831181

11841182
# homologuous

siibra/core/space.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"""A particular brain reference space."""
1616

1717

18-
from .concept import AtlasConcept
19-
18+
from . import concept
2019
from ..commons import logger, Species
2120

2221
from typing import List, TYPE_CHECKING, Union
@@ -25,7 +24,7 @@
2524
from ..volumes import volume
2625

2726

28-
class Space(AtlasConcept, configuration_folder="spaces"):
27+
class Space(concept.AtlasConcept, configuration_folder="spaces"):
2928

3029
def __init__(
3130
self,
@@ -66,7 +65,7 @@ def __init__(
6665
Key: EBRAINS KG schema, value: EBRAINS KG @id
6766
"""
6867

69-
AtlasConcept.__init__(
68+
concept.AtlasConcept.__init__(
7069
self,
7170
identifier=identifier,
7271
name=name,

siibra/features/tabular/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Multimodal data features in tabular formats."""
1616

1717
from .bigbrain_intensity_profile import BigBrainIntensityProfile
18-
from .cell_density_profile import CellDensityProfile
18+
from .cell_density_profile import CellDensityProfile, cell_reader, layer_reader
1919
from .gene_expression import GeneExpressions
2020
from .layerwise_bigbrain_intensities import LayerwiseBigBrainIntensities
2121
from .layerwise_cell_density import LayerwiseCellDensity

siibra/features/tabular/layerwise_cell_density.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
# limitations under the License.
1515

1616
from . import cortical_profile
17+
from . import tabular, cell_reader, layer_reader
1718
from .. import anchor as _anchor
18-
from . import tabular
19-
from ..tabular.cell_density_profile import cell_reader, layer_reader
20-
2119
from ... import commons
2220
from ...retrieval import requests
2321

siibra/livequeries/allen.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
"""Query Allen Human Brain Atlas microarray data in specified volume."""
1616

17-
from .query import LiveQuery
17+
from . import query as _query
1818

1919
from ..core import space as _space, structure
2020
from ..features import anchor as _anchor
@@ -51,7 +51,7 @@ class InvalidAllenAPIResponseException(Exception):
5151
pass
5252

5353

54-
class AllenBrainAtlasQuery(LiveQuery, args=['gene'], FeatureType=GeneExpressions):
54+
class AllenBrainAtlasQuery(_query.LiveQuery, args=['gene'], FeatureType=GeneExpressions):
5555
"""
5656
Interface to Allen Human Brain Atlas microarray data.
5757
@@ -117,7 +117,7 @@ def __init__(self, **kwargs):
117117
will be tested against the region mask in ICBM space
118118
to produce a table of outputs.
119119
"""
120-
LiveQuery.__init__(self, **kwargs)
120+
_query.LiveQuery.__init__(self, **kwargs)
121121
gene = kwargs.get('gene')
122122

123123
def parse_gene(spec):

siibra/locations/boundingbox.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
"""A box defined by two farthest corner coordinates on a specific space."""
1616

17-
from . import point, pointcloud, location
17+
from . import location, point, pointcloud
1818

1919
from ..commons import logger
2020
from ..exceptions import SpaceWarpingFailedError

siibra/locations/location.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
from __future__ import annotations
1818

1919
from ..core.structure import BrainStructure
20+
from ..core import space as _space
2021

2122
import numpy as np
2223
from abc import abstractmethod
2324

24-
from typing import TYPE_CHECKING, Union, Dict
25-
if TYPE_CHECKING:
26-
from siibra.core.space import Space
25+
from typing import Union, Dict
2726

2827

2928
class Location(BrainStructure):
@@ -46,29 +45,28 @@ class Location(BrainStructure):
4645
_MASK_MEMO = {} # cache region masks for Location._assign_region()
4746
_ASSIGNMENT_CACHE = {} # caches assignment results, see Region.assign()
4847

49-
def __init__(self, spacespec: Union[str, Dict[str, str], "Space"]):
48+
def __init__(self, spacespec: Union[str, Dict[str, str], "_space.Space"]):
5049
self._space_spec = spacespec
5150
self._space_cached = None
5251

5352
@property
54-
def space(self):
53+
def space(self) -> "_space.Space":
5554
if self._space_cached is None:
56-
from ..core.space import Space
5755
if isinstance(self._space_spec, dict):
5856
spec = self._space_spec.get("@id") or self._space_spec.get("name")
59-
self._space_cached = Space.get_instance(spec)
57+
self._space_cached = _space.Space.get_instance(spec)
6058
else:
61-
self._space_cached = Space.get_instance(self._space_spec)
59+
self._space_cached = _space.Space.get_instance(self._space_spec)
6260
return self._space_cached
6361

6462
@abstractmethod
65-
def warp(self, space):
63+
def warp(self, space: Union[str, "_space.Space"]):
6664
"""Generates a new location by warping the
6765
current one into another reference space."""
6866
pass
6967

7068
@abstractmethod
71-
def transform(self, affine: np.ndarray, space=None):
69+
def transform(self, affine: np.ndarray, space: Union[str, "_space.Space", None] = None):
7270
"""Returns a new location obtained by transforming the
7371
reference coordinates of this one with the given affine matrix.
7472

siibra/retrieval/datasets.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import re
2020
from typing import Union, List
21-
from abc import ABC, abstractproperty
21+
from abc import ABC, abstractmethod
2222
from hashlib import md5
2323

2424
try:
@@ -48,31 +48,38 @@ class EbrainsDatasetUrl(TypedDict):
4848

4949

5050
class EbrainsBaseDataset(ABC):
51-
@abstractproperty
51+
@property
52+
@abstractmethod
5253
def id(self) -> str:
5354
raise NotImplementedError
5455

55-
@abstractproperty
56+
@property
57+
@abstractmethod
5658
def name(self) -> str:
5759
raise NotImplementedError
5860

59-
@abstractproperty
61+
@property
62+
@abstractmethod
6063
def urls(self) -> List[EbrainsDatasetUrl]:
6164
raise NotImplementedError
6265

63-
@abstractproperty
66+
@property
67+
@abstractmethod
6468
def description(self) -> str:
6569
raise NotImplementedError
6670

67-
@abstractproperty
71+
@property
72+
@abstractmethod
6873
def contributors(self) -> List[EbrainsDatasetPerson]:
6974
raise NotImplementedError
7075

71-
@abstractproperty
76+
@property
77+
@abstractmethod
7278
def ebrains_page(self) -> str:
7379
raise NotImplementedError
7480

75-
@abstractproperty
81+
@property
82+
@abstractmethod
7683
def custodians(self) -> List[EbrainsDatasetPerson]:
7784
raise NotImplementedError
7885

@@ -342,7 +349,7 @@ def version_ids(self) -> List['str']:
342349
return [version.get("id") for version in self._detail.get("versions", [])]
343350

344351

345-
class GenericDataset():
352+
class GenericDataset:
346353

347354
def __init__(
348355
self,

siibra/retrieval/requests.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Request files with decoders, lazy loading, and caching."""
1616

1717
from .cache import CACHE, cache_user_fn
18-
from .exceptions import EbrainsAuthenticationError
18+
from . import exceptions as _exceptions
1919
from ..commons import (
2020
logger,
2121
HBP_AUTH_TOKEN,
@@ -388,7 +388,7 @@ def device_flow(cls, **kwargs):
388388
), # if explicitly enabled by env var, do not raise
389389
]
390390
):
391-
raise EbrainsAuthenticationError(
391+
raise _exceptions.EbrainsAuthenticationError(
392392
"sys.stdout is not tty, SIIBRA_ENABLE_DEVICE_FLOW is not set,"
393393
"and not running in a notebook. Are you running in batch mode?"
394394
)
@@ -444,7 +444,7 @@ def get_scope() -> str:
444444
f"exceeded max attempts: {cls._IAM_DEVICE_MAXTRIES}, aborting..."
445445
)
446446
logger.error(message)
447-
raise EbrainsAuthenticationError(message)
447+
raise _exceptions.EbrainsAuthenticationError(message)
448448
attempt_number += 1
449449
resp = requests.post(
450450
url=cls._IAM_TOKEN_ENDPOINT,
@@ -470,7 +470,7 @@ def get_scope() -> str:
470470
logger.debug(f"400 error: {resp.content}")
471471
continue
472472

473-
raise EbrainsAuthenticationError(resp.content)
473+
raise _exceptions.EbrainsAuthenticationError(resp.content)
474474

475475
@classmethod
476476
def set_token(cls, token):

0 commit comments

Comments
 (0)