AnalogIn

class picodaq.adc.AnalogIn(channel: int | None = None, channels: ArrayLike | None = None, rate: Frequency = None, port: str | None = None, serno: str | None = None)

Main interface for acquiring analog data

Parameters:
  • channel – A single channel to record from

  • channels – A list of channels to record from

  • rate – Sampling frequency for the recording

  • port – Device to connect to identified by COM port

  • serno – Device to connect to identified by serial number

You must specify either a single channel or a list of channels to record from, but not both. Any combination of analog inputs 0, 1, 2, and 3 may be used. The order in which you specify the channels in the constructor becomes the order in which they will appear in the output from read().

The rate may be specified in Hz or kHz. When using multiple streams, the rates must all be the same and only need to be specified on the first-opened stream.

The port specifies which serial port to open. Use picodaq.devices() to retrieve the list of available ports.

If you do not specify a port, the most recently opened device is used, or the first device on the system if none was opened before.

Example:

with AnalogIn(channel=2, rate=30*kHz) as ai:
    data = ai.read(10*s)

This reads 10 seconds worth of data from channel AI2 at 30 kS/s.

chunkscans() int

Quantum of data transfer

Returns:

The number of scans in a standard chunk

This is the number of scans that would be returned by the low-level readchunk() method. The high-level read() method is most efficient if requested quantities are an integer multiple of this number.

This number is only available when the stream is open.

close()

Close the stream

The underlying device is automatically closed once the last stream is closed.

continuous()

Select continuous recording mode

This cancels a previous episodic(...) call. You normally do not need to call this, as continuous recording is the default.

episodic(duration: Time | None = None, period: Time | None = None, count: int | None = None)

Select episodic recording mode

Parameters:
  • duration – Duration of each episode

  • period – start-to-start time between episodes

  • count – number of episodes before automatically stopping

The period is measured start-to-start and is optional if triggering is enabled, in which cases it specifies the minimum period.

The count parameter, if given, specifies that the recording will stop automatically after that number of episodes have been recorded. Otherwise, it continues until the user stops the recording.

The specified duration of each episode may be internally lengthened slightly so that it constitutes an even number of USB transfer chunks.

In episodic mode, the timing of any stimuli is modified such that there is one train per episode and the defined inter-train intervals are ignored. The timing between start of the episode and the first pulse of a stimulus is determined by the delay parameter on the stimulus.

See also continuous.

immediate()

Disable triggering

This cancels a preceding trigger(...) call, so recording commences immediately upon start(). You normally do not have to call this, as immediate start is the default operation.

open()

Open the stream

This automatically opens the underlying picoDAQ device. If more than one stream is associated with a single device, each stream must be individually opened and the device remains open as long as any streams are open.

Often, with ... as syntax is more convenient than calling open() yourself. If you do call open() yourself, you must match it with close().

read(amount: Time | int | None = None, raw: bool = False, times: bool = False) np.ndarray

High-level method for reading data

Parameters:
  • amount – Amount of data to be read, either in units of time, or as an integer number of samples.

  • raw – Whether to return raw data from the device or convert them to more convenient units.

  • times – Whether to return a vector of time stamps

Returns:

data — A numpy array containing the data, either a vector

or a T × C array.

times — A corresponding vector of time stamps, in seconds

since start of run; only if the times flag is set in the function call.

If no amount is specified at all, a single chunk is read in continuous mode, or a full episode in episodic mode.

The shape of the result depends on whether the channel or channels parameter was used at construction time. If channel was used, the result is a T-vector, where T is the number of samples read. Otherwise, the result is a T × C array, even if only one channel is in use.

If raw is true, signed 16-bit values from the DAC are returned. Otherwise, readings are converted to volts and returned as 32-bit floats.

readall(raw: bool = False, times: bool = False) ndarray

Read all data accumulated during run().

Parameters:
  • raw – Whether to return raw data from the device or convert them to more convenient units.

  • times – Whether to return a vector of time stamps.

Returns:

data — A numpy array containing the data.

times — A corresponding vector of time stamps, in seconds

since start of run; only if the times flag is set in the function call.

Used after calling run() on AnalogOut or DigitalOut to retrieve all the data recorded during the run. In continuous mode, returns a T-vector or T × C array. In episodic mode, returns an N × L or N × L × C array, where N is the number of episodes and L is the number of scans per episode.

Example of reading just the data:

data = ai.readall()

Example of reading timestamps along with the data:

data, times = ai.readall(times=True)

The returned times are always a simple vector which applies equally to all channels (and to all episodes).

readchunk(_maxn=None) ndarray

Read a single chunk

Parameters:

_maxn – Maximum number of scans to read. The use of this parameter is not recommended.

Returns:

A numpy array containing the data

The shape of the result depends on whether the channel or channels parameter was used at construction time. If channel was used, the result is a T-vector, where T is the number of samples read. Otherwise, the result is a T × C array, even if only one channel is in use.

Almost always, read() is more convenient in user code.

start()

Start data acquisition

You typically do not have to call this directly, as read() calls it for you. If more than one stream is associated with a single PicoDAQ device, calling start() on one stream suffices to start all of them.

The streams must be open before being started.

stop()

Stop data acquisition

You typically do not have to call this directly, as close() (or the end of a with ... as block) calls it for you.

If more than one stream is associated with a single PicoDAQ device, calling stop() on one stream suffices to stop all of them.

trigger(source: int, polarity: int)

Define triggering

Parameters:
  • source – the digital line to monitor

  • polarity – edge on which to trigger

The recording (whether continuous or episodic) is not actually started until the given trigger condition is met. The source parameter (0, 1, 2, or 3) specifies a digital channel. The polarity parameter specifies whether the system triggers on rising edge (polarity > 0) or on falling edge (polarity < 0).

See also immediate.

verify(force=False) bool

Confirm whether recording parameters are OK

Parameters:

force – Re-verify unconditionally

Returns:

True if OK, else false.

You typically don’t have to call this, as start() and read() call it for you if you don’t. To reduce the latency between when you first call read() and when the first sample is acquired, you can call this ahead of time, but the difference is unlikely to be more than a millisecond.

The device keeps track of parameter changes since last call to verify and returns without doing work if there have been none. The force parameter causes unconditional re-verification.