From 1830a60a7ee1933744d7bf26acde09af90c1eab6 Mon Sep 17 00:00:00 2001 From: Chris Barnes Date: Fri, 28 Jul 2023 16:40:11 +0100 Subject: [PATCH] Use old typing annotations --- pymaid/fetch/annotations.py | 2 +- pymaid/fetch/stack.py | 28 ++++++++++++++-------------- pymaid/neuron_label.py | 22 +++++++++++----------- pymaid/stack.py | 6 +++--- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pymaid/fetch/annotations.py b/pymaid/fetch/annotations.py index 1db874e..cba400a 100644 --- a/pymaid/fetch/annotations.py +++ b/pymaid/fetch/annotations.py @@ -391,7 +391,7 @@ def get_entity_graph( Neurons additionally have - - skeleton_ids: list[int] + - skeleton_ids: List[int] Skeletons additionally have diff --git a/pymaid/fetch/stack.py b/pymaid/fetch/stack.py index 04b9cc2..0ac8997 100644 --- a/pymaid/fetch/stack.py +++ b/pymaid/fetch/stack.py @@ -1,4 +1,4 @@ -from typing import Any, Optional, Union, Literal, Sequence +from typing import Any, Optional, Union, Literal, Sequence, Tuple, Dict, List import numpy as np from ..utils import _eval_remote_instance from ..client import CatmaidInstance @@ -17,7 +17,7 @@ class Orientation(IntEnum): def __bool__(self) -> bool: return True - def full_orientation(self, reverse=False) -> tuple[Dimension, Dimension, Dimension]: + def full_orientation(self, reverse=False) -> Tuple[Dimension, Dimension, Dimension]: out = [ ("x", "y", "z"), ("x", "z", "y"), @@ -48,7 +48,7 @@ class StackSummary: comment: str -def get_stacks(remote_instance: Optional[CatmaidInstance] = None) -> list[StackSummary]: +def get_stacks(remote_instance: Optional[CatmaidInstance] = None) -> List[StackSummary]: """Get summary of all stacks in the project. Parameters @@ -95,23 +95,23 @@ class StackInfo: pid: int ptitle: str stitle: str - downsample_factors: Optional[list[dict[Dimension, float]]] + downsample_factors: Optional[List[Dict[Dimension, float]]] num_zoom_levels: int - translation: dict[Dimension, float] - resolution: dict[Dimension, float] - dimension: dict[Dimension, int] + translation: Dict[Dimension, float] + resolution: Dict[Dimension, float] + dimension: Dict[Dimension, int] comment: str description: str metadata: Optional[str] - broken_slices: dict[int, int] - mirrors: list[MirrorInfo] + broken_slices: Dict[int, int] + mirrors: List[MirrorInfo] orientation: Orientation attribution: str - canary_location: dict[Dimension, int] + canary_location: Dict[Dimension, int] placeholder_color: Color @classmethod - def from_jso(cls, sinfo: dict[str, Any]): + def from_jso(cls, sinfo: Dict[str, Any]): sinfo["orientation"] = Orientation(sinfo["orientation"]) sinfo["placeholder_color"] = Color(**sinfo["placeholder_color"]) sinfo["mirrors"] = [MirrorInfo(**m) for m in sinfo["mirrors"]] @@ -120,7 +120,7 @@ def from_jso(cls, sinfo: dict[str, Any]): def to_jso(self): return asdict(self) - def get_downsample(self, scale_level=0) -> dict[Dimension, float]: + def get_downsample(self, scale_level=0) -> Dict[Dimension, float]: """Get the downsample factors for a given scale level. If the downsample factors are explicit in the stack info, @@ -151,13 +151,13 @@ def get_downsample(self, scale_level=0) -> dict[Dimension, float]: first, second, slicing = self.orientation.full_orientation() return {first: 2**scale_level, second: 2**scale_level, slicing: 1} - def get_coords(self, scale_level: int = 0) -> dict[Dimension, np.ndarray]: + def get_coords(self, scale_level: int = 0) -> Dict[Dimension, np.ndarray]: dims = self.orientation.full_orientation() dims = dims[::-1] downsamples = self.get_downsample(scale_level) - out: dict[Dimension, np.ndarray] = dict() + out: Dict[Dimension, np.ndarray] = dict() for d in dims: c = np.arange(self.dimension[d], dtype=float) c *= self.resolution[d] diff --git a/pymaid/neuron_label.py b/pymaid/neuron_label.py index 4f90844..ae46cbb 100644 --- a/pymaid/neuron_label.py +++ b/pymaid/neuron_label.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod from functools import cache -from typing import Optional, Union +from typing import Optional, Union, List, Tuple import re import networkx as nx @@ -38,7 +38,7 @@ def __init__( self, skeleton_id: Optional[int] = None, name: Optional[str] = None, - annotations: Optional[list[str]] = None, + annotations: Optional[List[str]] = None, remote_instance: Optional[CatmaidInstance] = None, ) -> None: """ @@ -51,7 +51,7 @@ def __init__( If None, determined from name. name : Optional[str], optional If None, determined from skeleton ID. - annotations : Optional[list[str]], optional + annotations : Optional[List[str]], optional If None, determined from skeleton ID or name. remote_instance : Optional[CatmaidInstance], optional If None, uses global instance. @@ -90,7 +90,7 @@ def name(self) -> str: return self._name @property - def annotations(self) -> list[str]: + def annotations(self) -> List[str]: if self._annotations is None: skid = self.skeleton_id skid_to_anns = pymaid.get_annotations(skid) @@ -155,8 +155,8 @@ def __init__( super().__init__() def _filter_by_author( - self, annotations: list[str], remote_instance: CatmaidInstance - ) -> list[str]: + self, annotations: List[str], remote_instance: CatmaidInstance + ) -> List[str]: if self.annotator_name is None or not annotations: return annotations @@ -166,8 +166,8 @@ def _filter_by_author( return [a for a in annotations if a in allowed] def _filter_by_annotation( - self, annotations: list[str], remote_instance: CatmaidInstance - ) -> list[str]: + self, annotations: List[str], remote_instance: CatmaidInstance + ) -> List[str]: if self.annotated_with is None or not annotations: return annotations @@ -193,7 +193,7 @@ def dedup_whitespace(s: str): @cache def parse_components( fmt: str, -) -> tuple[list[str], list[tuple[str, int, Optional[str]]]]: +) -> Tuple[List[str], List[Tuple[str, int, Optional[str]]]]: joiners = [] components = [] last_end = 0 @@ -264,7 +264,7 @@ class NeuronLabeller: """Class for calculating neurons' labels, as used in the CATMAID frontend.""" def __init__( self, - components: Optional[list[LabelComponent]] = None, + components: Optional[List[LabelComponent]] = None, fmt="%0", trim_empty=True, remove_neighboring_duplicates=True, @@ -273,7 +273,7 @@ def __init__( Parameters ---------- - components : list[LabelComponent], optional + components : List[LabelComponent], optional The label components as used in CATMAID's user settings. See `SkeletonId`, `NeuronName`, and `Annotations`. First component should be ``SkeletonId()`` for compatibility with CATMAID. diff --git a/pymaid/stack.py b/pymaid/stack.py index d6ac3d7..0144170 100644 --- a/pymaid/stack.py +++ b/pymaid/stack.py @@ -29,7 +29,7 @@ ENDIAN = "<" if sys.byteorder == "little" else ">" -def select_cli(prompt: str, options: dict[int, str]) -> Optional[int]: +def select_cli(prompt: str, options: Dict[int, str]) -> Optional[int]: out = None print(prompt) for k, v in sorted(options.items()): @@ -52,7 +52,7 @@ def select_cli(prompt: str, options: dict[int, str]) -> Optional[int]: def to_array( - coord: Union[dict[Dimension, Any], ArrayLike], + coord: Union[Dict[Dimension, Any], ArrayLike], dtype: DTypeLike = np.float64, order: Sequence[Dimension] = ("z", "y", "x"), ) -> np.ndarray: @@ -232,7 +232,7 @@ class TileStore5(JpegStore): # return s -tile_stores: dict[int, Type[JpegStore]] = { +tile_stores: Dict[int, Type[JpegStore]] = { t.tile_source_type: t for t in [ TileStore1,