TraDatabase¶
- class vallenae.io.TraDatabase(filename, mode='ro', *, compression=False)[source]¶
IO wrapper for tradb database file.
Methods
__init__(filename[, mode, compression])Open tradb database file.
channel()Get list of channels.
close()Close database connection.
columns()Columns of data table.
Get SQLite connection object.
create(filename)Create empty tradb.
Read fieldinfo table.
Read globalinfo table.
iread(*[, channel, time_start, time_stop, ...])Stream transient data with returned Iterable.
listen([existing, wait, query_filter, raw])Listen to database changes and return new records.
read(**kwargs)Read transient data to Pandas DataFrame.
read_continuous_wave(channel[, time_start, ...])Read transient signal of specified channel to a single, continuous array.
read_wave(trai[, time_axis, raw])Read transient signal for a given TRAI (transient recorder index).
rows()Number of rows in data table.
tables()Get table names.
write(tra)Write transient data to pridb.
write_fieldinfo(field, info)Write to fieldinfo table.
Attributes
- static create(filename)[source]¶
Create empty tradb.
- Parameters:
filename (
str) – Path to new tradb database file
- iread(*, channel=None, time_start=None, time_stop=None, trai=None, query_filter=None, raw=False)[source]¶
Stream transient data with returned Iterable.
- Parameters:
channel (
Union[int,Sequence[int],None]) – None if all channels should be read. Otherwise specify the channel number or a list of channel numberstime_start (
float|None) – Start reading at relative time (in seconds). Start at beginning if Nonetime_stop (
float|None) – Stop reading at relative time (in seconds). Read until end if Nonetrai (
Union[int,Sequence[int],None]) – Read data by TRAI (transient recorder index)query_filter (
str|None) – Optional query filter provided as SQL clause, e.g. “Pretrigger == 500 AND Samples >= 1024”raw (
bool) – Return data as ADC values (int16). Default: False
- Return type:
SizedIterable[TraRecord]- Returns:
Sized iterable to sequential read transient data
- read_wave(trai, time_axis=True, *, raw=False)[source]¶
Read transient signal for a given TRAI (transient recorder index).
This method is useful in combination with
PriDatabase.read_hits, that will store the TRAI in a DataFrame.- Parameters:
- Return type:
- Returns:
If
time_axisis TrueArray with transient signal
Time axis
If
time_axisis FalseArray with transient signal
Samplerate
- read_continuous_wave(channel, time_start=None, time_stop=None, *, time_axis=True, show_progress=True, raw=False)[source]¶
Read transient signal of specified channel to a single, continuous array.
The signal is exactly cropped to the given time range. Time gaps are filled with 0’s.
- Parameters:
channel (
int) – Channel number to readtime_start (
float|None) – Start reading at relative time (in seconds). Start at beginning if Nonetime_stop (
float|None) – Stop reading at relative time (in seconds). Read until end if Nonetime_axis (
bool) – Create the correspondig time axis. Default: Trueshow_progress (
bool) – Show progress bar. Default: Trueraw (
bool) – Return data as ADC values (int16). Default: False
- Return type:
- Returns:
If time_axis is True
Array with transient signal
Time axis
If time_axis is False
Array with transient signal
Samplerate
- listen(existing=False, wait=False, query_filter=None, raw=False)[source]¶
Listen to database changes and return new records.
- Parameters:
existing (
bool) – Return already existing recordswait (
bool) – Wait for new records even if no acquisition (writer) is active. Otherwise the function returns after all records are read.query_filter (
str|None) – Optional query filter provided as SQL clause, e.g. “TRAI >= 100 AND Samples >= 1024”raw (
bool) – Return data as ADC values (int16). Default: False
- Yields:
New transient data records
- Return type:
- close()¶
Close database connection.
- connection()¶
Get SQLite connection object.
- Raises:
RuntimeError – If connection is closed
- Return type:
- fieldinfo()¶
Read fieldinfo table.
The fieldinfo table stores informations about columns of the data table (like units).