Classes to hold sweep results

Submodule defining classes to store, plot, and save measurement results.

class result_table.ColumnTitle(name, unit=None, unit_fmt='[{}]')[source]

Bases: object

Class to hold a column title.

Parameters:
  • name (str) – Column name.
  • unit (str) – Column unit.
  • unit_fmt (str) – Formatting directive for units when generating string representations. By default, units are enclosed in square brackets (e.g., “Gate voltage [V]”).
class result_table.ResultTable(column_titles=None, units=None, data=None, params=None)[source]

Bases: object

Class that holds measurement data. All data is stored internally as a numpy array with the first index designating rows and the second index designating columns.

Columns must have titles and can have units. It is possible to access the data in a column by its title in a dictionary type notation.

Parameters:
  • column_titles (list) – List of column titles.
  • units (list) – List of column units.
  • data (numpy.ndarray or NoneType) – Numpy array holding the data with the first index designating rows and the second index designating columns. If data is None, an empty array with the required number of columns is created.
  • params (dict) – Dictionary of measurement parameters.
Examples:

Create a ResultTable to hold current-vs-time data:

>>> import time
>>> import numpy as np
>>> from  keithley2600 import ResultTable
>>> # create dictionary of relevant measurement parameters
>>> pars = {'recorded': time.asctime(), 'sweep_type': 'iv'}
>>> # create ResultTable with two columns
>>> rt = ResultTable(['Voltage', 'Current'], ['V', 'A'], pars)
>>> # create a live plot of the data
>>> fig = rt.plot(live=True)

Create a Keithley2600 instance and record some data:

>>> from  keithley2600 import Keithley2600
>>> k = Keithley2600('TCPIP0::192.168.2.121::INSTR')
>>> for v in range(11):  # measure IV characteristics from 0 to 10 V
...     k.applyVoltage(k.smua, 10)
...     i = k.smua.measure.i()
...     rt.append_row([v, i])
...     time.sleep(1)

Print a preview of data to the console:

>>> print(rt)
Voltage [V]   Current [A]
0.0000e+00   1.0232e-04
1.0000e+00   2.2147e-04
2.0000e+00   3.6077e-04
3.0000e+00   5.2074e-04
4.0000e+00   6.9927e-04

Save the recorded data to a tab-delimited text file:

>>> rt.save('~/Desktop/stress_test.txt')
nrows

Number of rows of the ResultTable.

ncols

Number of columns of the ResultTable.

shape

A tuple representing the dimensionality of the ResultTable.

column_names

List of strings with column names.

column_units

List of strings with column units.

has_unit(col)[source]

Returns True column units have been set and False otherwise.

Parameters:col (int or str) – Column index or name.
Returns:True if column_units have been set, False otherwise.
Return type:bool
get_unit(col)[source]

Get unit of column col.

Parameters:col (int or str) – Column index or name.
Returns:Unit string.
Return type:str
set_unit(col, unit)[source]

Set unit of column col.

Parameters:
  • col (int or str) – Column index or name.
  • unit (str) – Unit string.
clear_data()[source]

Clears all data.

append_row(data)[source]

Appends a single row to the data array.

Parameters:data – Iterable with the same number of elements as columns in the data array.
append_rows(data)[source]

Appends multiple rows to the data array.

Parameters:data – List of lists or numpy array with dimensions matching the data array.
append_column(data, name, unit=None)[source]

Appends a single column to the data array.

Parameters:
  • data – Iterable with the same number of elements as rows in the data array.
  • name (str) – Name of new column.
  • unit (str) – Unit of values in new column.
append_columns(data, column_titles, units=None)[source]

Appends multiple columns to data array.

Parameters:
  • data (list) – List of columns to append.
  • column_titles (list) – List of column titles (strings).
  • units (list) – List of units for new columns (strings).
get_row(i)[source]
Returns:Numpy array with data from row i.
Return type:numpy.ndarray
get_column(i)[source]
Returns:Numpy array with data from column i.
Return type:numpy.ndarray
save(filename, ext='.txt')[source]

Saves the result table to a text file. The file format is:

  • The _header contains all measurement parameters as comments.
  • Column titles contain column_names and column_units of measured quantity.
  • Delimited columns contain the data.

Files are saved with the specified extension (default: ‘.txt’). The classes default delimiters are used to separate columns and rows.

Parameters:
  • filename (str) – Path of file to save. Relative paths are interpreted with respect to the current working directory.
  • ext (str) – File extension. Defaults to ‘.txt’.
save_csv(filename)[source]

Saves the result table to a csv file. The file format is:

  • The _header contains all measurement parameters as comments.
  • Column titles contain column_names and column_units of measured quantity.
  • Comma delimited columns contain the data.

Files are saved with the extension ‘.csv’ and other extensions are overwritten.

Parameters:filename (str) – Path of file to save. Relative paths are interpreted with respect to the current working directory.
load(filename)[source]

Loads data from csv or tab delimited tex file. The _header is searched for measurement parameters.

Parameters:filename (str) – Absolute or relative path of file to load.
plot(x_clmn=0, y_clmns=None, func=<function ResultTable.<lambda>>, live=False, **kwargs)[source]

Plots the data. This method should not be called from a thread. The column containing the x-axis data is specified (defaults to first column), all other data is plotted on the y-axis. This method requires Matplotlib to be installed and accepts, in addition to the arguments documented here, the same keyword arguments as matplotlib.pyplot.plot().

Column titles are taken as legend labels. plot() tries to determine a common y-axis unit and name from all given labels.

Parameters:
  • x_clmn (int or str) – Integer or name of column containing the x-axis data.
  • y_clmns (list) – List of column numbers or column names for y-axis data. If not given, all columns will be plotted against the x-axis column.
  • func (function) – Function to apply to y-data before plotting.
  • live (bool) – If True, update plot when new rows are added (default: False).
Returns:

ResultTablePlot instance with Matplotlib figure.

Return type:

ResultTablePlot

Raises:

ImportError – If import of matplotlib fails.

class result_table.FETResultTable(column_titles=None, units=None, data=None, params=None)[source]

Bases: result_table.ResultTable

Class to handle, store and load transfer and output characteristic data of FETs. TransistorSweepData inherits from ResultTable and overrides the plot method.

plot(*args, **kwargs)[source]

Plots the transfer or output curves. Overrides ResultTable.plot(). Absolute values are plotted, on a linear scale for output characteristics and a logarithmic scale for transfer characteristics. Takes the same arguments as ResultTable.plot().

Returns:ResultTablePlot instance with Matplotlib figure.
Return type:ResultTablePlot
Raises:ImportError – If import of matplotlib fails.
class result_table.ResultTablePlot(result_table, x_clmn=0, y_clmns=None, func=<function ResultTablePlot.<lambda>>, live=False, **kwargs)[source]

Bases: object

Plots the data from a given ResultTable instance. Axes labels are automatically generated from column titles and units. This class requires Matplotlib to be installed. In addition to the arguments documented here, class:ResultTable accepts the same keyword arguments as matplotlib.pyplot.plot().

Parameters:
  • result_table (ResultTable) – ResultTable instance with data to plot.
  • x_clmn (int or str) – Integer or name of column containing the x-axis data.
  • y_clmns (list(int or str)) – List of column numbers or column names for y-axis data. If not given, all columns will be plotted against the x-axis column.
  • func (function) – Function to apply to y-data before plotting.
  • live (bool) – If True, update plot when new rows are added. Default to False`.