Stream Buffer API¶
-
class
joulescope.stream_buffer.StreamBuffer¶ Efficient real-time Joulescope data buffering.
Parameters: - duration – The total length of the buffering in seconds.
- reductions – The list of reduction integers. Each integer represents the reduction amount for each resuting sample in units of samples of the previous reduction. Reduction 0 is in raw sample units.
-
data_buffer¶ Get the underlying data buffer.
WARNING: Don’t use this! It should only be used for unit testing.
-
data_get()¶ 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.
-
get_reduction()¶ Get reduction data directly (for testing only).
Parameters: - idx – The reduction index.
- start – The starting sample_id (inclusive).
- stop – The ending sample_id (exclusive).
Returns: The The np.ndarray((N, STATS_FIELD_COUNT), dtype=DTYPE) reduction data which normally is memory mapped to the underlying data, but will be copied on rollover.
This method should not be used by production code. Use
data_get()orsamples_get().
-
has_raw¶ Query if this instance provides raw sample data.
Returns: True if samples_get supports ‘raw’, False otherwise.
-
insert()¶ Insert new device USB data into the buffer.
Parameters: data – The new data to insert. Returns: False to continue streaming, True to end.
-
insert_raw()¶ Insert raw data into the buffer
Parameters: data – The np.array of np.uint16 data to insert. Returns: False to continue streaming, True to end.
-
limits_samples¶ Get the sample limits.
Returns: (start, stop) where start is inclusive and stop is exclusive. - In other words:
- self.limits_time == (b.sample_id_to_time(b.limits_samples[0]),
- b.sample_id_to_time(b.limits_samples[1]))
-
limits_time¶ Get the time limits.
Returns: (start, stop). Stop corresponds to the exclusive sample returned by b.limits_samples[1].
-
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()¶ 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’, ‘raw’]. 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()¶ 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.