ezmsg-event 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ name: Upload Python Package - ezmsg-event
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build:
10
+ name: build and upload release to PyPI
11
+ runs-on: ubuntu-latest
12
+ environment: "release"
13
+ permissions:
14
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v2
21
+
22
+ - name: Build Package
23
+ run: uv build
24
+
25
+ - name: Publish package distributions to PyPI
26
+ run: uv publish
@@ -0,0 +1,41 @@
1
+ name: Test package
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ build:
12
+ strategy:
13
+ matrix:
14
+ python-version: [3.9, "3.10", "3.11", "3.12"]
15
+ os:
16
+ - "ubuntu-latest"
17
+ - "windows-latest"
18
+ - "macos-latest"
19
+ runs-on: ${{matrix.os}}
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v2
26
+ with:
27
+ enable-cache: true
28
+ cache-dependency-glob: "uv.lock"
29
+
30
+ - name: Set up Python ${{ matrix.python-version }}
31
+ run: uv python install ${{ matrix.python-version }}
32
+
33
+ - name: Install the project
34
+ run: uv sync --all-extras --dev
35
+
36
+ - name: Lint
37
+ run:
38
+ uv tool run ruff check --output-format=github src
39
+
40
+ - name: Run tests
41
+ run: uv run pytest tests
@@ -0,0 +1,164 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ src/ezmsg/event/__version__.py
@@ -0,0 +1 @@
1
+ 3.9
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ezmsg-org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.3
2
+ Name: ezmsg-event
3
+ Version: 0.1.1
4
+ Summary: Namespace package for ezmsg to work with signal events like neural spikes and heartbeats
5
+ Author-email: Chadwick Boulay <chadwick.boulay@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.9
8
+ Requires-Dist: ezmsg-sigproc>=1.3.3
9
+ Requires-Dist: ezmsg>=3.5.0
10
+ Requires-Dist: numpy>=2.0.2
11
+ Requires-Dist: sparse>=0.15.4
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest>=8.3.3; extra == 'test'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # ezmsg-event
17
+
18
+ ezmsg namespace package for working with signal events like neural spikes and heartbeats
@@ -0,0 +1,3 @@
1
+ # ezmsg-event
2
+
3
+ ezmsg namespace package for working with signal events like neural spikes and heartbeats
@@ -0,0 +1,45 @@
1
+ import ezmsg.core as ez
2
+ from ezmsg.sigproc.math.log import Log
3
+ from ezmsg.util.debuglog import DebugLog
4
+ from ezmsg.util.messages.chunker import ArrayChunker
5
+ from ezmsg.util.terminate import TerminateOnTotal
6
+ import typer
7
+
8
+ from ezmsg.event.util.simulate import generate_white_noise_with_events
9
+ from ezmsg.event.peak import ThresholdCrossing
10
+ from ezmsg.event.rate import EventRate
11
+
12
+
13
+ def main(bin_duration: float = 0.05):
14
+ fs = 30_000.0
15
+ dur = 10.0
16
+ n_chans = 128
17
+ threshold = 2.5
18
+ rate_range = (10, 100)
19
+ chunk_dur = bin_duration / 2
20
+ chunk_len = int(fs * chunk_dur)
21
+ data = generate_white_noise_with_events(
22
+ fs, dur, n_chans, rate_range, chunk_dur, threshold
23
+ )
24
+ n_chunks = int(dur / bin_duration)
25
+
26
+ comps = {
27
+ "SOURCE": ArrayChunker(data, chunk_len, fs=fs),
28
+ "THRESH": ThresholdCrossing(threshold=threshold),
29
+ "RATE": EventRate(bin_duration=bin_duration),
30
+ "LOG10": Log(10, clip_zero=True),
31
+ "SINK": DebugLog(),
32
+ "TERM": TerminateOnTotal(n_chunks),
33
+ }
34
+ conns = (
35
+ (comps["SOURCE"].OUTPUT_SIGNAL, comps["THRESH"].INPUT_SIGNAL),
36
+ (comps["THRESH"].OUTPUT_SIGNAL, comps["RATE"].INPUT_SIGNAL),
37
+ (comps["RATE"].OUTPUT_SIGNAL, comps["LOG10"].INPUT_SIGNAL),
38
+ (comps["LOG10"].OUTPUT_SIGNAL, comps["SINK"].INPUT),
39
+ (comps["SINK"].OUTPUT, comps["TERM"].INPUT_MESSAGE),
40
+ )
41
+ ez.run(components=comps, connections=conns)
42
+
43
+
44
+ if __name__ == "__main__":
45
+ typer.run(main)
@@ -0,0 +1,65 @@
1
+ import ezmsg.core as ez
2
+ from ezmsg.util.messages.modify import ModifyAxis
3
+ from ezmsg.sigproc.aggregate import RangedAggregate, AggregationFunction
4
+ from ezmsg.sigproc.math.scale import Scale
5
+ from ezmsg.sigproc.math.log import Log
6
+ from ezmsg.util.debuglog import DebugLog
7
+ from ezmsg.util.messages.chunker import ArrayChunker
8
+ from ezmsg.util.terminate import TerminateOnTotal
9
+ import typer
10
+
11
+ from ezmsg.event.util.simulate import generate_white_noise_with_events
12
+ from ezmsg.event.window import Window
13
+ from ezmsg.event.peak import ThresholdCrossing
14
+ from ezmsg.event.sparse import Densify
15
+
16
+
17
+ def main(bin_duration: float = 0.05):
18
+ fs = 30_000.0
19
+ dur = 10.0
20
+ n_chans = 128
21
+ threshold = 2.5
22
+ rate_range = (10, 100)
23
+ chunk_dur = bin_duration / 2
24
+ chunk_len = int(fs * chunk_dur)
25
+ data = generate_white_noise_with_events(
26
+ fs, dur, n_chans, rate_range, chunk_dur, threshold
27
+ )
28
+ n_chunks = int(dur / bin_duration)
29
+
30
+ comps = {
31
+ "SOURCE": ArrayChunker(data, chunk_len, fs=fs),
32
+ "THRESH": ThresholdCrossing(threshold=threshold),
33
+ "WIN": Window(
34
+ axis="time",
35
+ newaxis="win",
36
+ window_dur=bin_duration,
37
+ window_shift=bin_duration,
38
+ zero_pad_until="none",
39
+ ),
40
+ "AGG": RangedAggregate(
41
+ axis="time", bands=[(0, bin_duration)], operation=AggregationFunction.SUM
42
+ ),
43
+ "SCALE": Scale(1 / bin_duration),
44
+ "DENSE": Densify(),
45
+ "AXIS": ModifyAxis(name_map={"time": None, "win": "time"}),
46
+ "LOG10": Log(10, clip_zero=True),
47
+ "SINK": DebugLog(),
48
+ "TERM": TerminateOnTotal(n_chunks),
49
+ }
50
+ conns = (
51
+ (comps["SOURCE"].OUTPUT_SIGNAL, comps["THRESH"].INPUT_SIGNAL),
52
+ (comps["THRESH"].OUTPUT_SIGNAL, comps["WIN"].INPUT_SIGNAL),
53
+ (comps["WIN"].OUTPUT_SIGNAL, comps["AGG"].INPUT_SIGNAL),
54
+ (comps["AGG"].OUTPUT_SIGNAL, comps["SCALE"].INPUT_SIGNAL),
55
+ (comps["SCALE"].OUTPUT_SIGNAL, comps["DENSE"].INPUT_SIGNAL),
56
+ (comps["DENSE"].OUTPUT_SIGNAL, comps["AXIS"].INPUT_SIGNAL),
57
+ (comps["AXIS"].OUTPUT_SIGNAL, comps["LOG10"].INPUT_SIGNAL),
58
+ (comps["LOG10"].OUTPUT_SIGNAL, comps["SINK"].INPUT),
59
+ (comps["SINK"].OUTPUT, comps["TERM"].INPUT_MESSAGE),
60
+ )
61
+ ez.run(components=comps, connections=conns)
62
+
63
+
64
+ if __name__ == "__main__":
65
+ typer.run(main)
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "ezmsg-event"
3
+ description = "Namespace package for ezmsg to work with signal events like neural spikes and heartbeats"
4
+ authors = [
5
+ { name = "Chadwick Boulay", email = "chadwick.boulay@gmail.com" },
6
+ ]
7
+ readme = "README.md"
8
+ requires-python = ">=3.9"
9
+ dynamic = ["version"]
10
+ dependencies = [
11
+ "ezmsg-sigproc>=1.3.3",
12
+ "ezmsg>=3.5.0",
13
+ "numpy>=2.0.2",
14
+ "sparse>=0.15.4",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ test = [
19
+ "pytest>=8.3.3",
20
+ ]
21
+
22
+ [build-system]
23
+ requires = ["hatchling", "hatch-vcs"]
24
+ build-backend = "hatchling.build"
25
+
26
+ [tool.hatch.version]
27
+ source = "vcs"
28
+
29
+ [tool.hatch.build.hooks.vcs]
30
+ version-file = "src/ezmsg/event/__version__.py"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/ezmsg"]
34
+
35
+ [tool.uv]
36
+ dev-dependencies = [
37
+ "ruff>=0.6.8",
38
+ "typer>=0.12.5",
39
+ ]
@@ -0,0 +1 @@
1
+ from .__version__ import __version__ as __version__
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '0.1.1'
16
+ __version_tuple__ = version_tuple = (0, 1, 1)
@@ -0,0 +1,17 @@
1
+ from dataclasses import dataclass
2
+ from numbers import Number
3
+
4
+
5
+ @dataclass
6
+ class EventMessage:
7
+ offset: float
8
+ """The temporal offset at which the event occurred. This is a float in seconds. The reference point is
9
+ unspecified and depends on the clock the application uses. Most applications will use time.time."""
10
+
11
+ ch_idx: int
12
+
13
+ sub_idx: int = 0
14
+ """The sub-index of the channel. For Blackrock multi-unit data: 0=unsorted, 1-5 sorted unit, >5=noise"""
15
+
16
+ value: Number = 1
17
+ """The value of the event. This can be any number, but is usually an integer, and is often 1 for spikes."""