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.
Metadata
Release files for scietex.hal.analog-sensor 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scietex_hal_analog_sensor-1.0.1.tar.gz | 13.1 kB | With provenance | Details for scietex_hal_analog_sensor-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scietex_hal_analog_sensor-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for scietex_hal_analog_sensor-1.0.1-py3-none-any.whl |
Total release size: 23.3 kB
Release files / scietex_hal_analog_sensor-1.0.1.tar.gz
| Download URL | scietex_hal_analog_sensor-1.0.1.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6b74b140239d9f7d4f031bda8d34fb408ab07aab40e4674b47bd3953a6331f4
|
|
BLAKE2b-256 checksum How to use checksums |
62a7705b1988c6606245e794e5d462ff7dfc33b7b0f850494f13ec47bd0e2965
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Mar 17, 2025.
Transparency logRelease files / scietex_hal_analog_sensor-1.0.1-py3-none-any.whl
| Download URL | scietex_hal_analog_sensor-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17b740757a77f0be975555ae83526480ac276729545cd424e0ef8f7470301d7c
|
|
BLAKE2b-256 checksum How to use checksums |
1856b981612f2882f5a1237d7f97395b07de70703c734c90bf3d0dd291572d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 Mar 17, 2025.
Transparency logSecurity for scietex.hal.analog-sensor 1.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for scietex_hal_analog_sensor-1.0.1.tar.gz
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 Mar 17, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.