astro-ndslice
Slice NumPy arrays, convert FITS/IRAF sections, and align images by pixel offsets.
Install
pip install astro-ndslice
Python >= 3.10.
For astronomers who need WCS/header offset helpers:
pip install "astro-ndslice[full]"
Slice an image
import numpy as np
from astro_ndslice import slicefy
data = np.arange(100).reshape(10, 10)
cutout = data[slicefy("[2:5,3:7]")] # Same as data[2:7, 1:5].
trimmed = data[slicefy(1)] # Trim one pixel from each edge - bezeling.
- FITS sections use 1-based, inclusive bounds in x, y order.
- NumPy uses 0-based, exclusive stops in row, column order.
slicefy()assumes FITS stringsslice_from_string()assumes Python strings unless you passfits_convention=True.
Align images
import numpy as np
from astro_ndslice import offseted_shape, offsets2slice
images = [np.ones((3, 4)), np.full((2, 3), 2)]
shapes = [image.shape for image in images] # NumPy axis order.
offsets = [(0, 0), (2, 1)] # x, y offsets.
_, shape = offseted_shape(shapes, offsets)
indices = offsets2slice(shapes, offsets)
stack = np.full((len(images), *shape), np.nan)
for image, index in zip(images, indices):
stack[index] = image
Both helpers round relative offsets to pixel positions. Use method="inner"
to find the region shared by every image; no shared pixels raises ValueError.
Function guide
| Task | Functions |
|---|---|
| Normalize scalars and iterables | is_list_like, listify, ndfy |
| Parse sections and trim edges | slicefy, slice_from_string, slice_to_string, bezel2slice |
| Place images and find overlap | regularize_offsets, offseted_shape, offsets2slice |
| Read WCS or physical offsets | calc_offset_wcs, calc_offset_physical (requires Astropy) |
calc_offset_physical() corrects LTV translation terms
for LTM scaling in shared physical-coordinate units. For example,
LTV1=6, LTM1_1=2 gives 3 along x; ignore_ltm=True gives the raw value 6.
This preserves the LTV sign; differing LTM matrices require resampling for
image alignment.
See CHANGELOG.md for return-type changes and stricter validation. For version bumps and PyPI publishing, see RELEASING.md.
Metadata
Release files for astro-ndslice 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| astro_ndslice-0.4.tar.gz | 60.9 kB | Without provenance | Details for astro_ndslice-0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| astro_ndslice-0.4-py3-none-any.whl | Python 3 | none | any | Details for astro_ndslice-0.4-py3-none-any.whl |
Total release size: 77.5 kB
Release files / astro_ndslice-0.4.tar.gz
| Download URL | astro_ndslice-0.4.tar.gz |
|---|---|
| Size | 60.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
748c30b135bace08b5cb1cf15c73304a28b34aa3b0cae5cbe1196c8736bf9fc9
|
|
BLAKE2b-256 checksum How to use checksums |
b157953c1b12f4190a8ee00fcfbcb5aa1e13db62273f0f9c7a7b848704da36f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / astro_ndslice-0.4-py3-none-any.whl
| Download URL | astro_ndslice-0.4-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64f2552fc1d53ee5f19acc508115bd010ed22d6b22bdde8aac681e715ea9d94e
|
|
BLAKE2b-256 checksum How to use checksums |
d957d5b45672b6b3d7eebfae03d26a1da92ff291e9a98c003a789d9338c667cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for astro-ndslice 0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.