Classes to hold sweep results

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

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

Bases: object

Class to hold a column title.

Parameters
  • name – Column name.

  • unit – Column unit.

  • unit_fmt – Formatting directive for units when generating string representations. By default, units are enclosed in square brackets (e.g., “Gate voltage [V]”).

class result_table.FETResultTable(column_titles: Optional[List[str]] = None, units: Optional[List[str]] = None, data: Optional[Sequence[float]] = None, params: Optional[Dict[str, Any]] = None)

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) → result_table.ResultTablePlot

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.

Raises

ImportError – If import of matplotlib fails.

class result_table.ResultTable(column_titles: Optional[List[str]] = None, units: Optional[List[str]] = None, data: Optional[Sequence[float]] = None, params: Optional[Dict[str, Any]] = None)

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 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 – 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'], params=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.apply_voltage(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')
append_column(data: Sequence[float], name: str, unit: Optional[str] = None) → None

Appends a single column to the data array.

Parameters
  • data – Sequence with the same number of elements as rows in the data array.

  • name – Name of new column.

  • unit – Unit of values in new column.

append_columns(data: Sequence[float], column_titles: List[str], units: Optional[List[str]] = None) → None

Appends multiple columns to data array.

Parameters
  • data – List of columns to append.

  • column_titles – List of column titles (strings).

  • units – List of units for new columns (strings).

append_row(data: Sequence[float]) → None

Appends a single row to the data array.

Parameters

data – Sequence with the same number of elements as columns in the data array.

append_rows(data: Sequence[float]) → None

Appends multiple rows to the data array.

Parameters

data – List of lists or numpy array with dimensions matching the data array.

clear_data() → None

Clears all data.

property column_names

List of strings with column names.

property column_units

List of strings with column units.

get_column(i: int) → numpy.ndarray
Parameters

i – Index of column.

Returns

Numpy array with data from column i.

get_row(i: int) → numpy.ndarray
Parameters

i – Index of row.

Returns

Numpy array with data from row i.

get_unit(col: Union[int, str]) → str

Get unit of column col.

Parameters

col – Column index or name.

Returns

Unit of column.

has_unit(col: Union[int, str]) → bool

Returns True column units have been set and False otherwise.

Parameters

col – Column index or name.

Returns

True if column_units have been set, False otherwise.

load(filename: str) → None

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

Parameters

filename – Absolute or relative path of file to load.

property ncols

Number of columns of the ResultTable.

property nrows

Number of rows of the ResultTable.

plot(x_clmn: int = 0, y_clmns: Optional[List[str]] = None, func: Callable = <function ResultTable.<lambda>>, live: bool = False, **kwargs) → result_table.ResultTablePlot

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 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 to apply to y-data before plotting.

  • live – If True, update the plot when new data is added. Plotting will be carried out in the main (GUI) thread, therefore take care not to block the thread. This can be achieved for instance by adding data in a background thread which carries out the measurement, or by calling matplotlib.pyplot.pause after adding data to give the GUI time to update.

Returns

ResultTablePlot instance with Matplotlib figure.

Raises

ImportError – If import of matplotlib fails.

save(filename: str, ext: str = '.txt') → None

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 – Path of file to save. Relative paths are interpreted with respect to the current working directory.

  • ext – File extension. Defaults to ‘.txt’.

save_csv(filename: str) → None

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 – Path of file to save. Relative paths are interpreted with respect to the current working directory.

set_unit(col: Union[int, str], unit: str) → None

Set unit of column col.

Parameters
  • col – Column index or name.

  • unit – Unit string.

property shape

A tuple representing the dimensionality of the ResultTable.

class result_table.ResultTablePlot(result_table: result_table.ResultTable, x_clmn: int = 0, y_clmns: List[Union[str, int]] = None, func: Callable = <function ResultTablePlot.<lambda>>, live: bool = False, **kwargs)

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 to apply to y-data before plotting.

  • live – If True, update the plot when new data is added (default: False). Plotting will be carried out in the main (GUI) thread, therefore take care not to block the thread. This can be achieved for instance by adding data in a background thread which carries out the measurement, or by calling matplotlib.pyplot.pause after adding data to give the GUI time to update.

show() → None

Shows the plot.

update() → None

Updates the plot with the data of the corresponding ResultTable. This will be called periodically when :param:live is True.