Skip to content

Commit

Permalink
Use old typing annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Jul 28, 2023
1 parent 5b60f8a commit 1830a60
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pymaid/fetch/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def get_entity_graph(
Neurons additionally have
- skeleton_ids: list[int]
- skeleton_ids: List[int]
Skeletons additionally have
Expand Down
28 changes: 14 additions & 14 deletions pymaid/fetch/stack.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]]
Expand All @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
22 changes: 11 additions & 11 deletions pymaid/neuron_label.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pymaid/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1830a60

Please sign in to comment.