|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import csv |
| 4 | + |
| 5 | +# Load data from breakout board tutorial workflow |
| 6 | +suffix = '0'; # Change to match file names' suffix |
| 7 | +plt.close('all') |
| 8 | + |
| 9 | +#%% Metadata |
| 10 | +dt = {'names': ('time', 'acq_clk_hz', 'block_read_sz', 'block_write_sz'), |
| 11 | + 'formats': ('datetime64[us]', 'u4', 'u4', 'u4')} |
| 12 | +meta = np.genfromtxt('start-time_' + suffix + '.csv', delimiter=',', dtype=dt) |
| 13 | +print(f"Recording was started at {meta['time']} GMT") |
| 14 | + |
| 15 | +#%% Analog Inputs |
| 16 | +analog_input = {} |
| 17 | +analog_input['time'] = np.fromfile('analog-clock_' + suffix + '.raw', dtype=np.uint64) / meta['acq_clk_hz'] |
| 18 | +analog_input['data'] = np.reshape(np.fromfile('analog-data_' + suffix + '.raw', dtype=np.float32), (-1, 12)) |
| 19 | + |
| 20 | +plt.figure() |
| 21 | +plt.plot(analog_input['time'], analog_input['data']) |
| 22 | +plt.xlabel("time (sec)") |
| 23 | +plt.ylabel("volts") |
| 24 | +plt.legend(['Ch. 0', 'Ch. 1', 'Ch. 2', 'Ch. 3', 'Ch. 4', 'Ch. 5', |
| 25 | + 'Ch. 6', 'Ch. 7', 'Ch. 8', 'Ch. 9', 'Ch. 10', 'Ch. 11']) |
| 26 | + |
| 27 | +#%% Digital Inputs |
| 28 | +digital_input_flags = ['Pin0', 'Pin1', 'Pin2', 'Pin3', 'Pin4', 'Pin5', 'Pin6', 'Pin7', |
| 29 | + 'Moon', 'Triangle', 'X', 'Check', 'Circle', 'Square', |
| 30 | + 'Reserved0', 'Reserved1', 'PortDOn', 'PortCOn', 'PortBOn', 'PortAOn'] |
| 31 | +digital_input_data = [] |
| 32 | +with open("digital-data_" + suffix + '.csv', 'r') as digital_input_file: |
| 33 | + digital_input_reader = csv.reader(digital_input_file) |
| 34 | + row = [entry.strip() for entry in next(digital_input_reader)] |
| 35 | + time = int(row[0]) / meta['acq_clk_hz'] |
| 36 | + for digital_input_flag in digital_input_flags: |
| 37 | + if digital_input_flag in [entry.strip() for entry in row[1:]]: |
| 38 | + digital_input_data.append((time, digital_input_flag, True)) |
| 39 | + else: |
| 40 | + digital_input_data.append((time, digital_input_flag, False)) |
| 41 | + row_previous = row |
| 42 | + for row in digital_input_reader: |
| 43 | + time = int(row[0]) / meta['acq_clk_hz'] |
| 44 | + row = [entry.strip() for entry in row] |
| 45 | + for entry in (set(row) | set(row_previous)): |
| 46 | + if (entry in row_previous[1:]) and (not entry in row[1:]): |
| 47 | + digital_input_data.append((time, entry, False)) |
| 48 | + elif (not entry in row_previous[1:]) and (entry in row[1:]): |
| 49 | + digital_input_data.append((time, entry, True)) |
| 50 | + row_previous = row |
| 51 | + |
| 52 | +dt = np.dtype([('Clock', np.float64), ('Digital Input', '<U10'), ('State', np.bool_)]) |
| 53 | +digital_input_data = np.array(digital_input_data, dtype=dt) |
| 54 | + |
| 55 | +plt.figure() |
| 56 | +line_spacing = 1.25 |
| 57 | +for i, digital_input_flag in enumerate(digital_input_flags): |
| 58 | + index_mask = digital_input_data['Digital Input'] == digital_input_flag |
| 59 | + line = plt.step(digital_input_data['Clock'][index_mask], digital_input_data['State'][index_mask] + line_spacing * i, color="black") |
| 60 | +plt.ylim(-0.5, len(digital_input_flags) * line_spacing + 0.5) |
| 61 | +plt.yticks(np.arange(0.5, len(digital_input_flags) * line_spacing, line_spacing), digital_input_flags) |
| 62 | +plt.tight_layout() |
| 63 | + |
| 64 | +plt.show() |
| 65 | + |
| 66 | +#%% Hardware FIFO buffer use |
| 67 | +dt = {'names': ('clock', 'bytes', 'percent'), |
| 68 | + 'formats': ('u8', 'u4', 'f8')} |
| 69 | +memory_use = np.genfromtxt('memory-use_' + suffix + '.csv', delimiter=',', dtype=dt) |
| 70 | + |
| 71 | +plt.figure() |
| 72 | +plt.plot(memory_use['clock'] / meta['acq_clk_hz'], memory_use['percent']) |
| 73 | +plt.xlabel("time (sec)") |
| 74 | +plt.ylabel("FIFO used (%)") |
0 commit comments