Getting started
Installation
Use Python 3.14 or later.
Choose either uv or the traditional venv and pip workflow to install sensorfusion-tools from PyPI.
Both install the published package and its dependencies.
The Python import name is sftools, not sensorfusion-tools.
Using uv
Install uv, then create a project and add the library:
uv init --python 3.14 sensorfusion-example
cd sensorfusion-example
uv add sensorfusion-tools
In an existing uv project with Python 3.14 or later, run uv add sensorfusion-tools.
uv records the dependency in the project and manages its environment.
Using venv and pip
Create a project directory and a virtual environment using Python 3.14 or later. On macOS or Linux:
mkdir sensorfusion-example
cd sensorfusion-example
python3.14 -m venv .venv
source .venv/bin/activate
python -m pip install sensorfusion-tools
On Windows, in PowerShell:
mkdir sensorfusion-example
cd sensorfusion-example
py -3.14 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install sensorfusion-tools
Activate the environment again whenever you open a new terminal for the project.
Run deactivate when you want to leave it.
A first estimate
Save the following as first_estimate.py in your project directory.
It creates a linear observation model, simulates a noisy observation, and computes a weighted least-squares estimate.
import numpy as np
from sftools import create_observation, estimator
rng = np.random.default_rng(0)
model = create_observation(
"linear",
H=np.eye(2),
R=np.diag([0.1, 0.2]),
)
truth = np.array([[1.0], [2.0]])
measurement = model.random(x=truth, rng=rng)
estimate = estimator.wls(model, measurement, np.zeros((2, 1)))
print("Mean:", estimate.mean())
print("Covariance:", estimate.cov())
If you used uv, run it with:
uv run first_estimate.py
If you used venv and pip, run the script with the Python interpreter in your activated virtual environment.
The example prints:
Mean: [[0.95822477]
[2.05622826]]
Covariance: [[0.1 0. ]
[0. 0.2]]
Both the true state and the observation are explicit columns.
The returned GaussianState exposes the estimated mean through .mean() and covariance through .cov().
Next steps
Read the dimension conventions before adapting the example. The tracking example combines motion models, measurements, and a Kalman filter.