Skip to main content

Callable container of Numpy arrays with support for masking and slicing

Project description

The ChannelPack class provides a callable container of data. The channelpack package also provides some factory functions to get such a pack from data files.

Channelpack is a Python project (a small library) assuming Numpy being available and that numpy arrays are the preferred data sequences.

Example

Produce some data and make a pack:

>>> import channelpack as cp
>>> data = {0: range(5), 1: ('A', 'B', 'C', 'D', 'E')}
>>> names = {0: 'seq', 1: 'abc'}
>>> pack = cp.ChannelPack(data=data, names=names)
>>> pack
ChannelPack(
data={0: array([0, 1, 2, 3, 4]),
      1: array(['A', 'B', 'C', 'D', 'E'], dtype='<U1')},
names={0: 'seq',
       1: 'abc'})
>>> pack(0)
array([0, 1, 2, 3, 4])
>>> pack(0) is pack('seq')
True

Set the pack mask and use it to slice or filter out parts:

>>> pack.mask = (pack('seq') < 2) | (pack('abc') == 'D')
>>> pack('seq', part=0)
array([0, 1])
>>> pack('seq', part=1)
array([3])
>>> pack('abc', nof='filter')
array(['A', 'B', 'D'], dtype='<U1')
>>> pack('abc', nof='nan')
array(['A', 'B', None, 'D', None], dtype=object)
>>> pack('seq', nof='nan')
array([ 0.,  1., nan,  3., nan])

Read data from file:

>>> import io
>>> datstring = \
... u"""date: 20-05-01 17:39
... room: east lab hall, floor 2, room 8
... operator: Goran Operatorsson
...
... time, speed, onoff, distance
... 0, 23, on, 0.3
... 1, 21, off, 0.28
... """
>>> sio = io.StringIO(datstring)
>>> pack = cp.textpack(sio, delimiter=',', skiprows=5, hasnames=True)
>>> pack
ChannelPack(
data={0: array([0., 1.]),
      1: array([23., 21.]),
      2: array([' on', ' off'], dtype='<U4'),
      3: array([0.3 , 0.28])},
names={0: 'time',
       1: 'speed',
       2: 'onoff',
       3: 'distance'})

Lazy read numeric data:

>>> datstring = \
... u"""date: 20-05-01 17:39
... room: east lab hall, floor 2, room 8
... operator: Goran Operatorsson
...
... time, speed, distance
... 0, 23, 0.3
... 1, 21, 0.28
... """
>>> sio = io.StringIO(datstring)
>>> pack = cp.lazy_textpack(sio)
>>> pack
ChannelPack(
data={0: array([0., 1.]),
      1: array([23., 21.]),
      2: array([0.3 , 0.28])},
names={0: 'time',
       1: 'speed',
       2: 'distance'})

Channel?

The naming (channelpack) sort of origins from work with measurements and data acquisition. Using tools for that, the recorded arrays of data are often called “channels”, because it was acquired through some IO channel.

Install

$ pip install channelpack

Documentation and repository

There is some documentation at Read the Docs and the code repository is on GitHub.

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

channelpack-0.6.2.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

channelpack-0.6.2-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file channelpack-0.6.2.tar.gz.

File metadata

  • Download URL: channelpack-0.6.2.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for channelpack-0.6.2.tar.gz
Algorithm Hash digest
SHA256 1b4224ade008636ea052dee70a2adcc58b52921af7710bfb23cabc427f2284ce
MD5 0c70cfbd41ecfd1d69e30c6cac0c84c9
BLAKE2b-256 de588440cd5c4721b9d7b9281789f4568e3094b7ee5b4eaa0e3c0c459004b7e3

See more details on using hashes here.

File details

Details for the file channelpack-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: channelpack-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

File hashes

Hashes for channelpack-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ec652a2946784d24e81aec387ffb28a04a12e4f32615c44301a4ec3e5967be1
MD5 9e5b4ad818d06248ba3f5e5411563c6a
BLAKE2b-256 82f166d77f39a24e466e87ad95e82ab205e3fefb85ea8d6ee5cb046c7a053a3a

See more details on using hashes here.

Supported by

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