From d2b9a082aa04d648c2628ef2faaa1d11d314e1a7 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Mon, 9 Feb 2026 06:38:19 -0500 Subject: [PATCH 1/3] Add type annotation and change signature for centered_image --- celerpy/visualize.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/celerpy/visualize.py b/celerpy/visualize.py index b50c382..e99faf7 100644 --- a/celerpy/visualize.py +++ b/celerpy/visualize.py @@ -19,6 +19,7 @@ from matplotlib import colormaps from matplotlib.axes import Axes as mpl_Axes from matplotlib.colors import BoundaryNorm, ListedColormap +from numpy.typing import ArrayLike from . import process from .model.input import ImageInput, ModelSetup, TraceInput @@ -384,10 +385,11 @@ def plot_all_geometry( def centered_image( - center, - xdir, - outdir, - width: Union[float, tuple[float, float]], + center: ArrayLike = (0, 0, 0), + *, + width: Union[float, tuple, np.ndarray], + xdir: ArrayLike = (0, 0, 1), + outdir: ArrayLike = (0, 1, 0), **kwargs: Any, ) -> ImageInput: """ @@ -401,7 +403,7 @@ def centered_image( The direction along the rendered x-axis. outdir : array_like The direction out of the page in the result. - width : float or tuple of two floats or array_like with shape (2,) + width : float or array_like with shape (2,) If a single float is provided, the image is square and that value is used for both the x (horizontal) and y (vertical) dimensions. If a tuple or array-like with two elements is @@ -415,16 +417,18 @@ def centered_image( ImageInput The input to ``visualize`` to generate the centered image. """ - center = np.asarray(center) - xdir = np.asarray(xdir) + center = np.asarray(center, dtype=float) + xdir = np.asarray(xdir, dtype=float) + outdir = np.asarray(outdir, dtype=float) ydir = np.cross(outdir, xdir) - if isinstance(width, float): + if isinstance(width, (float, int)): wx, wy = width, width - elif len(width) == 2: - wx, wy = width else: - raise ValueError("width must be a float or a length-2 tuple") + width_array = np.asarray(width, dtype=float) + if width_array.shape != (2,): + raise ValueError("width must be a float or a length-2 array") + wx, wy = width_array offset = xdir * (wx / 2) + ydir * (wy / 2) lower_left = (center - offset).tolist() From ae18e56c43c6dc5c380ee3e3c9e8b78cec4ba804 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Mon, 9 Feb 2026 07:04:26 -0500 Subject: [PATCH 2/3] Fix ordering --- celerpy/visualize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/celerpy/visualize.py b/celerpy/visualize.py index e99faf7..801fd16 100644 --- a/celerpy/visualize.py +++ b/celerpy/visualize.py @@ -399,16 +399,16 @@ def centered_image( ---------- center : array_like The center coordinate (real space) of the image. - xdir : array_like - The direction along the rendered x-axis. - outdir : array_like - The direction out of the page in the result. width : float or array_like with shape (2,) If a single float is provided, the image is square and that value is used for both the x (horizontal) and y (vertical) dimensions. If a tuple or array-like with two elements is provided, the first element specifies the width along the x-axis and the second element specifies the width along the y-axis. + xdir : array_like + The direction along the rendered x-axis. + outdir : array_like + The direction out of the page in the result. **kwargs Additional keyword arguments passed to the ImageInput constructor. From d15344e55729c6168726ad45a0a26e6c2af6db25 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Mon, 9 Feb 2026 07:07:06 -0500 Subject: [PATCH 3/3] Update pre-commit --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 500eb4a..d6d93e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,19 +27,19 @@ repos: language: system pass_filenames: false - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # v5.0.0 , 5 Oct 2024 + rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # v6.0.0 , 9 Aug 2025 hooks: - id: check-added-large-files args: ['--maxkb=100'] - id: check-case-conflict - id: check-merge-conflict - id: check-shebang-scripts-are-executable - - id: check-json - - id: check-yaml - id: end-of-file-fixer exclude: '\.(diff|patch)$' - id: trailing-whitespace exclude: '\.(diff|patch)$' + - id: check-json + - id: check-yaml ci: autoupdate_schedule: quarterly