Analog sensor signal conversion
Project description
scietex.hal.analog_sensor
The scietex.hal.analog_sensor package is a Python library for interfacing with and processing
data from analog sensors. It provides an abstract base class (AnalogSensorInterface) and concrete
implementations for converting analog voltage readings into physical quantities (e.g., temperature,
pressure) using linear transformations and advanced interpolation techniques.
Features
- Abstract base class (
AnalogSensorInterface) for consistent sensor implementations. - Support for single
floatvalues and NumPy arrays (NDArray[np.float64]) for batch processing. - Linear sensor models:
LinearSensor: Basic linear transformation (gain * voltage + offset).LinearLimitedSensor: Linear transformation with voltage clamping.
- Interpolation-based sensors for non-linear data:
LinearInterpolatorSensor: Linear interpolation using NumPy.CubicSplineInterpolatorSensor: Cubic spline interpolation with configurable boundary conditions.AkimaInterpolatorSensor: Akima interpolation for smooth curves with less overshoot.PchipInterpolatorSensor: PCHIP interpolation for shape-preserving curves.
- Extensible design for custom sensor models.
- Built on NumPy and SciPy for efficient numerical and interpolation operations.
Installation
Install the package via pip (assuming it’s published to PyPI):
pip install scietex.hal.analog_sensor
Alternatively, clone the repository and install locally:
git clone https://github.com/bond-anton/scietex.hal.analog_sensor.git
cd scietex.hal.analog_sensor
pip install .
Requirements
- Python 3.9 or higher.
numpy(for array operations and linear interpolation).scipy(for cubic spline, Akima, and PCHIP interpolation).
Usage
The package uses AnalogSensorInterface as a base class, requiring subclasses to implement
convert_voltage.
Linear sensors use a simple gain-offset model, while interpolation-based sensors require
calibration data.
Basic example with a linear sensor:
from scietex.hal.analog_sensor import LinearSensor
# Linear sensor: output = gain * voltage + offset
sensor = LinearSensor(model_name="PressureSensor", gain=0.5, offset=10)
# Convert a voltage
value = sensor.convert_voltage(100)
print(f"Physical value: {value}") # Output: 60.0
Using cubic spline interpolation:
import numpy as np
from scietex.hal.analog_sensor import CubicSplineInterpolatorSensor
# Calibration data: [voltage, physical value]
data = np.array([[0, 0], [50, 25], [100, 50]])
sensor = CubicSplineInterpolatorSensor(
model_name="LightSensor", data=data, bc="natural"
)
# Convert an array of voltages
voltages = np.array([25, 75])
values = sensor.convert_voltage(voltages)
print(f"Physical values: {values}") # Output depends on spline fit
Modules
AnalogSensorInterface(ininterface.py):- Abstract base class requiring
convert_voltageimplementation. - Attributes:
model_name(str) for sensor identification. - Supports single float or NumPy array inputs/outputs.
- Abstract base class requiring
LinearSensor(inlinear.py):- Linear transformation:
gain * voltage + offset. - Args:
model_name,gain,offset(optional, default 0.0).
- Linear transformation:
LinearLimitedSensor(inlinear.py):- Linear transformation with voltage clamping between
v_minandv_max. - Args:
v_min,v_max,model_name,gain,offset(optional, default 0.0).
- Linear transformation with voltage clamping between
LinearInterpolatorSensor(ininterpolation.py):- Linear interpolation using
np.interp. - Args:
model_name,data(2D array: voltage, physical value),extrapolate(optional).
- Linear interpolation using
CubicSplineInterpolatorSensor(ininterpolation.py):- Cubic spline interpolation via
scipy.interpolate.CubicSpline. - Args:
model_name,data,bc(e.g., "natural", "clamped"),extrapolate(optional).
- Cubic spline interpolation via
AkimaInterpolatorSensor(ininterpolation.py):- Akima interpolation via
scipy.interpolate.Akima1DInterpolator. - Args:
model_name,data,extrapolate(optional, SciPy 1.14+).
- Akima interpolation via
PchipInterpolatorSensor(ininterpolation.py):- PCHIP interpolation via
scipy.interpolate.PchipInterpolator. - Args:
model_name,data,extrapolate(optional).
- PCHIP interpolation via
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m "Add your message"). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
Please include tests (if applicable) and follow PEP 8 style guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scietex_hal_analog_sensor-1.0.1.tar.gz.
File metadata
- Download URL: scietex_hal_analog_sensor-1.0.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b74b140239d9f7d4f031bda8d34fb408ab07aab40e4674b47bd3953a6331f4
|
|
| MD5 |
0260104ea6a565a55d51432990387613
|
|
| BLAKE2b-256 |
62a7705b1988c6606245e794e5d462ff7dfc33b7b0f850494f13ec47bd0e2965
|
Provenance
The following attestation bundles were made for scietex_hal_analog_sensor-1.0.1.tar.gz:
Publisher:
python-publish.yml on bond-anton/scietex.hal.analog_sensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scietex_hal_analog_sensor-1.0.1.tar.gz -
Subject digest:
e6b74b140239d9f7d4f031bda8d34fb408ab07aab40e4674b47bd3953a6331f4 - Sigstore transparency entry: 183245758
- Sigstore integration time:
-
Permalink:
bond-anton/scietex.hal.analog_sensor@9dc4df46945d8c59af5daaacb4d7c0194577dcce -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/bond-anton
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9dc4df46945d8c59af5daaacb4d7c0194577dcce -
Trigger Event:
release
-
Statement type:
File details
Details for the file scietex_hal_analog_sensor-1.0.1-py3-none-any.whl.
File metadata
- Download URL: scietex_hal_analog_sensor-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17b740757a77f0be975555ae83526480ac276729545cd424e0ef8f7470301d7c
|
|
| MD5 |
1124e062971e3b58f9332af9815ad78e
|
|
| BLAKE2b-256 |
1856b981612f2882f5a1237d7f97395b07de70703c734c90bf3d0dd291572d06
|
Provenance
The following attestation bundles were made for scietex_hal_analog_sensor-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on bond-anton/scietex.hal.analog_sensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scietex_hal_analog_sensor-1.0.1-py3-none-any.whl -
Subject digest:
17b740757a77f0be975555ae83526480ac276729545cd424e0ef8f7470301d7c - Sigstore transparency entry: 183245764
- Sigstore integration time:
-
Permalink:
bond-anton/scietex.hal.analog_sensor@9dc4df46945d8c59af5daaacb4d7c0194577dcce -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/bond-anton
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9dc4df46945d8c59af5daaacb4d7c0194577dcce -
Trigger Event:
release
-
Statement type: