IO

Read/write Vallen Systeme database and setup files.

Database classes

Classes to read/write pridb, tradb and trfdb database files.

Warning

Writing is still experimental

PriDatabase(filename[, mode])

IO Wrapper for pridb database file.

TraDatabase(filename[, mode, compression])

IO Wrapper for tradb database file.

TrfDatabase(filename[, mode])

IO Wrapper for trfdb (transient feature) database file.

All database classes implement two different interfaces to access data:

Standard read_*

Read data to pandas.DataFrame, e.g. with PriDatabase.read_hits

>>> pridb = vae.io.PriDatabase("./examples/steel_plate/sample.pridb")
>>> df = pridb.read_hits()  # save all hits to pandas dataframe
>>> df[["time", "channel"]]  # output columns hit and channel
            time  channel
set_id
10      3.992771        3
11      3.992775        2
12      3.992813        4
13      3.992814        1

Streaming iread_*

Iterate through the data row by row. This is a memory-efficient solution ideal for batch processing. The return types are specific typing.NamedTuple, see Data types.

Example with PriDatabase.iread_hits:

>>> pridb = vae.io.PriDatabase("./examples/steel_plate/sample.pridb")
>>> for hit in pridb.iread_hits():
...     print(f"time: {hit.time:0.4f}, channel: {hit.channel}")
...
time: 3.9928,   channel: 3
time: 3.9928,   channel: 2
time: 3.9928,   channel: 4
time: 3.9928,   channel: 1
>>> type(hit)
<class 'vallenae.io.datatypes.HitRecord'>

Data types

Records of the database are represented as typing.NamedTuple. Each record implements a class method from_sql to init from a SQLite row dictionary (column name: value).

HitRecord(time, channel, param_id, ...[, ...])

Hit record in pridb (SetType = 2).

MarkerRecord(time, set_type, data[, number, ...])

Marker record in pridb (SetType = 4, 5, 6).

StatusRecord(time, channel, param_id, ...[, ...])

Status data record in pridb (SetType = 3).

ParametricRecord(time, param_id[, set_id, ...])

Parametric data record in pridb (SetType = 1).

TraRecord(time, channel, param_id, ...[, ...])

Transient data record in tradb.

FeatureRecord(trai, features)

Transient feature record in trfdb.

Compression

Transient signals in the tradb are stored as BLOBs of 16-bit ADC values – either uncompressed or compressed (FLAC). Following functions convert between BLOBs and arrays of voltage values.

decode_data_blob(data_blob, data_format, ...)

Decodes (compressed) 16-bit ADC values from BLOB to array of voltage values.

encode_data_blob(data, data_format, ...[, raw])

Encodes array of voltage values to BLOB of 16-bit ADC values for memory-efficient storage.