Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
max-complexity = 10
max-line-length = 88

extend-ignore =
extend-ignore =
# Let formatting take care of line length (not flake8)
E501
E203
Expand All @@ -12,4 +12,3 @@ per-file-ignores =
# We should aim is to address all of these in the future
src/signaloid/distributional_information_plotting/*: C901
src/signaloid/distributional/*: C901

13 changes: 8 additions & 5 deletions .github/workflows/signaloid-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: Checkout the PR branch
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
Expand All @@ -44,7 +44,7 @@ jobs:
echo "contains(github.event.pull_request.labels, 'ci:upload-binaries'):" ${{ contains(github.event.pull_request.labels, 'ci:"upload-binaries') }}

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -58,7 +58,8 @@ jobs:
run: ls

- name: Install
run: poetry install
# Testing needs the optional dependencies
run: poetry install --all-extras

- name: Install Poetry plugins
run: poetry self add "poetry-dynamic-versioning[plugin]>=1.0.0,<2.0.0"
Expand All @@ -75,6 +76,8 @@ jobs:
run: poetry run black --check src/

- name: Typecheck
# Run mypy just once on the oldest supported Python version
if: ${{ matrix.args.host == 'ubuntu-22.04' && matrix.python-version == '3.10' }}
run: poetry run mypy -p signaloid

- name: Test
Expand All @@ -84,7 +87,7 @@ jobs:
run: poetry build

- name: Upload test logs
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
if: always()
with:
name: "test-logs-${{matrix.args.host}}-py${{ matrix.python-version }}-${{ github.event.pull_request.head.sha || github.sha }}"
Expand All @@ -93,7 +96,7 @@ jobs:

- name: Upload wheels
if: ${{ startsWith(matrix.args.host, 'ubuntu') && matrix.python-version == '3.11' }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: "wheel-${{ github.event.pull_request.head.sha || github.sha }}"
path: |
Expand Down
67 changes: 49 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@
# signaloid-python
This repository contains a set of tools for parsing and plotting Signaloid distributional data in python. The code has been tested on MacOS-14 and Ubuntu-20.04 using python 3.11.
# Signaloid Python Library and SDK

## Installation:
You can install the latest version of `signaloid-python` package via pip:
The Signaloid Python Library and SDK provides tools for interacting with
applications that utilize Signaloid's UxHw® technology for distributional
arithmetic. Use the library to analyze Ux Data values from the application.


## Requirements

The Signaloid Python Library and SDK requires Python 3.10 or later. See
`pyproject.toml` for the full list of dependencies.

## Installation
Install `signaloid-python` package via pip (recommended):
```bash
pip install git+https://github.com/signaloid/signaloid-python
python -m pip install signaloid-python
```

## Parse `Ux` data
You can construct `DistributionalValue` objects by parsing `Ux` string or `Ux` bytes. You can find more details about the Signaloid `Ux` format [here](https://docs.signaloid.io/docs/hardware-api/ux-data-format/). Following is an example of parsing `Ux` strings and `Ux` bytes.

Install the latest version from the GitHub repository:
```bash
python -m pip install git+https://github.com/signaloid/signaloid-python
```

Alternatively, clone this repository and install from source with:
```bash
python -m pip install .
```

## Usage


### Parsing Ux Data
Construct `DistributionalValue` Python objects by parsing
[Ux Data](https://docs.signaloid.io/docs/uxhw-api/ux-data-format/) in
Ux String or Ux Binary format.

```python
from signaloid.distributional.distributional import DistributionalValue

...
# Intermediate code which writes to ux_string and ux_binary_buffer
# ...

# Parse a Ux string
distValue = DistributionalValue.parse(ux_string)
# Parse a Ux String
dist_value = DistributionalValue.parse(ux_string)

# Parse a Ux bytes buffer
distValue = DistributionalValue.parse(ux_bytes_buffer)
# Parse a Ux Binary buffer
dist_value = DistributionalValue.parse(ux_binary_buffer)
```

## Plot `DistributionalValue` objects
You can use the `PlotHistogramDiracDeltas` class for plotting a distributional value as a histogram with variable bin width. We also provide a wrapper function to assist plotting. You can use the `plot` function, which you can find [here](./src/signaloid/distributional_information_plotting/plot_wrapper.py), to easily plot a distributional value like in the following example:
### Create Distribution Plots
Create plots to visualize distributional information by using the
[`plot` function](./src/signaloid/distributional_information_plotting/plot_wrapper.py)
with a `DistributionalValue` object containing Ux Data. The `plot` function is a
wrapper function for the `PlotHistogramDiracDeltas` class for plotting a
distributional value as a histogram with variable bin widths.

```python
from signaloid.distributional_information_plotting.plot_wrapper import plot

...
# Intermediate code which writes to ux_string
# ...

# Create distributional value object from string
distValue = DistributionalValue.parse(ux_string)
plot(distValue)
# Create distributional value object from Ux String
dist_value = DistributionalValue.parse(ux_string)
plot(dist_value)
```
Loading
Loading