Skip to content

Commit 7c7dd53

Browse files
committed
Add full type annotations to gPhoton/moviemaker/_steps.py.
This code uses dicts as pseudo-records a lot and therefore the typing is sloppier than I would ideally like. For clarity, sm_make_map was folded into sm_make_maps and the loop unrolled. So as not to be using one dict for two radically different things, up in make_movies, the alternative threads/no-threads code paths needed to be split apart. Some of the functions in calibrate.py were incorrectly annotated in an earlier commit; this is corrected now I can see what their callers actually supply. In a few places we use the experimental shape typing from numpy 2.2; this should be removed with prejudice if it causes any problems whatsoever (see numpy/numpy#28076 ) but it does seem to work for the very limited case this code wants, i.e. “this is a 2-d matrix”.
1 parent 3cf534b commit 7c7dd53

4 files changed

Lines changed: 220 additions & 137 deletions

File tree

‎gPhoton/calibrate.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
calibration, including walk, wiggle, linearity, post-CSP, and stim
77
scaling corrections.
88
"""
9-
from collections.abc import Sequence
109
from pathlib import Path
1110
from typing import Any, Literal, NamedTuple, cast
1211

@@ -627,20 +626,20 @@ def center_and_scale(
627626
def compute_shutter(
628627
timeslice: NDArray[NFloat],
629628
flagslice: NDArray[NFloat],
630-
trange: Sequence[float],
629+
trange: tuple[float, float],
631630
shutgap: float = 0.05
632631
) -> float:
633632
ix = np.where(flagslice == 0)
634633
t = np.hstack([trange[0], np.unique(timeslice[ix]), trange[1]])
635634
ix = np.where(t[1:] - t[:-1] >= shutgap)
636-
return cast(float, np.array(t[1:] - t[:-1])[ix].sum())
635+
return np.array(t[1:] - t[:-1])[ix].sum()
637636

638637

639638
def compute_exptime(
640639
timeslice: NDArray[NFloat],
641640
flagslice: NDArray[NFloat],
642641
band: GalexBand,
643-
trange: Sequence[float],
642+
trange: tuple[float, float],
644643
) -> float:
645644
shutter = compute_shutter(timeslice, flagslice, trange)
646645
# Calculate deadtime

0 commit comments

Comments
 (0)