Skip to content

Add ctis.arange, a centered variant of named_arrays.arange - #20

Merged
roytsmart merged 1 commit into
mainfrom
feature/arange-centered
Jul 26, 2026
Merged

Add ctis.arange, a centered variant of named_arrays.arange#20
roytsmart merged 1 commit into
mainfrom
feature/arange-centered

Conversation

@roytsmart

Copy link
Copy Markdown
Contributor

Summary

Adds ctis.arange(start, stop, axis, step), a centered counterpart of named_arrays.arange.

na.arange starts exactly at start and leaves the remainder of the range as a gap on the right. ctis.arange fits as many step-spaced samples as fit in [start, stop] and centers them, splitting the leftover evenly between both ends. This is convenient for building a coordinate grid with a fixed pitch centered on a field of view instead of biased toward one edge.

na.arange(0, 10, axis="x", step=3)     # [0, 3, 6, 9]      (gap on the right)
ctis.arange(0, 10, axis="x", step=3)   # [0.5, 3.5, 6.5, 9.5]  (centered)

Notes

  • Built on na.linspace, so it is unit-safe. na.arange wraps numpy.arange, which misbehaves with astropy.units.Quantity step.
  • Vector support: when start/stop/step are AbstractVectorArrays (and axis is a matching vector of names), each component is centered independently along its own axis, producing an outer-product grid.
  • For divisible ranges both endpoints are included (symmetric); for non-divisible ranges it matches na.arange's sample count, just shifted to center.

Dependency

Requires named-arrays >=2.2 (pin bumped ~=2.0~=2.2): the vector-of-ScalarArrays path relies on linspace accepting a scalar-array num, fixed in named-arrays #194 / released in v2.2.0.

Tests

ctis/_arange_test.py: scalar (divisible + non-divisible), Quantity, and vector cases, the latter parametrized over both Quantity-component and ScalarArray-component vectors. 100% coverage of the module; black/ruff clean; docstring jupyter-execute examples verified.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CtdKmedevWkDab6BWupXqQ

`ctis.arange` fits as many samples spaced by `step` as possible into
`[start, stop]` and centers them, splitting the leftover evenly between the
two ends (rather than starting at `start` and leaving a gap on the right like
`named_arrays.arange`). This is convenient for building a coordinate grid
with a fixed pitch centered on a field of view.

It is built on `named_arrays.linspace`, so it is unit-safe (unlike
`named_arrays.arange`, which wraps `numpy.arange` and misbehaves with
`astropy.units.Quantity`). When `start`, `stop`, and `step` are vectors, each
component is centered independently along its own axis, producing an
outer-product grid.

Requires named-arrays >=2.2 for the vector-of-`ScalarArray`s case
(`linspace` accepting a scalar-array `num`).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CtdKmedevWkDab6BWupXqQ
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (54f116f) to head (6360c1e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #20   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        23    +2     
  Lines          643       697   +54     
=========================================
+ Hits           643       697   +54     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roytsmart
roytsmart merged commit 2eb14d0 into main Jul 26, 2026
12 checks passed
@roytsmart
roytsmart deleted the feature/arange-centered branch July 26, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant