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
16 changes: 11 additions & 5 deletions .github/workflows/signaloid-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
args:
- host: ubuntu-22.04
- host: macos-14
python-version: ["3.10", "3.11", "3.13"]

runs-on: ${{ matrix.args.host }}

Expand All @@ -31,6 +32,8 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
fetch-tags: true

- name: Debug
run: |
Expand All @@ -43,10 +46,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: ${{ matrix.python-version }}

- name: Install Poetry Action
run: python -m pip install poetry==1.4.0
run: python -m pip install poetry==1.8.0

- name: Print Poetry version
run: poetry --version
Expand All @@ -57,6 +60,9 @@ jobs:
- name: Install
run: poetry install

- name: Install Poetry plugins
run: poetry self add "poetry-dynamic-versioning[plugin]>=1.0.0,<2.0.0"

- name: Print Python Information
run: |
which python
Expand All @@ -81,12 +87,12 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
name: "test-logs-${{matrix.args.host}}-${{ github.event.pull_request.head.sha || github.sha }}"
name: "test-logs-${{matrix.args.host}}-py${{ matrix.python-version }}-${{ github.event.pull_request.head.sha || github.sha }}"
path: |
./src/signaloid/distributional_information_plotting/tests/testdata/Brown-Ham-model-actual-results_df.csv

- name: Upload wheels
if: ${{ startsWith(matrix.args.host, 'ubuntu') }}
if: ${{ startsWith(matrix.args.host, 'ubuntu') && matrix.python-version == '3.11' }}
uses: actions/upload-artifact@v4
with:
name: "wheel-${{ github.event.pull_request.head.sha || github.sha }}"
Expand All @@ -95,7 +101,7 @@ jobs:

# Upload the artifact to the GitHub release
- name: Upload Release Asset
if: ${{ github.event_name == 'release' && startsWith(matrix.args.host, 'ubuntu') }}
if: ${{ github.event_name == 'release' && startsWith(matrix.args.host, 'ubuntu') && matrix.python-version == '3.11' }}
run: |
gh release upload ${{ github.event.release.tag_name }} dist/*
env:
Expand Down
842 changes: 373 additions & 469 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "signaloid"
version = "1.7.2"
version = "0.0.0"
description = ""
authors = [
"Signaloid <info@signaloid.com>"
Expand All @@ -10,24 +10,30 @@ packages = [
{ include = "signaloid", from = "src" }
]

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "pep440"


[tool.poetry.group.dev.dependencies]
wheel = "^0.46.3"
pex = "^2.87.0"
types-toml = "^0.10.8.20240310"
pytest = "^8.4.2"
mypy = "^1.19.1"
flake8 = "^7.3.0"
toml = "^0.10.2"
black = {version = "^25.11.0", python = ">=3.9"}
black = {version = "^25.11.0", python = ">=3.10"}

[build-system]
requires = ["poetry_core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry.dependencies]
python = ">=3.9,<3.14"
python = ">=3.10,<3.14"
numpy = "~2.0.2"
matplotlib = "~3.9.4"
Pillow = "~12.1.1"

[tool.poetry.scripts]
signaloid-uxdata-toolkit = "signaloid.uxdata_toolkit:main"
Expand All @@ -36,7 +42,7 @@ signaloid-uxdata-toolkit = "signaloid.uxdata_toolkit:main"
warn_unused_configs = true
strict = true
disallow_any_generics = false
python_version = "3.9"
python_version = "3.10"

[[tool.mypy.overrides]]
module = [
Expand Down
2 changes: 1 addition & 1 deletion src/signaloid/circuitpython/extended_ulab_numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down
3 changes: 2 additions & 1 deletion src/signaloid/circuitpython/plot_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -38,6 +38,7 @@
PlotData,
)


# The background color of the plot
BG_COLOR = 0xFFFFFF
BG_COLOR_STR = f"{BG_COLOR:06x}"
Expand Down
4 changes: 2 additions & 2 deletions src/signaloid/distributional/dirac_delta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -174,7 +174,7 @@ def __ne__(self, other: object) -> bool:
return self.position != other.position

def __ge__(self, other: "DiracDelta") -> bool:
"""Checks if this Dirac Delta is greater than the given Dirac Delta.
"""Checks if this Dirac Delta is greater than or equal to the given Dirac Delta.

:param other: The second Dirac Delta to use for the comparison.
:type other: DiracDelta
Expand Down
2 changes: 1 addition & 1 deletion src/signaloid/distributional/dirac_delta_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
11 changes: 7 additions & 4 deletions src/signaloid/distributional/distributional.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -191,7 +191,10 @@ def calculate_mean(self) -> float | None:
total_weighted_position += dd.position * dd.mass
total_mass += dd.mass

self._mean = total_weighted_position / total_mass
if total_mass == 0:
self._mean = np.nan
else:
self._mean = total_weighted_position / total_mass

return self._mean

Expand Down Expand Up @@ -286,7 +289,7 @@ def export(self, to_str: bool = True) -> str | bytes:
Constructs the Ux string/Ux bytes with particle value for the `DistributionalValue`.

Args:
to_str: Weather to export a Ux string or a Ux bytes
to_str: Whether to export a Ux string or a Ux bytes
- True: Export a Ux string
- False: Export a Ux bytes

Expand Down Expand Up @@ -551,7 +554,7 @@ def mean_relative_diff(self, other: "DistributionalValue") -> float:
The relative difference between the mean values (normalized by
the mean value of the other `DistributionalValue`).
"""
if self.mean is None or other.mean is None:
if self.mean is None or other.mean is None or other.mean == 0:
return math.nan

return abs((self.mean - other.mean) / other.mean)
Expand Down
2 changes: 1 addition & 1 deletion src/signaloid/distributional/distributional_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

class PlotData:
def __init__(
self, dist: DistributionalValue, plotting_resolution: int | None = None
self,
dist: DistributionalValue,
plotting_resolution: int | None = None,
) -> None:
if dist.mean is None or dist.UR_order == 0:
raise ValueError("Failed to load data")
Expand Down Expand Up @@ -369,7 +371,7 @@ def _get_binning(
return (boundary_positions, bin_widths, bin_heights)

@staticmethod
def _create_binning(
def create_binning(
finite_sorted_dirac_deltas: list[DiracDelta],
exponent: int,
use_ttr_binning: bool,
Expand Down Expand Up @@ -557,21 +559,33 @@ def _construct_plot_data(self) -> None:
"plot_histogram_dirac_deltas: plotting_resolution must be a power of 2!"
)

# Create the binning such that the average of two bins surrounding a Dirac delta
# is the Dirac delta itself.
boundary_positions, bin_widths, bin_heights = PlotData._create_binning(
finite_dirac_deltas, 0, False
)
try:
# Create the binning such that the average of two bins surrounding a Dirac delta
# is the Dirac delta itself.
boundary_positions, bin_widths, bin_heights = PlotData.create_binning(
finite_dirac_deltas, 0, False
)

# Find the TTR of the created binning. This is always a valid TTR.
ttr = PlotData._bin_pdf_to_ttr(
boundary_positions, bin_widths, bin_heights, self.plotting_ttr_order
)
# Find the TTR of the created binning. This is always a valid TTR.
ttr = PlotData._bin_pdf_to_ttr(
boundary_positions, bin_widths, bin_heights, self.plotting_ttr_order
)

# Create the binning from the obtained (valid) TTR using the TTR binning method.
boundary_positions, bin_widths, bin_heights = PlotData._create_binning(
ttr, self.plotting_ttr_order, True
)
# Create the binning from the obtained (valid) TTR using the TTR binning method.
boundary_positions, bin_widths, bin_heights = PlotData.create_binning(
ttr, self.plotting_ttr_order, True
)

self.positions = boundary_positions
self.masses = bin_heights
except (ValueError, TypeError):
positions = np.array([dd.position for dd in finite_dirac_deltas])
masses = np.array([dd.mass for dd in finite_dirac_deltas])

midpoints = (positions[:-1] + positions[1:]) / 2
left = 2 * positions[0] - midpoints[0]
right = 2 * positions[-1] - midpoints[-1]
self.positions = np.concatenate(([left], midpoints, [right]))

self.positions = boundary_positions
self.masses = bin_heights
widths = np.diff(self.positions)
self.masses = masses / widths
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_create_binning_property_dirac_deltas_average_of_bins(self) -> None:
input_dirac_delta_ensembles.append(dirac_deltas)

for i, input_ensemble in enumerate(input_dirac_delta_ensembles):
boundary_positions, bin_widths, bin_heights = PlotData._create_binning(
boundary_positions, bin_widths, bin_heights = PlotData.create_binning(
input_ensemble, 0, False
)

Expand Down Expand Up @@ -133,7 +133,7 @@ def test_create_binning_property_preserve_ttr(self) -> None:
for i, input_ttr in enumerate(input_ttrs):
exponent = ttr_orders[i]

boundary_positions, bin_widths, bin_heights = PlotData._create_binning(
boundary_positions, bin_widths, bin_heights = PlotData.create_binning(
input_ttr, exponent, True
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, Signaloid.
# Copyright (c) 2026, Signaloid.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
Loading
Loading