Data processing and file saving¶
The keyoscacquire.oscacq module contains function for processing the raw data captured with Oscilloscope, and for saving the processed data to files and plots.
Data processing¶
The output from the Oscilloscope.capture_and_read() function is processed by process_data(), a wrapper function that sends the data to the respective binary or ascii processing function.
-
keyoscacquire.oscacq.process_data(raw, metadata, wav_format, acquire_print=True)[source]¶ Wrapper function for choosing the correct process_data function according to
wav_formatfor the data obtained fromOscilloscope.capture_and_read()- Parameters
raw (ndarray or str) – From
capture_and_read(): Raw data, type depending onwav_formatmetadata (list or tuple) – From
capture_and_read(): List of preambles or tuple of preamble and model series depending onwav_format. See The preamble.wav_format ({
'WORD','BYTE','ASCii'}) – Specify what waveform type was used for acquiring to choose the correct processing function.acquire_print (bool) – True prints the number of points captured per channel
- Returns
- Raises
ValueError – If
wav_formatis not {‘BYTE’, ‘WORD’, ‘ASCii’}
See also
-
keyoscacquire.oscacq.process_data_binary(raw, preambles, acquire_print=True)[source]¶ Process raw 8/16-bit data to time values and y voltage values as received from
Oscilloscope.capture_and_read_binary().- Parameters
raw (ndarray) – From
capture_and_read_binary(): An ndarray of ints that is converted to voltage values using the preamble.preambles (list of str) – From
capture_and_read_binary(): List of preamble metadata for each channel (list of comma separated ascii values, see The preamble)acquire_print (bool) – True prints the number of points captured per channel
- Returns
-
keyoscacquire.oscacq.process_data_ascii(raw, metadata, acquire_print=True)[source]¶ Process raw comma separated ascii data to time values and y voltage values as received from
Oscilloscope.capture_and_read_ascii()- Parameters
raw (str) – From
capture_and_read_ascii(): A string containing a block header and comma separated ascii valuesmetadata (tuple) – From
capture_and_read_ascii(): Tuple of the preamble for one of the channels to calculate time axis (same for all channels) and the model series. See The preamble.acquire_print (bool) – True prints the number of points captured per channel
- Returns
File saving¶
The package has built-in functions for saving traces to numpy.lib.format files or ascii values (the latter is slower but will give a header that can be customised, for instance Oscilloscope.generate_file_header() can be used).
-
keyoscacquire.oscacq.save_trace(fname, time, y, fileheader='', ext='.csv', print_filename=True)[source]¶ Saves the trace with time values and y values to file.
Current date and time is automatically added to the header. Saving to numpy format with
save_trace_npy()is faster, but does not include metadata and header.- Parameters
fname (str) – Filename of trace
time (ndarray) – Time axis for the measurement
y (ndarray) – Voltage values, same sequence as channel_nums
fileheader (str, default
"") – Header of file, usegenerate_file_header()ext (str, default
_filetype) – Choose the filetype of the saved traceprint_filename (bool, default
True) –Trueprints the filename it is saved to
-
keyoscacquire.oscacq.save_trace_npy(fname, time, y, print_filename=True)[source]¶ Saves the trace with time values and y values to npy file.
Note
Saving to numpy files is faster than to ascii format files (
save_trace()), but no file header is added.
-
keyoscacquire.oscacq.plot_trace(time, y, channel_nums, fname='', show=False, savepng=True)[source]¶ Plots the trace with oscilloscope channel screen colours according to the Keysight colourmap and saves as a png.
Caution
No filename check for the saved plot, can overwrite existing png files.
- Parameters
time (ndarray) – Time axis for the measurement
y (ndarray) – Voltage values, same sequence as channel_nums
channel_nums (list of chars) – list of the channels obtained, example [‘1’, ‘3’]
fname (str, default
"") – Filename of possible exported pngshow (bool, default
_show_plot) – True shows the plot (must be closed before the programme proceeds)savepng (bool, default
_export_png) –Trueexports the plot tofname.png