Stream Buffer API

class joulescope.v1.stream_buffer.StreamBuffer(duration, frequency, device, output_frequency=None)[source]

Efficient real-time Joulescope data buffering.

Parameters:

duration – The total length of the buffering in seconds.

data_get(start, stop, increment=None, out=None)[source]

Get the samples with statistics.

Parameters:
  • start – The starting sample id (inclusive).

  • stop – The ending sample id (exclusive).

  • increment – The number of raw samples.

  • out – The optional output np.ndarray((N, STATS_FIELD_COUNT), dtype=DTYPE) to populate with the result. None (default) will construct and return a new array.

Returns:

The np.ndarray((N, STATS_FIELD_COUNT), dtype=DTYPE) data.

This method provides fast access to statistics data, primarily for graphical display. Applications should prefer using samples_get() which provides metadata along with the samples.

property sample_id_range

Get the range of sample ids currently available in the buffer.

Returns:

Tuple of sample_id start, sample_id end. Start and stop follow normal python indexing: start is inclusive, end is exclusive

samples_get(start, stop, fields=None)[source]

Get exact sample data without any skips or reductions.

Parameters:
  • start – The starting sample id (inclusive).

  • stop – The ending sample id (exclusive).

  • fields

    The single field or list of field names to return. None (default) is equivalent to [‘current’, ‘voltage’, ‘power’, ‘current_range’, ‘current_lsb’, ‘voltage_lsb’]. The available fields are:

    • raw: The raw u16 data from Joulescope. Equivalent to self.raw_get(start, stop)

    • raw_current: The raw 14-bit current data in LSBs.

    • raw_voltage: The raw 14-bit voltage data in LSBs.

    • current: The calibrated float32 current data array in amperes.

    • voltage: The calibrated float32 voltage data array in volts.

    • current_voltage: The calibrated float32 Nx2 array of current, voltage.

    • power: The calibrated float32 power data array in watts.

    • bits: The (voltage_lsb << 5) | (current_lsb << 4) | current_range

    • current_range: The current range. 0 = 10A, 6 = 18 uA, 7=off.

    • current_lsb: The current LSB, which can be assign to a general purpose input.

    • voltage_lsb: The voltage LSB, which can be assign to a general purpose input.

Returns:

The dict containing top-level ‘time’ and ‘signals’ keys. The ‘time’ value is a dict contain the timing metadata for these samples. The ‘signals’ value is a dict with one key for each field in fields. Each field value is also a dict with entries ‘value’ and ‘units’. However, if single field string is provided to fields, then just return that field’s value.

statistics_get(start, stop, out=None)[source]

Get exact statistics over the specified range.

Parameters:
  • start – The starting sample_id (inclusive).

  • stop – The ending sample_id (exclusive).

  • out – The optional output np.ndarray(STATS_FIELD_COUNT, dtype=DTYPE). None (default) creates and outputs a new record.

Returns:

The tuple of (np.ndarray(STATS_FIELD_COUNT, dtype=DTYPE), [start, stop]). The values of start and stop will be constrained to the available range.