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
Built Distribution
File details
Details for the file channelpack-0.7.0.tar.gz
.
File metadata
- Download URL: channelpack-0.7.0.tar.gz
- Upload date:
- Size: 123.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b77934063688f0039208937f2a2d3a1e5363767c8848c5d89d446ce3424d1faa |
|
MD5 | 58f8408cc0f6fc3a0fa60b7f20163d7e |
|
BLAKE2b-256 | a235c9759a79be63c977fab22665d2e6c0b0e5a623399b89cde70c4e1af0cb64 |
File details
Details for the file channelpack-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: channelpack-0.7.0-py3-none-any.whl
- Upload date:
- Size: 129.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2205b420acc6a56a5d27bfa52e3a622881133f7d5bc15a93d66bb8224795ad4b |
|
MD5 | 0a06a3a6126c740fc08b0938320f6c6d |
|
BLAKE2b-256 | 3057c7aa12c3e4eccc41f89319b3b992e3897e4dfd5c18cb1fa5d83afc1114fd |