Skip to main content

A domain specific language for modeling and manipulating discrete time signals.

Project description

py-aiger logo
A domain specific language for modeling and manipulating discrete time signals.

Build Status codecov Updates

PyPI version License: MIT

About

This library aims to provide a domain specific language for modeling and manipulating discrete time signals. Intuitively, most of the time, the discrete time signal's value is undefined.

If discrete-signals isn't for you, I recommend checking out traces (which this library took design inspiration from). Both libraries offer a convenient way to model unevenly-spaced discrete time signals.

Installation

$ pip install discrete-signals

Usage

from discrete_signals import signal

x = signal([(0, 1), (1, 2), (2, 3)], start=0, end=10, tag='x')
y = signal([(0.5, 'a'), (1, 'b'), (2, 'c')], start=0, end=3, tag='y')

x
# start, end: [0, 10)
# data: [(0, {'x': 1}), (1, {'x': 2}), (2, {'x': 3})]

y
# start, end: [0, 3)
# data: [(0.5, {'y': 'a'}), (1, {'y': 'b'}), (2, {'y': 'c'})]

Parallel Composition

x | y
# start, end: [0, 10)
# data: [(0, {'x': 1}), (0.5, {'y': 'a'}), (1, {'x': 2, 'y': 'b'}), (2, {'x': 3, 'y': 'c'})]

Concatenation

x @ y
# start, end: [0, 13)
# data: [(0, {'x': 1}), (1, {'x': 2}), (2, {'x': 3}), (10.5, {'y': 'a'}), (11, {'y': 'b'}), (12, {'y': 'c'})]

Retagging/Relabeling

x.retag({'x': 'z'})
# start, end: [0, 10)
# data: [(0, {'z': 1}), (1, {'z': 2}), (2, {'z': 3})]

Time shifting

x >> 1.1
# start, end: [1.1, 11.1)
# data: [(1.1, {'x': 1}), (2.1, {'x': 2}), (3.1, {'x': 3})]

x << 1
# start, end: [-1, 9)
# data: [(-1, {'x': 1}), (0, {'x': 2}), (1, {'x': 3})]

Slicing

x[1:]
# start, end: [1, 10)
# data: [(1, {'x': 2}), (2, {'x': 3})]

x[:1]
# start, end: [0, 1)
# data: [(0, {'x': 1})]

Rolling Window

x.rolling(1, 3)
# start, end: [-1, 7)
# data: [(-1, {'x': (1, 2)}), (0, {'x': (2, 3)}), (1, {'x': (3,)})]

Mapping a Function

One perform a point wise transform of the signal. For example, the following is equivalent to retagging the signal and adding 1.

x.transform(lambda val: {'y': val['x'] + 1})
# start, end: [0, 10)
# data: [(0, {'y': 2}), (1, {'y': 3}), (2, {'y': 4})]

Alternatively, DiscreteSignals support mapping the dictionary of values to a single value (and optionally tag it):

x.map(lambda val: str(val['x']), tag='z')
# start, end: [0, 10)
# data: [(0, {'z': '1'}), (1, {'z': '2'}), (2, {'z': '3'})]

Filter a signal

x.filter(lambda val: val['x'] > 2)
# start, end: [0, 10)
# data: [(2, {'x': 3})]

Projecting onto a subset of the tags.

(x | y).project({'x'})
# start, end: [0, 10)
# data: [(0, {'x': 1}), (1, {'x': 2}), (2, {'x': 3})]

Attributes

(x | y).tags
# {'x', 'y'}

x.values()
# SortedDict_values([defaultdict(None, {'x': 1}), defaultdict(None, {'x': 2}), defaultdict(None, {'x': 3})])

list(x.times())
# [0, 1, 2]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discrete-signals-0.8.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

discrete_signals-0.8.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file discrete-signals-0.8.2.tar.gz.

File metadata

  • Download URL: discrete-signals-0.8.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.0-1-MANJARO

File hashes

Hashes for discrete-signals-0.8.2.tar.gz
Algorithm Hash digest
SHA256 de4a2eea6b02e07959e2f793d1bcff93afc56af8c9e4423669b74a097c3a3dba
MD5 80b7c1222ccc52762b476c83f93194db
BLAKE2b-256 21ace3eaa99ace8a8de5511cc5f53d7485d14d8f99630c6459a168e4994ba585

See more details on using hashes here.

File details

Details for the file discrete_signals-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: discrete_signals-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.0-1-MANJARO

File hashes

Hashes for discrete_signals-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3972bd51ec60325087423baffdfc57ace8bf500cff20bbccf2a959be1d66415
MD5 6b57e24d4449abda9bf7d7d451a39888
BLAKE2b-256 472017a552514057a318c530a87f0a9008c289104f8af070754bdd3fde305274

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page