Skip to content

Commit

Permalink
Merge pull request #148 from ezmsg-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pperanich authored Sep 18, 2024
2 parents 49506a0 + c9757d5 commit 25ddadd
Show file tree
Hide file tree
Showing 66 changed files with 1,763 additions and 2,018 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export VIRTUAL_ENV=.venv
layout python
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# chore: format files with ruff. Add pre-commit-config.
5b4c220154d33cac15a75d3d7d978a75e67f2b8a
# Ran `black` formatter on entire codebase and fixed non-standard line-endings with `dos2unix`.
4e4f20be40a73f2162a565732bae76ea0c812739
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test package

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
run: uv run pytest tests
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Upload Python Package

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Build Package
run: uv build

- name: Publish Package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: uvx twine upload dist/*
40 changes: 0 additions & 40 deletions .github/workflows/python-publish-ezmsg.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .github/workflows/python-tests.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
9 changes: 4 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.napoleon"
"sphinx.ext.napoleon",
]

intersphinx_mapping = {
Expand Down Expand Up @@ -46,15 +46,14 @@


def linkcode_resolve(domain, info):
if domain != 'py':
if domain != "py":
return None
if not info['module']:
if not info["module"]:
return None
filename = info['module'].replace('.', '/')
filename = info["module"].replace(".", "/")
if "sigproc" in filename:
return f"{sigproc_code_url}src/{filename}.py"
elif "core" in filename:
return f"{code_url}src/ezmsg/core/__init__.py"
else:
return f"{code_url}src/{filename}.py"

34 changes: 34 additions & 0 deletions docs/source/extensions/sigproc.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
ezmsg-sigproc
=============

Timeseries signal processing implementations in ezmsg, leveraging numpy and scipy.
Most of the methods and classes in this extension are intended to be used in building signal processing pipelines.
They use :class:`ezmsg.util.messages.axisarray.AxisArray` as the primary data structure for passing signals between components.
The message's data are expected to be a numpy array.

Note for offline processing: some generators might yield valid :class:`AxisArray` messages with ``.data`` size of 0.
This may occur when the generator receives inadequate data to produce a valid output, such as when windowing or buffering.

ezmsg.sigproc.activation
-----------------------------

.. automodule:: ezmsg.sigproc.activation
:members:


ezmsg.sigproc.affinetransform
-----------------------------

Expand Down Expand Up @@ -57,6 +72,25 @@ ezmsg.sigproc.ewmfilter
:members:


ezmsg.sigproc.math
-----------------------

.. automodule:: ezmsg.sigproc.math.clip
:members:

.. automodule:: ezmsg.sigproc.math.difference
:members:

.. automodule:: ezmsg.sigproc.math.invert
:members:

.. automodule:: ezmsg.sigproc.math.log
:members:

.. automodule:: ezmsg.sigproc.math.scale
:members:


ezmsg.sigproc.sampler
---------------------

Expand Down
11 changes: 5 additions & 6 deletions examples/ezmsg_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TerminatorSettings(ez.Settings):


class Terminator(ez.Unit):
SETTINGS: TerminatorSettings
SETTINGS = TerminatorSettings

@ez.task
async def terminate(self) -> None:
Expand All @@ -31,7 +31,7 @@ class GeneratorSettings(ez.Settings):


class Generator(ez.Unit):
SETTINGS: GeneratorSettings
SETTINGS = GeneratorSettings

OUTPUT = ez.OutputStream(int)

Expand All @@ -51,7 +51,7 @@ class ModulusSettings(ez.Settings):


class Modulus(ez.Unit):
SETTINGS: ModulusSettings
SETTINGS = ModulusSettings

INPUT = ez.InputStream(int)
OUTPUT = ez.OutputStream(int)
Expand All @@ -70,7 +70,7 @@ class ListenerState(ez.State):


class Listener(ez.Unit):
STATE: ListenerState
STATE = ListenerState

INPUT = ez.InputStream(int)

Expand All @@ -93,8 +93,7 @@ def network(self) -> ez.NetworkDefinition:
# CORNER CASES


class EmptySystem(ez.Collection):
...
class EmptySystem(ez.Collection): ...


class EmptyTerminateSystem(ez.Collection):
Expand Down
18 changes: 14 additions & 4 deletions examples/ezmsg_count.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import time
import array
from dataclasses import dataclass
import ezmsg.core as ez
Expand All @@ -20,7 +21,7 @@ class CountSettings(ez.Settings):


class Count(ez.Unit):
SETTINGS: CountSettings
SETTINGS = CountSettings

OUTPUT = ez.OutputStream(int)

Expand All @@ -29,14 +30,23 @@ async def count(self) -> AsyncGenerator:
count = 0
while True:
await asyncio.sleep(0.1)
yield self.OUTPUT, CountMessage(
value=count, arr=array.array("b", [0x00] * (2**count))
yield (
self.OUTPUT,
CountMessage(value=count, arr=array.array("b", [0x00] * (2**count))),
)
count = count + 1

if count >= self.SETTINGS.num_msgs:
raise ez.Complete

@ez.thread
def hello_world(self):
i = 0
while True:
print(f"Hello world {i}")
i += 1
time.sleep(1)


class CountSystem(ez.Collection):
COUNT = Count()
Expand All @@ -61,4 +71,4 @@ def process_components(self):
# multiprocessing.set_start_method('spawn', force=True)

system = CountSystem()
ez.run(SYSTEM = system)
ez.run(SYSTEM=system)
13 changes: 4 additions & 9 deletions examples/ezmsg_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PowSettings(ez.Settings):


class Pow(Gen):
SETTINGS: PowSettings
SETTINGS = PowSettings

def construct_generator(self):
self.STATE.gen = pow(self.SETTINGS.n)
Expand All @@ -66,7 +66,7 @@ class AddSettings(ez.Settings):


class Add(Gen):
SETTINGS: AddSettings
SETTINGS = AddSettings

def construct_generator(self):
self.STATE.gen = add(self.SETTINGS.n)
Expand Down Expand Up @@ -123,10 +123,7 @@ def network(self):
(self.POW_0_5.OUTPUT, self.LOG_OUT.INPUT),
)

ez.run(
SYSTEM=GenOneExample()
)

ez.run(SYSTEM=GenOneExample())

# This example will show the type-hint based introspection to construct ezmsg Units
# at runtime, which simplifies the integration of generators into Units, reducing
Expand Down Expand Up @@ -158,6 +155,4 @@ def network(self):
(self.POW_0_5.OUTPUT, self.LOG_OUT.INPUT),
)

ez.run(
SYSTEM=GenTwoExample()
)
ez.run(SYSTEM=GenTwoExample())
Loading

0 comments on commit 25ddadd

Please sign in to comment.