rebasis
Linear maps between function bases, with a Rust core and a Python interface.
pip install pyrebasis # import rebasis
cargo add rebasis # the Rust crate
The PyPI distribution is pyrebasis because rebasis there is an unrelated project; the import
name is rebasis. Documentation: https://usask-arg.github.io/rebasis/.
A quantity is represented as f(x) = Σ_j f_j B_j(x). rebasis computes the sparse matrices that turn the coefficients f_j into:
| operation | what it computes | typical use |
|---|---|---|
measure(kernels, basis) |
g_i = ∫ K_i f / ∫ K_i | instrument line shape applied to a high-resolution spectrum |
evaluate(basis, x) |
g_i = f(x_i) | interpolation, plotting a reconstruction |
project(src, dst) |
best L2 fit Σ g_i G_i ≈ f | conservative regridding, up- or down-sampling |
Fit(kernels, model) |
model coefficients whose measurements match data | smooth conservative upsampling, smoothing splines, inverting measure |
Inner products are exact for piecewise polynomials (boxes, hats, B-splines, tabulated shapes) and accurate to rounding for the analytic line shapes; there are no tolerance or resolution parameters.
import numpy as np
import rebasis as rb
wavel = np.linspace(300, 310, 100_001) # high-resolution model grid
hires = rb.Space.hats(wavel) # radiance = linear interpolant of the samples
ils = rb.Space.voigts(np.arange(301, 309, 0.1), fwhm_gaussian=0.4, fwhm_lorentzian=0.05)
W = rb.measure(ils, hires) # scipy.sparse.csr_array, (80, 100001)
measured = W @ radiance # or rb.apply_along(W, radiance, axis=...)
coarse = rb.Space.boxes(np.arange(300, 310.01, 0.5))
binned = rb.regrid(radiance, hires, coarse) # conservative; bounded=True to avoid overshoot
Spaces
Elements are shapes, not densities: everything peaks at 1. Normalization is a property of the
operation (measure(..., normalization="integral" | "rowsum" | "none")), not of the element, so
the same space can serve as a basis in one call and as kernels in another. Per-element widths
can be scalars or arrays.
Bases
Space.hats(nodes): piecewise linear; coefficients are values at the nodes. The basis for a function known by samples.Space.boxes(edges),Space.boxes_from_centers(centers): piecewise constant; coefficients are bin averages.Space.bsplines_clamped(breakpoints, degree),Space.bsplines(knots, degree): B-splines of degree 0 to 3.Space.deltas(x): point evaluation as kernels, point masses as a basis.
Line shapes (cutoff is the half width of the truncated support, in the unit given)
| constructor | shape | cutoff unit |
|---|---|---|
gaussians(c, sigma= | fwhm=) |
Gaussian | σ (default 6) |
lorentzians(c, hwhm= | fwhm=) |
Lorentzian | HWHM (100) |
voigts(c, sigma= | fwhm_gaussian=, gamma= | fwhm_lorentzian=) |
Voigt (Faddeeva, ~3e-15) | Voigt HWHM (100) |
pseudo_voigts(c, fwhm=, eta=) |
η·L + (1−η)·G | HWHM (100) |
super_gaussians(c, fwhm=, power=, asymmetry=0) |
exp(−ln2·|2t/w|^p), optionally asymmetric | HWHM per side (6) |
smoothed_boxes(c, width=, sigma= | fwhm=) |
slit ⊗ Gaussian | σ past the box edge (6) |
fts(c, max_opd=, apodization=) |
FTS line shape: none (sinc), triangle (sinc²), hann, hamming, blackman, blackman_harris, norton_beer_weak/medium/strong, or custom cosine-sum / Norton–Beer coefficients |
1/(2·max_opd) (100) |
rectangles(c, width=), triangles(c, fwhm=), trapezoids(c, top_width=, bottom_width=) |
exact piecewise linear | |
shifted(c, shape_x, shape_y, stretch=1, interp="linear" | "pchip") |
one tabulated shape, stored once | |
tabulated(c, x, y, interp=) |
a tabulated shape per channel |
examples/lineshapes.py plots all of them.
Regridding
rb.regrid(data, src, dst, axis, method=...):"project"(conservative, default),"measure"(dstas averaging kernels),"interpolate", or"fit"(smooth conservative upsampling of bin averages onto a splinedst).bounded=Truegives the best L2 approximation that conserves the integral and creates no new extrema: each coefficient stays within the range of the inputs it overlaps. It solves a small banded quadratic program exactly, so corrections stay local.bounded="positive"andbounded=(lo, hi)apply global bounds instead.skipna=Truehandles missing data.weight="cos_lat_deg"gives area weighting in latitude.
rb.regrid_nd(data, {axis: (src, dst[, weight]), ...}): tensor-product grids, one axis at a time (exact for separable grids).rebasis.xarray.regrid(ds, {"lat": new_lat, "lon": new_lon}, weight={"lat": "cos_lat_deg"})regrids DataArrays and Datasets by dimension name.rb.Fit(kernels, model, smoothing=..., penalty="derivative", order=2)is the general penalized least-squares fit. The penalty is ∫(f⁽ʳ⁾)² (a smoothing spline) or coefficient differences (P-splines).
Derivatives with respect to line-shape parameters
rb.measure_derivative(kernels, basis, parameter) returns (W, dW), where dW is ∂W/∂p with
row i differentiated with respect to kernel i's parameter. For a spectrum f, dW @ f is the
Jacobian of the measurements with respect to per-channel parameters (diagonal), or with respect
to one parameter shared by all channels. The derivatives are exact: they include the moving
truncation edges and the normalization, and they agree with finite differences to the accuracy
of the finite differences.
| parameter | kernels |
|---|---|
center |
all (spectral shift) |
scale |
all but deltas: width · ∂/∂width, every width scaled together (squeeze or stretch) |
sigma |
Gaussian, Voigt, smoothed box |
gamma |
Lorentzian, Voigt |
eta |
pseudo-Voigt |
power, asymmetry |
super-Gaussian |
half_width |
smoothed box |
Wavelength and wavenumber
space.to_wavenumber(jacobian=...) (and to_wavelength, reciprocal, affine) uses each
element exactly in another coordinate, e.g. an instrument response in nm against a model grid in
cm⁻¹: rb.measure(ils_nm.to_wavenumber(jacobian=True), hires_cminv). The required jacobian is
True for kernels and spectral densities, False for plain functions.
Development
uv sync # builds the extension (release profile)
uv run pytest
cargo test -p rebasis
uv run --extra docs sphinx-build -W -b html docs docs/_build/html
The Rust crate rebasis (in rebasis/) has no Python dependency and is intended to be used
directly by sasktran2; rebasis-py/ holds the pyo3 bindings. examples/ has a benchmark and
figure scripts.
Metadata
Release files for pyrebasis 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyrebasis-0.1.0.tar.gz | 67.2 kB | Details |
Built distributions (wheels)
Total release size: 5.0 MB
Release files / pyrebasis-0.1.0.tar.gz
| Download URL | pyrebasis-0.1.0.tar.gz |
|---|---|
| Size | 67.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f469f9db6857cb988a0eb15f812858f7b142d0bbb221f66d50acb02edc7d2e8
|
|
BLAKE2b-256 checksum How to use checksums |
129a7aaeb5306c3fd173acbb5d837e8f41f234939808f581a877b229304d2bdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-win_arm64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-win_arm64.whl |
|---|---|
| Size | 338.9 kB |
| Tags | CPython 3.11 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b6076b969e7d9e9c84504ceea4bd435b5dbe8df56d79838cea0502246487208e
|
|
BLAKE2b-256 checksum How to use checksums |
36476ba9531e8df2cdc1f36e8bd726b58d3ae2feebf823b8c3654a6f34b06610
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 366.7 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f165a040915f96beb1b312f1e49e3c33d1f22c981999cf00c7817476edee55fb
|
|
BLAKE2b-256 checksum How to use checksums |
d81e1a5b0ced5c31874b38fe7f2b50c4773995717bfbaf6556e34ec704bbf2e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 691.8 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a36377c253123bfca60b1c9b59735d5e72bef4b16a328a55acca769974b367c8
|
|
BLAKE2b-256 checksum How to use checksums |
95cd9cd4ecefb428b4a39a730b19c8007569f5d23c6b638cfacc956b12de918d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 645.6 kB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6175d7542543aac1845c89766e3bca0571b779c7acff30935d774827fd67021e
|
|
BLAKE2b-256 checksum How to use checksums |
d8f46c1bd4edf9b5174ecb01caf730b0ffa22787fe25029cdc8987fac2cd5390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 481.7 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6ac368aad79d2e35b71ef228167e9b54f96a7522af7ab18ae5af00d37d34cea7
|
|
BLAKE2b-256 checksum How to use checksums |
093f060ade4f2dcb2586950c795e3ea8ae210515bf6e821ca4dffe5daf95e7d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 520.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
91b45bda6b74cb0500868bcdc2bc9ead9472b1a8b9104f7f085e2f5cc5b85f15
|
|
BLAKE2b-256 checksum How to use checksums |
31537aad835c7a19bfc6828df1a3722bdcbd440f421112f44b49b8066112738d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 530.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
40de233b6b77646929b4152ea45eeab4e0d4635283992ce47e134ae110245b60
|
|
BLAKE2b-256 checksum How to use checksums |
b6185270535e3762c4bc7105331e8aa81125fc84d8e289b32e6e25dd0ebe2d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 467.9 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f0146f8caa23373b72932590570b692c03a747442d2ce1565c4a9c45565bc461
|
|
BLAKE2b-256 checksum How to use checksums |
0a66c66b06a4ef3cdb315159ccdae3a173cd00fb653265410f1354f5c0b06ab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 433.2 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
957990ec72f6704ea5a27803ae8e4f1821c5a42cba684c59ef99fe6f3e1f7665
|
|
BLAKE2b-256 checksum How to use checksums |
a953995d66d26e39c4118e88f64cae9e1a3a5ad24aeb49d6e1af2655cb4946ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / pyrebasis-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | pyrebasis-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 448.7 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
6d104a4aaf69a214a01155545dd1109d53a690f64a6fcf731db3ff2dd38a2cec
|
|
BLAKE2b-256 checksum How to use checksums |
fbb9358ce586678fc62d6274be58df1b4defe2f65ace26b82466634ac0990a7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency log