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
9 changes: 6 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[flake8]
max-complexity = 20
max-line-length = 79
max-complexity = 10
max-line-length = 88

extend-ignore =
# Let formatting take care of line length (not flake8)
E501
E203

per-file-ignores =
src/signaloid/distributional_information_plotting/*: F841
# Ignore complex mains in these scripts for now
# We should aim is to address all of these in the future
src/signaloid/distributional_information_plotting/*: C901
src/signaloid/distributional/*: C901

3 changes: 3 additions & 0 deletions .github/workflows/signaloid-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ jobs:
- name: Lint
run: poetry run flake8 src/

- name: Check format
run: poetry run black --check src/

- name: Typecheck
run: poetry run mypy -p signaloid

Expand Down
337 changes: 245 additions & 92 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "signaloid"
version = "1.7.0"
version = "1.7.2"
description = ""
authors = [
"Signaloid <info@signaloid.com>"
Expand All @@ -18,6 +18,7 @@ pytest = "^8.4.2"
mypy = "^1.19.1"
flake8 = "^7.3.0"
toml = "^0.10.2"
black = {version = "^25.11.0", python = ">=3.9"}

[build-system]
requires = ["poetry_core>=1.0.0"]
Expand All @@ -34,6 +35,8 @@ signaloid-uxdata-toolkit = "signaloid.uxdata_toolkit:main"
[tool.mypy]
warn_unused_configs = true
strict = true
disallow_any_generics = false
python_version = "3.9"

[[tool.mypy.overrides]]
module = [
Expand Down
55 changes: 25 additions & 30 deletions src/signaloid/circuitpython/plot_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
from circuitpython_uplot.scatter import Pointer, Scatter

from signaloid.circuitpython.extended_ulab_numpy import np
from signaloid.distributional_information_plotting.plot_histogram_dirac_deltas import \
PlotData

from signaloid.distributional_information_plotting.plot_histogram_dirac_deltas import (
PlotData,
)

# The background color of the plot
BG_COLOR = 0xFFFFFF
Expand Down Expand Up @@ -73,15 +73,15 @@


def apply_array_multiplier(arr, multiplier):
arr = np.divide(arr, 10 ** multiplier)
arr = np.divide(arr, 10**multiplier)

return arr


def transform_array_with_multiplier(arr):
max_value = max(np.abs(arr))
multiplier = int(math.log(max_value, 10)) + (-1 if max_value < 1 else 0)
arr = np.divide(arr, 10 ** multiplier)
arr = np.divide(arr, 10**multiplier)

return arr, multiplier

Expand Down Expand Up @@ -193,8 +193,8 @@ def render_histogram(plot, boundary_positions, bin_heights, width, align, edgeco


def render_x_multiplier(g, c, multiplier):
anchored_x = c.points[1][0] + X_SHIFT - .5 * TICK_SIZE
anchored_y = c.points[1][1] - Y_SHIFT + .5 * TICK_SIZE
anchored_x = c.points[1][0] + X_SHIFT - 0.5 * TICK_SIZE
anchored_y = c.points[1][1] - Y_SHIFT + 0.5 * TICK_SIZE
text_area = label.Label(
font=terminalio.FONT,
text=f"e{multiplier:+d}",
Expand All @@ -209,7 +209,7 @@ def render_x_multiplier(g, c, multiplier):

def render_y_multiplier(g, c, multiplier):
minh = min(c.points[:][1])
anchored_x = c.points[1][0] + X_SHIFT - .5 * TICK_SIZE
anchored_x = c.points[1][0] + X_SHIFT - 0.5 * TICK_SIZE
anchored_y = minh - 2 * TICK_SIZE
text_area = label.Label(
font=terminalio.FONT,
Expand All @@ -230,7 +230,10 @@ def render_non_finite_values(g, nan, neg_inf, pos_inf):
color=TEXT_COLOR,
line_spacing=0.8,
anchor_point=(0.5, 1.0),
anchored_position=(board.DISPLAY.width // 2, board.DISPLAY.height - 1.5 * TICK_SIZE),
anchored_position=(
board.DISPLAY.width // 2,
board.DISPLAY.height - 1.5 * TICK_SIZE,
),
label_direction="LTR",
)
g.append(text_area)
Expand Down Expand Up @@ -342,7 +345,9 @@ def render_particle_value_value_label(g, particle_value):
g.append(text_area)


def render_particle_value_line(plot, particle_value, bin_heights, width, rangex, rangey, facecolor):
def render_particle_value_line(
plot, particle_value, bin_heights, width, rangex, rangey, facecolor
):
# To draw the particle value, we need to create a rectangle, the same
# way we create the histogram bars

Expand Down Expand Up @@ -389,18 +394,14 @@ def render_particle_value_line_label(g, c):

def render_logo(g):
# Add the Signaloid logo to the top right corner of the screen
bitmap = displayio.OnDiskBitmap(
open("assets/signaloid_logo_24x24.bmp", "rb")
)
bitmap = displayio.OnDiskBitmap(open("assets/signaloid_logo_24x24.bmp", "rb"))
sprite = displayio.TileGrid(
bitmap,
pixel_shader=bitmap.pixel_shader,
width=1,
height=1,
)
sprite.x = (
board.DISPLAY.width - SIGNALOID_LOGO_SIZE - SIGNALOID_LOGO_MARGIN
)
sprite.x = board.DISPLAY.width - SIGNALOID_LOGO_SIZE - SIGNALOID_LOGO_MARGIN
sprite.y = SIGNALOID_LOGO_MARGIN
g.append(sprite)

Expand Down Expand Up @@ -442,17 +443,14 @@ def bar(
render_bg_plot(g)
plot = create_main_plot(g)

boundary_positions, boundary_multiplier = transform_array_with_multiplier(boundary_positions)
boundary_positions, boundary_multiplier = transform_array_with_multiplier(
boundary_positions
)
bin_heights, bin_heights_multiplier = transform_array_with_multiplier(bin_heights)
width = apply_array_multiplier(width, boundary_multiplier)

c, rangex, rangey = render_histogram(
plot,
boundary_positions,
bin_heights,
width,
align,
edgecolor
plot, boundary_positions, bin_heights, width, align, edgecolor
)

render_x_multiplier(g, c, boundary_multiplier)
Expand All @@ -463,7 +461,7 @@ def bar(
g,
plot_data.dist.nan_dirac_delta.mass,
plot_data.dist.neg_inf_dirac_delta.mass,
plot_data.dist.pos_inf_dirac_delta.mass
plot_data.dist.pos_inf_dirac_delta.mass,
)

render_title(g, title)
Expand All @@ -472,11 +470,8 @@ def bar(
render_y_axis_label(g)

# Show the particle value
if (
particle_value is not None
and np.isfinite(particle_value)
):
particle_value_normalized = particle_value / (10 ** boundary_multiplier)
if particle_value is not None and np.isfinite(particle_value):
particle_value_normalized = particle_value / (10**boundary_multiplier)
if (
particle_value_normalized >= rangex[0]
and particle_value_normalized <= rangex[1]
Expand All @@ -488,7 +483,7 @@ def bar(
width,
rangex,
rangey,
facecolor
facecolor,
)
render_particle_value_line_label(g, c)

Expand Down
2 changes: 1 addition & 1 deletion src/signaloid/distributional/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from signaloid.distributional.distributional import DistributionalValue
from signaloid.distributional.dirac_delta import DiracDelta

__all__ = ['DistributionalValue', 'DiracDelta']
__all__ = ["DistributionalValue", "DiracDelta"]
17 changes: 6 additions & 11 deletions src/signaloid/distributional/dirac_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import annotations
import sys
import math

if sys.implementation.name != 'circuitpython':
from typing import Optional

if sys.implementation.name != "circuitpython":
# Use numpy for accelerated computing
import numpy as np
else:
Expand All @@ -36,10 +35,7 @@

class DiracDelta:
def __init__(
self,
position: float,
raw_mass: Optional[int] = None,
mass: Optional[float] = None
self, position: float, raw_mass: int | None = None, mass: float | None = None
) -> None:
"""Initializes the Dirac Delta, given a position, and a mass in either
a fixed-point or a floating point representation. If both representations
Expand All @@ -50,10 +46,10 @@ def __init__(
:type position: float
:param raw_mass: The Dirac Delta mass in 64bit fixed-point representation,
defaults to None.
:type raw_mass: Optional[int]
:type raw_mass: int | None
:param mass: The Dirac Delta mass in floating-point representation,
defaults to None.
:type mass: Optional[float]
:type mass: float | None
"""
self.position: float = position
self._raw_mass: int = 0
Expand Down Expand Up @@ -124,8 +120,7 @@ def __add__(self, other: "DiracDelta") -> "DiracDelta":
"""
combined_mass: float = self.mass + other.mass
combined_position: float = (
self.position * self.mass
+ other.position * other.mass
self.position * self.mass + other.position * other.mass
) / combined_mass

return DiracDelta(position=combined_position, mass=combined_mass)
Expand Down
5 changes: 1 addition & 4 deletions src/signaloid/distributional/dirac_delta_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ def test_dirac_delta_operations(self) -> None:
d3 = d1 + d2

combined_mass: float = 2.3 + 5.6
combined_position: float = (
1.2 * 2.3
+ 4.5 * 5.6
) / combined_mass
combined_position: float = (1.2 * 2.3 + 4.5 * 5.6) / combined_mass
self.assertTrue(d3.position == combined_position)
self.assertTrue(d3.mass == combined_mass)

Expand Down
Loading
Loading