Skip to main content

rebasis

CI Docs

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" (dst as averaging kernels), "interpolate", or "fit" (smooth conservative upsampling of bin averages onto a spline dst).
    • bounded=True gives 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" and bounded=(lo, hi) apply global bounds instead.
    • skipna=True handles 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

Averages from sparse samples

rb.optimal_estimate(values, coords, targets, covariance, noise=..., mean=...) computes the best linear unbiased estimates (kriging) of grid averages, e.g. monthly zonal means, from irregularly sampled observations, with uncertainties and the weights each estimate puts on the data. Every covariance, including those between box averages, cos-latitude weighted and around a periodic longitude, is computed exactly; the mean can be a tensor product of rebasis spaces (universal kriging). See the estimation docs.

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.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyrebasis 0.2.1
File Size Uploaded
pyrebasis-0.2.1.tar.gz 99.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyrebasis 0.2.1
File
pyrebasis-0.2.1-cp311-abi3-win_arm64.whl CPython 3.11 abi3 Windows ARM64 Details
pyrebasis-0.2.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details
pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.11 abi3 Linux glibc 2.17+ IBM System/390x Details
pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.11 abi3 Linux glibc 2.17+ PowerPC 64-le Details
pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
pyrebasis-0.2.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
pyrebasis-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 6.2 MB

Release files / pyrebasis-0.2.1.tar.gz

Download URL pyrebasis-0.2.1.tar.gz
Size 99.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bcd7b2a573137fc75bf9ce8a50e5eb718b8eb95fb05cf6d664ac070379b7520a
BLAKE2b-256 checksum
How to use checksums
3d10b1a4700b458cec6ef10f5109bbe584c8aed8269929216cb8bca02e96f7a3
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

Release files / pyrebasis-0.2.1-cp311-abi3-win_arm64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-win_arm64.whl
Size 454.2 kB
Tags CPython 3.11 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
edba9a3c02b952f5e2e0d7bf72a508dedc5808ae711c809f055813a0f7e814fe
BLAKE2b-256 checksum
How to use checksums
6557647b24f17bcda5dfc46dac7636312aa04310e07c71107b9eea83df42742f
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

Release files / pyrebasis-0.2.1-cp311-abi3-win_amd64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-win_amd64.whl
Size 493.2 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b9ee5b1f1affd106746b3033a3054026d340844f0abdce99e950420c6893e34e
BLAKE2b-256 checksum
How to use checksums
3cbfeaa95b8ccee56f368ed01e1c0c6a39d0f447fcb0a5f374143cc2f2db71ea
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

Release files / pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 812.3 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6fca1e38c1a5fcad34a2a080770d0ca27146f83b774091c0f5809f6192a807b5
BLAKE2b-256 checksum
How to use checksums
77a5d737c5fd822212a1800c1700e833b4cbaaf0ab5ad3c21a02bdeb27cb5d12
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

Release files / pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 755.1 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
0eae674ef5e6add81e009d73f9029f19f312d417a190b6f40c1eea75a795795b
BLAKE2b-256 checksum
How to use checksums
866301d5c8b668525bdc47fdb385073d2d15716f8a843677b52f0fe50f0eb01a
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

Release files / pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 601.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a53f9f803ad975b85c923dea64257e53b417b8344b35af4f88e4bc0d4df9342d
BLAKE2b-256 checksum
How to use checksums
52881a94b3583bb525bf8210bcea4fef0bc5f9ff39f13f8574da7f2101c480f5
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

Release files / pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 636.4 kB
Tags CPython 3.11 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
23dec7aaa796f2ef7921fada1f55c58f5ecd13cd520bccaaeb19ec0abe2a3ecd
BLAKE2b-256 checksum
How to use checksums
54714191e2be11680693531583e56c2baea8716cd7eb971df88a2156259f1df8
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

Release files / pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 665.4 kB
Tags CPython 3.11 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
0624fa7657df44727fbdb92db368f9872147fac5cd6c0ad8628bde705ece44e8
BLAKE2b-256 checksum
How to use checksums
f3b0162881b6be574468d4eaa101b42ccb99f06db3dc639aaa8462499ed6ab13
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

Release files / pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 577.1 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
82d019d6540be7c3ad2b4fd234f8fd6d4cf4a358b630cb89523f6d6133d0f77d
BLAKE2b-256 checksum
How to use checksums
3dc408e00d31caac59aa1ba1ee225fc65e7feb357c687be9c0263ef914ac2e85
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

Release files / pyrebasis-0.2.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
Size 545.8 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
16b5f6bd3c8a94ab4afb14ff51077fbf56046ddef6d31f16165b35fdbd1c4143
BLAKE2b-256 checksum
How to use checksums
711f07a77cfc40373872df9d5ab6ac54112e0b6bde9913cbb1e572a0a35507b6
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

Release files / pyrebasis-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pyrebasis-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl
Size 566.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2f47a1224fb7d433f387db3f1852326d3ef8103a11633044d00edea0bae6d0b8
BLAKE2b-256 checksum
How to use checksums
6b113c68e4cf18a908dd8e2da5b509b33de609c3556b0ff52d84860f44e7c1a2
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

Release history Release notifications | RSS feed

This release

0.2.1 This release

11 release files

0.2.0

11 release files

0.1.0

11 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page