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

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.0
File Size Uploaded
pyrebasis-0.2.0.tar.gz 97.2 kB Details

Built distributions (wheels)

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

Total release size: 5.8 MB

Release files / pyrebasis-0.2.0.tar.gz

Download URL pyrebasis-0.2.0.tar.gz
Size 97.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4a68da8bc1b43b8e6b045c979addba8ece510523804b5c20183dfe6764833ac7
BLAKE2b-256 checksum
How to use checksums
08c15564f3799ac4f263c2b341d0490f1ecdc8474818721c773c8b31a807f5bf
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.0-cp311-abi3-win_arm64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-win_arm64.whl
Size 416.8 kB
Tags CPython 3.11 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
177facdfb0ed2de09f838e1600161bd9733f1d12ae2cf4e9e7d2bc6a98df65db
BLAKE2b-256 checksum
How to use checksums
b7f77a04835d48ec6b8af0381918da0b911d05273a5a6a689734b774e36676a7
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.0-cp311-abi3-win_amd64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-win_amd64.whl
Size 451.6 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8bfcd6adaa6d55d2d2fb1379af5e1b5f771dd96298d1c7ed3422849ea1441eac
BLAKE2b-256 checksum
How to use checksums
6c60a02e778cc5a04e3ac055e91e4f4b94057ad508b9199a984807d4b25c2884
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.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 773.7 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
1eb28324bb0baa230bfbb4c3854a9e17993377d6712a4c9e126bf92c95b742ec
BLAKE2b-256 checksum
How to use checksums
54e1e528b0cf4daf21afd42e27859cb22b9a35118ab0be28bc1054365eaec650
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.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 721.3 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
cd6ecc5e006d87292e938a0eb417d1884e052c23eb356eb359fc760ba19538d5
BLAKE2b-256 checksum
How to use checksums
95a82a7c2f4dbc518c518cb8d94489e5716b6bf8f559f9081c9f80d5dfdd00ef
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.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 563.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
6ca698ff1177f35aef2674dfb74ab900a63ed63189e5d0590175aa38fcaa506d
BLAKE2b-256 checksum
How to use checksums
1d7c6b0346883b1b00cb4962720e5285e3bd162a7d16145cc0021072e658c679
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.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL pyrebasis-0.2.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 598.7 kB
Tags CPython 3.11 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
f73b4b2667a053ccf9d4a54567886ee4e79ac9c9a65e4bb3d5a6557d486ecd4a
BLAKE2b-256 checksum
How to use checksums
27366c0094fedfd95e18806472f63f6f237213aa943d884cc1641e4fe4ea6d9c
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.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL pyrebasis-0.2.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 617.9 kB
Tags CPython 3.11 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
fedd686885f5a3198c068c7842dead44d8beea97e542fb68f99c2d1ff6e85ce2
BLAKE2b-256 checksum
How to use checksums
22f393c23d3ac4c3964033b2579c6ad6ef80f46c4fd8c7dd8240b46788d066d2
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.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 544.0 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5968ec61248729e63e8477c042d67f513e8dcc2e07e00a4031d9ca4d116434b9
BLAKE2b-256 checksum
How to use checksums
bf4b6922d062d0cc9c5b529f3b8327a662911c3b2d84b78b3e7f5a6236497f8e
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.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 510.6 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
02721b271623fa6dba322c144f9ea25129796d8b00878bd23be3ec415107db50
BLAKE2b-256 checksum
How to use checksums
a41ed792a947cfd853fc56ca249e0129723b69a299a55078beb8f9cbfca7de0d
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.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pyrebasis-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 529.9 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4cc500b2b1f49e005aa5667b1f1dc7172cb45fc4446de43f3c5df9cfd6741e0a
BLAKE2b-256 checksum
How to use checksums
656e16551fb6a93d4039e751b2a87b1623e5ae6cf228817ae1d39fe4b5349daf
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

0.2.1

11 release files

This release

0.2.0 This release

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