Add ctis.arange, a centered variant of named_arrays.arange - #20
Merged
Conversation
`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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
ctis.arange(start, stop, axis, step), a centered counterpart ofnamed_arrays.arange.na.arangestarts exactly atstartand leaves the remainder of the range as a gap on the right.ctis.arangefits as manystep-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.Notes
na.linspace, so it is unit-safe.na.arangewrapsnumpy.arange, which misbehaves withastropy.units.Quantitystep.start/stop/stepareAbstractVectorArrays (andaxisis a matching vector of names), each component is centered independently along its own axis, producing an outer-product grid.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 onlinspaceaccepting a scalar-arraynum, 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 andScalarArray-component vectors. 100% coverage of the module; black/ruff clean; docstringjupyter-executeexamples verified.🤖 Generated with Claude Code
https://claude.ai/code/session_01CtdKmedevWkDab6BWupXqQ