Skip to content

Commit

Permalink
docs(eyepy.core): adds type annotations to all objects in the core su…
Browse files Browse the repository at this point in the history
…bpackage
  • Loading branch information
Oli4 committed Mar 17, 2023
1 parent 986f9bc commit ea1cb4c
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/eyepy/core/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EyeVolumeLayerAnnotation:
def __init__(
self,
volume: EyeVolume,
data: Optional[npt.NDArray[np.float32]] = None,
data: Optional[npt.NDArray[np.float_]] = None,
meta: Optional[dict] = None,
**kwargs,
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/eyepy/core/eyebscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class EyeBscan:
""" """

def __init__(self, volume: EyeVolume, index: int):
def __init__(self, volume: EyeVolume, index: int) -> None:
"""
Args:
Expand Down Expand Up @@ -84,7 +84,7 @@ def plot(
layer_kwargs: Optional[dict] = None,
area_kwargs: Optional[dict] = None,
#ascan_kwargs=None,
annotations_only=False,
annotations_only: bool=False,
region: Union[slice, Tuple[slice, slice]] = np.s_[:, :],
) -> None:
""" Plot B-scan.
Expand Down
30 changes: 18 additions & 12 deletions src/eyepy/core/eyeenface.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, TYPE_CHECKING, Union

import matplotlib.pyplot as plt
from numpy import typing as npt
import numpy as np

from eyepy.core.annotations import EyeEnfacePixelAnnotation

if TYPE_CHECKING:
from eyepy import EyeEnfaceMeta


class EyeEnface:
""" """

def __init__(self, data, meta):
def __init__(self, data: npt.NDArray[np.int_],
meta: EyeEnfaceMeta) -> None:
"""
Args:
Expand All @@ -22,7 +26,7 @@ def __init__(self, data, meta):
self.meta = meta

@property
def area_maps(self):
def area_maps(self) -> Dict[str, EyeEnfacePixelAnnotation]:
"""
Returns:
Expand All @@ -31,7 +35,10 @@ def area_maps(self):
# Create a dict to access area_maps by their name
return {am.name: am for am in self._area_maps}

def add_area_annotation(self, area_map=None, meta=None, **kwargs):
def add_area_annotation(self,
area_map: Optional[npt.NDArray[np.bool_]] = None,
meta: Optional[Dict] = None,
**kwargs) -> EyeEnfacePixelAnnotation:
"""
Args:
Expand All @@ -50,7 +57,7 @@ def add_area_annotation(self, area_map=None, meta=None, **kwargs):
return area_annotation

@property
def scale_x(self):
def scale_x(self) -> float:
"""
Returns:
Expand All @@ -59,7 +66,7 @@ def scale_x(self):
return self.meta["scale_x"]

@property
def scale_y(self):
def scale_y(self) -> float:
"""
Returns:
Expand All @@ -68,7 +75,7 @@ def scale_y(self):
return self.meta["scale_y"]

@property
def size_x(self):
def size_x(self) -> int:
"""
Returns:
Expand All @@ -77,7 +84,7 @@ def size_x(self):
return self.shape[1]

@property
def size_y(self):
def size_y(self) -> int:
"""
Returns:
Expand All @@ -86,7 +93,7 @@ def size_y(self):
return self.shape[0]

@property
def laterality(self):
def laterality(self) -> str:
"""
Returns:
Expand All @@ -95,7 +102,7 @@ def laterality(self):
return self.meta["laterality"]

@property
def shape(self):
def shape(self) -> Tuple[int, int]:
"""
Returns:
Expand All @@ -115,8 +122,7 @@ def plot(self,
Returns:
"""
if ax is None:
ax = plt.gca()
ax = plt.gca() if ax is None else ax
ax.imshow(self.data[region], cmap="gray")

# Make sure tick labels match the image region
Expand Down
28 changes: 14 additions & 14 deletions src/eyepy/core/eyemeta.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import datetime
import json
import os
from typing import List, MutableMapping, Tuple
from typing import Any, Dict, Iterable, List, MutableMapping, Tuple, Union


class EyeMeta(MutableMapping):
""" """

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
"""
Args:
Expand All @@ -17,7 +17,7 @@ def __init__(self, *args, **kwargs):
self._store = dict()
self.update(dict(*args, **kwargs)) # use the free update to set keys

def as_dict(self):
def as_dict(self) -> Dict:
"""
Returns:
Expand All @@ -29,32 +29,32 @@ def as_dict(self):
data[key] = data[key].isoformat()
return data

def __getitem__(self, key):
def __getitem__(self, key: str) -> Any:
return self._store[key]

def __setitem__(self, key, value):
def __setitem__(self, key: str, value) -> None:
self._store[key] = value

def __delitem__(self, key):
def __delitem__(self, key: str) -> None:
del self._store[key]

def __iter__(self):
return iter(self._store)

def __len__(self):
def __len__(self) -> int:
return len(self._store)

def __str__(self):
def __str__(self) -> str:
return f"{os.linesep}".join([f"{f}: {self[f]}" for f in self if f != "__empty"])

def __repr__(self):
def __repr__(self) -> str:
return self.__str__()


class EyeEnfaceMeta(EyeMeta):
""" """

def __init__(self, scale_x: float, scale_y: float, scale_unit: str, **kwargs):
def __init__(self, scale_x: float, scale_y: float, scale_unit: str, **kwargs) -> None:
"""A dict with required keys to hold meta data for enface images of the eye
Args:
Expand All @@ -68,7 +68,7 @@ def __init__(self, scale_x: float, scale_y: float, scale_unit: str, **kwargs):
)

@classmethod
def from_dict(cls, data: dict):
def from_dict(cls, data: dict) -> "EyeEnfaceMeta":
"""
Args:
Expand All @@ -92,7 +92,7 @@ def __init__(
end_pos: Tuple[float, float],
pos_unit: str,
**kwargs,
):
) -> None:
"""A dict with required keys to hold meta data for OCT B-scans
Args:
Expand Down Expand Up @@ -137,7 +137,7 @@ def __init__(
**kwargs,
)

def as_dict(self):
def as_dict(self) -> Dict:
"""
Returns:
Expand All @@ -148,7 +148,7 @@ def as_dict(self):
return data

@classmethod
def from_dict(cls, data: dict):
def from_dict(cls, data: dict) -> "EyeVolumeMeta":
"""
Args:
Expand Down
Loading

0 comments on commit ea1cb4c

Please sign in to comment.