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_format for the data obtained from Oscilloscope.capture_and_read()

Parameters
  • raw (ndarray or str) – From capture_and_read(): Raw data, type depending on wav_format

  • metadata (list or tuple) – From capture_and_read(): List of preambles or tuple of preamble and model series depending on wav_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

  • time (ndarray) – Time axis for the measurement

  • y (ndarray) – Voltage values, each row represents one channel

Raises

ValueError – If wav_format is not {‘BYTE’, ‘WORD’, ‘ASCii’}

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

  • time (ndarray) – Time axis for the measurement

  • y (ndarray) – Voltage values, each row represents one channel

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 values

  • metadata (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

  • time (ndarray) – Time axis for the measurement

  • y (ndarray) – Voltage values, each row represents one channel

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, use generate_file_header()

  • ext (str, default _filetype) – Choose the filetype of the saved trace

  • print_filename (bool, default True) – True prints 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.

Parameters
  • fname (str) – Filename to save to

  • time (ndarray) – Time axis for the measurement

  • y (ndarray) – Voltage values, same sequence as channel_nums

  • print_filename (bool, default True) – True prints the filename it is saved to

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 png

  • show (bool, default _show_plot) – True shows the plot (must be closed before the programme proceeds)

  • savepng (bool, default _export_png) – True exports the plot to fname.png

keyoscacquire.oscacq.check_file(fname, ext='.csv', num='')[source]

Checking if file fname+num+ext exists. If it does, the user is prompted for a string to append to fname until a unique fname is found.

Parameters
  • fname (str) – Base filename to test

  • ext (str, default _filetype) – File extension

  • num (str, default "") – Filename suffix that is tested for, but the appended part to the fname will be placed before it, and the suffix will not be part of the returned fname

Returns

fname – New fname base

Return type

str