From 821b4b3bb39dae02bbee8f971f3c28259435c965 Mon Sep 17 00:00:00 2001 From: Eoghan O'Connell Date: Tue, 26 Nov 2024 12:08:47 +0100 Subject: [PATCH] docs: add futures annotations import for older py versions --- dclab/features/bright.py | 2 ++ dclab/features/bright_bc.py | 9 ++++++++- dclab/features/bright_perc.py | 2 ++ dclab/features/contour.py | 9 ++++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dclab/features/bright.py b/dclab/features/bright.py index c5342cfb..a5e40931 100644 --- a/dclab/features/bright.py +++ b/dclab/features/bright.py @@ -2,6 +2,8 @@ Computation of mean and standard deviation of grayscale values inside the RT-DC event image mask. """ +from __future__ import annotations + import numpy as np import numpy.typing as npt diff --git a/dclab/features/bright_bc.py b/dclab/features/bright_bc.py index dba8c578..ec99e048 100644 --- a/dclab/features/bright_bc.py +++ b/dclab/features/bright_bc.py @@ -2,10 +2,17 @@ Computation of mean and standard deviation of grayscale values inside the RT-DC event image mask with background-correction taken into account. """ +from __future__ import annotations + import numpy as np +import numpy.typing as npt -def get_bright_bc(mask, image, image_bg, bg_off=None, ret_data="avg,sd"): +def get_bright_bc(mask: npt.NDArray[bool] | list[npt.NDArray[bool]], + image: npt.NDArray | list[npt.NDArray], + image_bg: npt.NDArray | list[npt.NDArray], + bg_off: float | npt.NDArray = None, + ret_data: str = "avg,sd"): """Compute avg and/or std of the background-corrected event brightness The background-corrected event brightness is defined by the diff --git a/dclab/features/bright_perc.py b/dclab/features/bright_perc.py index bc5a6b1c..6a9ced56 100644 --- a/dclab/features/bright_perc.py +++ b/dclab/features/bright_perc.py @@ -2,6 +2,8 @@ Computation of the 10th and 90th percentile of grayscale values inside the RT-DC event image mask with background-correction taken into account. """ +from __future__ import annotations + import numpy as np import numpy.typing as npt diff --git a/dclab/features/contour.py b/dclab/features/contour.py index 977b13da..c9e13fec 100644 --- a/dclab/features/contour.py +++ b/dclab/features/contour.py @@ -1,8 +1,11 @@ """Computation of event contour from event mask""" +from __future__ import annotations + from collections import deque import numbers import numpy as np +import numpy.typing as npt # equivalent to # from skimage.measure import find_contours @@ -14,15 +17,15 @@ class NoValidContourFoundError(BaseException): class LazyContourList(object): - def __init__(self, masks, max_events=1000): + def __init__(self, masks: npt.ArrayLike, max_events: int = 1000): """A list-like object that computes contours upon indexing Parameters ---------- - masks: array-like + masks 3D array of masks, may be an HDF5 dataset or any other structure that supports indexing - max_events: int + max_events maximum number of contours to keep in the contour list; set to 0/False/None to cache all contours