daq
Protocol and threaded interface for data acquisition.
- class axopy.daq.DaqStream(device)[source]
Asynchronous interface to an input device.
Runs a persistent while loop wherein the device is repeatedly polled for data. When the data becomes available, it is emitted and the loop continues.
There are effectively two methods of this class: start and stop. These methods do as their names suggest – they start and stop the underlying device from sampling new data.
The device used to create the DaqStream is also accessible via the
device
attribute so you can change settings on the underlying device any time (e.g. sampling rate, number of samples per update, etc.).- Parameters:
device (daq) – Any object implementing the AxoPy data acquisition interface. See
NoiseGenerator
for an example.
- updated
Transmitted when the latest chunk of data is available. The data type depends on the underlying input device, but it is often a numpy ndarray.
- Type:
Transmitter
- disconnected
Transmitted if the device cannot be read from (it has disconnected somehow).
- Type:
Transmitter
- finished
Transmitted when the device has stopped and samping is finished.
- Type:
Transmitter
- run()[source]
Implementation for the underlying QThread.
Don’t call this method directly – use
start()
instead.
- property running
Boolean value indicating whether or not the stream is running.
- class axopy.daq.Keyboard(rate=10, keys=None)[source]
Keyboard input device.
The keyboard device works by periodically sampling (with the rate specified) whether or not the watched keys have been pressed since the last sampling event. The output is a numpy array of shape
(n_keys, 1)
, where the numerical values are booleans indicating whether or not the corresponding keys have been pressed.- Parameters:
Notes
There are a couple reasonable alternatives to the way the keyboard device is currently implemented. One way to do it might be sampling the key states at a given rate and producing segments of sampled key state data, much like a regular data acquisition device. One issue is that actual key state (whether the key is being physically pressed or not) doesn’t seem to be feasible to find out with Qt. You can hook into key press and key release events, but these are subject to repeat delay and repeat rate.
Another possible keyboard device would be responsive to key press events themselves rather than an input sampling event. While Qt enables event-based keyboard handling, the method used here fits the input device model, making it easily swappable with other input devices.
- class axopy.daq.Mouse(rate=10, position=False)[source]
Mouse input device.
The mouse device works by periodically sampling (with the rate specified) the mouse position within the AxoPy experiment window. The output is in the form of a numpy array of shape
(2, 1)
, representing either the change in position (default) or the absolute position in the window.- Parameters:
Notes
In Qt’s coordinate system, the positive y direction is downward. Here, this is inverted as a convenience (upward movement of the mouse produces a positive “velocity”).
Mouse events are intercepted here but they are not consumed, meaning you can still use the mouse to manipulate widgets in the experiment window.
- class axopy.daq.NoiseGenerator(rate=1000, num_channels=1, amplitude=1.0, read_size=100)[source]
An emulated data acquisition device which generates random data.
Each sample of the generated data is sampled from a zero-mean Gaussian distribution with variance determined by the amplitude specified, which corresponds to three standard deviations. That is, approximately 99.7% of the samples should be within the desired peak amplitude.
NoiseGenerator
is meant to emulate data acquisition devices that block on each request for data until the data is available. Seeread()
for details.- Parameters:
rate (int, optional) – Sample rate in Hz. Default is 1000.
num_channels (int, optional) – Number of “channels” to generate. Default is 1.
amplitude (float, optional) – Approximate peak amplitude of the signal to generate. Specifically, the amplitude represents three standard deviations for generating the Gaussian distributed data. Default is 1.
read_size (int, optional) – Number of samples to generate per
read()
call. Default is 100.
- read()[source]
Generates zero-mean Gaussian data.
This method blocks (calls
time.sleep()
) to emulate other data acquisition units which wait for the requested number of samples to be read. The amount of time to block is calculated such that consecutive calls will always return with constant frequency, assuming the calls occur faster than required (i.e. processing doesn’t fall behind).- Returns:
data – The generated data.
- Return type:
ndarray, shape (num_channels, read_size)