SLiCAPplots.py

SLiCAP module with plot functions.

Cadence2traces(csvFile, absx=False, logx=False, absy=False, logy=False, selection=['all'], assignID=True)

Generates a dictionary with traces (key = label, value = trace object) from data from a csv file generated in Cadence. :param csvFile: name of the csv file (in the ini.csv_path directory) :type csvFile: str :param absx: if ‘True’, it applies the absolute (abs) function to the indpendent variable data (xData) :type absx: bool :param logx: if ‘True’, it applies the logarithm in base 10 (log10) function to the independent variable data (xData) :type logx: bool :param absy: if ‘True’, it applies the absolute (abs) function to the dependent variable data (yData) :type absy: bool :param logy: if ‘True’, it applies the logarithm in base 10 (log10) function to the dependent variable data (yData) :type logy: bool :param selection: if:

  • selection=[‘all’]: Selects all traces in the dictionary and does not replace any label

  • selection=[‘all’,(“Var1”,”Variable”),(“Var2”,”Variable2”)]: selects all traces and replaces all character strings mentioned in the first element of the tuples (e.g. “Var1” and “Var2”) with the strings in the second element of the tuples (“Variable” and “Variable2”).

  • selection=[(‘Var1 (SweepVar=1e-06) Y’,”New Label”),(‘Var2 (SweepVar=1e-06) Y’,””)]: selects only the traces that are explicitly mentioned in the first element of the tuple (e.g. ‘Var1 (SweepVar=1e-06) Y’ and ‘Var2 (SweepVar=1e-06) Y’) and replaces its label with the second element of the tuple unless it is “”.

Parameters:

assignID (bool) – if ‘True’, it generates an ID for each processed trace to avoid overwriting when merging dictionaries.

Returns:

dictionary with key-value pairs: - key: str: label of the trace - value: SLiCAPplots.trace trace object

Return type:

dict

LTspiceAC2SLiCAPtraces(fileName, dB=False, color='c')

This function converts the results of a single-run LTspice AC analysis into two traces (mag, phase) that can be added to SLiCAP plots. Stepping is not (yet) supported.

Parameters:
  • fileName (str) – Name of the file. The file should be located in the ditectory given in ini.txt_path.

  • dB (bool) – True if the trace magnitude should be in dB, else False. Default value = False

  • color (str) – Matplotlib color name. Valid names can be found at: https://matplotlib.org/stable/gallery/color/named_colors.html Default value is cyan (c); this does not correspond with one of the standard gain colors of the asymptotic-gain model.

Returns:

a list with two trace dicts, magnitude and phase, respectively.

Return type:

list

Example:

>>> LTmag, LTphase = LTspiceAC2SLiCAPtraces('LTspiceACdata.txt')
LTspiceData2Traces(txtFile)

Generates a dictionary with traces (key = label, value = trace object) from LTspice plot data (saved as .txt file).

Parameters:

txtFile (str) – Name of the text file stored in the ini.txt_path directory

Returns:

Dictionary with key-value pairs:

  • key: str: label of the trace

  • value: SLiCAPplots.trace trace object

Return type:

dict

addTraces(figObj, traceDict)

Adds the traces in the dictionary ‘traceDict’ to the figure object ‘figObj’.

Parameters:
  • figObj – SLiCAP figure object to which the traces will be added.

  • traceDict (dict) – dictionary with traces (result from csv2traces)

Returns:

updated figure object (traces addad)

Return type:

SLiCAP figure object

class axis(title)

Axis prototype.

Parameters:

title (str) – Title of the axis. The title will be placed on top of the axis.

makeTraceDict()

Returns a dict with data of all the traces on the axis.

Returns:

dictionary with key-value pairs:

  • key: str label of the trace

  • value: SLiCAPplots.trace trace object

Return type:

dict

point_snap

(bool) True replaces the A/B cursors with a point-snap cursor: a click snaps to the nearest data point and shows its x-y value - vertical A/B lines mean nothing on a scatter plot. Set by pzAxis(). Defaults to False.

polar

(bool) True if a polar axis is required. Defaults to False.

square

(bool) True keeps the axis BOX square in a multi-axis figure - SLiCAP’s pole-zero convention (axis width = axis height), which is what makes a root locus readable. Set by pzAxis(). Defaults to False.

text

Text ([int, int, str]) with relative plot position: [<xPos>, <yPos>, <text>]. Defaults to [0, 0, ‘’].

title

Title (str) of the axis, will be placed on top of the axis

traces

List with SLiCAPplots.trace objects to be plotted on this axis: [<trace1>(,<trace2>,…,<traceN>)]. Defaults to [].

xLabel

Label (str) for the x-axis, e.g. ‘frequency [Hz]’. Defaults to False.

xLim

Limits (list) for the x-scale: [<xMin>, <xMax>]. Defaults to [].

xScale

Scale (str) for the x-axis can be ‘lin’ or ‘log’. Defaults to ‘lin’.

xScaleFactor

Scale factor (str) for the x-scale; e.g. M for 1E6. Defaults to ‘’.

yLabel

Label (str) for the x-axis, e.g. ‘voltage [V]’. Defaults to False.

yLim

Limits (list) for the y-scale: [<yMin>, <yMax>]. Defaults to [].

yScale

Scale (str) for the y-axis can be ‘lin’ or ‘log’. Defaults to ‘lin’.

yScaleFactor

Scale factor (str) for the y-scale; e.g. M for 1E6. Defaults to ‘’.

csv2traces(csvFile)

Generates a dictionary with traces (key = label, value = trace object) from data from a csv file. The CSV file should have the following structure:

x0_label, y0_label, x1_label, y1_label, … x0_0 , y0_0 , x1_0 , y1_0 , … x0_1 , y0_1 , x1_1 , y1_1 , … … , … , … , … , …

The traces will be named with their y label.

Parameters:

csvFile (str) – name of the csv file (in the ini.csv_path directory)

Returns:

dictionary with key-value pairs:

  • key: str: label of the trace

  • value: SLiCAPplots.trace trace object

Return type:

dict

defaultsPlot()

Applies default settings for plots.

enable_ab_cursors(ax, readout_fn=None)

Attach A/B dual vertical cursors to ax.

Left-click sets cursor A (blue dashed), right-click sets cursor B (red dashed). When both cursors are placed:

  • A text annotation box appears in the upper-left corner of the plot showing x_A, x_B, ΔX and, for every data trace, y_A, y_B, ΔY.

  • The same text is printed to stdout immediately (flushed), so it appears in the log panel without waiting for the plot window to close.

Pass a custom readout_fn(x_a, x_b) to add extra processing on top.

Silent no-op when the active backend is non-interactive (Agg, PDF, SVG, …).

Parameters:
  • ax (matplotlib.axes.Axes) – Matplotlib Axes to attach cursors to.

  • readout_fn (callable or None) – Optional extra callback f(x_a, x_b) called after the built-in annotation update.

enable_polar_cursor(ax)

Attach a nearest-point cursor to a polar ax.

A mouse click snaps to the closest data point on any trace and shows a read-out ON THE FIGURE - the sweep value (frequency) of the point, the radius in the axis’ units, and the angle in degrees. Clicking empty space hides it.

Silent no-op when the active backend is non-interactive.

Parameters:

ax (matplotlib.axes.Axes) – Polar matplotlib Axes to attach the cursor to.

enable_pz_cursor(ax)

Attach a point-snap cursor to a scatter ax (pole-zero plot).

A click snaps to the nearest data point of any trace and shows its coordinates on the figure. Distances are measured in AXIS fractions, so a root locus with |Re| >> |Im| still snaps to what the eye is near.

Silent no-op when the active backend is non-interactive.

Parameters:

ax (matplotlib.axes.Axes) – matplotlib Axes to attach the cursor to.

fig2traces(figObject, names=None)

Returns the traces of an existing figure, for reuse in another plot.

Every figure carries a trace dictionary that is updated when the figure is plotted (plotSweep(), plot() and plotPZ() all do this, also with show=False and save=False). This function makes those traces available as input for plot(), so traces from any figure — including traces that were generated inside plotSweep() — can be combined in a new figure.

Parameters:
  • figObject (SLiCAPplots.figure) – Figure of which the traces must be returned.

  • names (str, list, NoneType) – Label, or list of labels, of the traces to be returned. If None (default), all traces of the figure are returned.

Returns:

Dictionary with key-value pairs:

  • key: str: label of the trace

  • value: SLiCAPplots.trace trace object

Return type:

dict

class figure(fileName)

Prototype SLiCAP figure object.

Parameters:

fileName (str) – Name of the file for saving the figure.

axes

List with SLiCAPplots.axis objects to be plotted on this figure. Defaults to [].

axisHeight

Relative height (int, float) of a single axis. Defaults to ini.axis_height.

To do: absolute measures in inch or cm.

axisWidth

Relative width (int, float) of a single axis. Defaults to ini.axis_width.

To do: absolute measures in inch or cm.

cursors

(bool) If True and show=True, attach interactive A/B cursors to each non-polar axis and a nearest-point cursor to each polar axis. The cursors stay inactive until enabled from the figure toolbar. Silently ignored when the active backend is non-interactive. Defaults to True.

fileName

File name of the figure.

fileType

Graphic file type (str) for saving the figure. Defaults to fileName

make_mpl_figure()

Build and return the matplotlib Figure without saving or closing it.

Called by plot() internally; also called by the GUI waveform dock to embed the figure in a FigureCanvasQTAgg widget.

Returns:

live matplotlib Figure, or False on error.

Return type:

matplotlib.figure.Figure or bool

plot()

Creates the figure, and saves it to disk. It displays the figure if SLiCAPplots.figure.show == True.

Showing does NOT block: the script continues (so all instructions of a run execute) and the process waits once, at exit, until every open figure has been closed.

save

(bool) if ‘True’ the figure will be saved to the img folder in pdf and in svg format Defaults to True.

shareX

(str) Axes sharing ONE x axis: ‘none’ (default), ‘col’ (down each column), ‘row’ (across each row) or ‘all’. Sharing axes keep the same range and zoom together, the tick labels and the x label are drawn on the outer axis only, and the gap between them is closed, so a magnitude-over-phase pair reads as one plot with a single frequency axis. Only the FIRST axis of such a stack shows its title: with the gap closed there is no room for the others.

shareY

(str) Axes sharing ONE y axis: ‘none’ (default), ‘row’ (across each row), ‘col’ (down each column) or ‘all’. See shareX; here the y tick labels and y label are drawn on the outer axis only.

show

(bool) if ‘True’ the figure will be displayed with the method SLiCAPplots.figure.plot(). Defaults to [].

traceDict

Dictionary with key-value pairs:

  • key: label of the trace

  • value: trace object

updateTracedict()

Updates the trace dictionary of the figure.

fit_text_to_axis(text_artist, ax, base_fontsize, floor=5.5)

Shrink text_artist until it fits inside ax; return the size used.

The A/B read-out lists a block per axis of a shared stack, so a Bode pair with five transfers is fifteen lines: at the configured font size the box grew past the bottom of the plot and the last entries were unreadable The font is reduced only as far as needed and never below floor - past that the box is simply large, which is better than silently cut off.

Parameters:
  • text_artist (matplotlib.text.Text) – the annotation to fit.

  • ax (matplotlib.axes.Axes) – the axis it must stay inside.

  • base_fontsize (float) – the size to use when it fits (ini.cursor_fontsize).

Returns:

the font size that was set.

Return type:

float

makeFigure(axes, fileName, show=False, save=True, cursors=True, axisWidth=None, axisHeight=None, shareX='none', shareY='none')

Creates a figure from a grid of axis objects and plots it.

axes is a list of lists: one list per row, one entry per column. An entry is an axis object, or the empty string for an empty cell. An axis object placed in several ADJACENT cells spans them; the occupied cells must form a solid rectangle. A single axis may also be passed.

Example:

>>> D       = sl.sweepData(LAPLACE1, 1, "1M", 500)
>>> axMag   = sl.traceAxis("Magnitude", "semilogx",
...                        sl.make_traces(D, [{"y": "dB(laplace)"}]),
...                        xName="frequency", xUnits="Hz",
...                        yName="magnitude", yUnits="dB")
>>> axPhase = sl.traceAxis("Phase", "semilogx",
...                        sl.make_traces(D, [{"y": "phase(laplace)"}]),
...                        xName="frequency", xUnits="Hz",
...                        yName="phase", yUnits="deg")
>>> fig     = sl.makeFigure([[axMag], [axPhase]], "bode", show=True)
>>> # axMag spans both columns of the top row:
>>> fig = sl.makeFigure([[axMag, axMag], [axPhase, axPZ]], "views")
Parameters:
  • axes (list, SLiCAPplots.axis) – grid of axis objects (list of lists), or a single axis.

  • fileName (str) – Name of the file for saving it to disk.

  • show (bool) – If True the figure will be shown in the workspace. Defaults to False.

  • save (bool) – If True the figure is saved in the img folder. Defaults to True.

  • cursors (bool) – If True, the shown figure offers A/B cursors. Defaults to True.

  • axisWidth (float, int, NoneType) – Width of ONE grid cell in inches; the figure is axisWidth*columns wide. Defaults to None: ini.axis_width.

  • axisHeight (float, int, NoneType) – Height of ONE grid cell in inches; the figure is axisHeight*rows high. Defaults to None: ini.axis_height.

  • shareX (str, list) – Axes that share ONE x axis: ‘none’ (default), ‘col’ (down each column), ‘row’ (across each row), ‘all’, or a LIST of axis-object groups - shareX=[[axMag, axPhase]] - sharing exactly those axes wherever they sit. A positional mode shares only axes plotting the SAME quantity (judged by the axis label), so a column may hold a Bode stack above a pole-zero plot and only the stack shares (‘col’ once welded a unit-step response to the Re axis below it). Shared axes keep the same range and zoom together. Where a whole column (row) is one share group its gap is closed: tick labels and the x label on the outer axis only, no space in between, only the first title shown - the closed Bode look. Elsewhere the scales are shared but every axis keeps its gap, ticks and title. Polar axes never share.

  • shareY (str, list) – Axes that share ONE y axis: ‘none’ (default), ‘row’, ‘col’, ‘all’ or a list of groups. As shareX, for the y axis.

Example:

>>> BODE = sl.makeFigure([[axMag], [axPhase]], "bode", shareX="col")
Returns:

fig

Return type:

SLiCAPplots.figure

plot(fileName, title, axisType, plotData, xName='', xScale='', xUnits='', yName='', yScale='', yUnits='', xLim=[], yLim=[], show=False, save=True, cursors=True)

Plots x-y data, or multiple pairs of x-y data.

Parameters:
  • fileName (str) – Name of the file for saving it to disk.

  • title (str) – Title of the figure.

  • axisType (str) – Type of axis: ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.

  • plotData (dict, SLiCAPplots.trace) –

    dictionary with key-value pairs or dictionary with traces

    • key: str label for the trace

    • value:

      1. list [<xData>, <yData>]

        • xData: list: x values

        • yData: list: y values

      2. SLiCAPplots.trace object

  • xName (str) – Name of the variable to be plotted along the x axis. Defaults to ‘’.

  • xScale (str) – Scale factor of the x axis variable. Defaults to ‘’.

  • xUnits (str) – Units of the x axis variable. Defaults to ‘’.

  • xLim (list) – Limits for the x-axis scale: [<xmin>, <xmax>]

  • yName – Name of the variable to be plotted along the y axis. Defaults to ‘’.

  • yScale (str) – Scale factor of the y axis variable. Defaults to ‘’.

  • yUnits (str) – Units of the y axis variable. Defaults to ‘’.

  • yLim (list) – Limits for the y-axis scale: [<ymin>, <ymax>]

  • show (bool) – If ‘True’ the plot will be shown in the workspace.

  • save (bool) – If ‘True’ the plot will be saved to the img folder in both pdf and svg format. Defaults to True.

  • cursors (bool) – If ‘True’, the shown figure’s toolbar offers A/B cursors and a crosshair (inactive until enabled there). Defaults to True.

Returns:

fig

Return type:

SLiCAPplots.figure

plotPZ(fileName, title, results, xmin=None, xmax=None, ymin=None, ymax=None, xscale='', yscale='', show=False, save=True)

Creates a pole-zero scatter plot.

If parameter stepping of the instruction is enabled, a root locus is drawn with the parameter as root locus variable.

In such cases special begin end endpoint markers are used:

  • poles begin of root locus: ‘x’

  • poles end of root locus: ‘+’

  • zeros begin of root locus: ‘o’

  • zeros end of root locus: ‘square’

The root locus itself is drawn with dots for each position of a pole or zero.

Results of multiple analysis can be combined in one plot by putting them in a list.

The type of the axis is ‘lin’.

Parameters:
  • fileName (str) – Name of the file for saving it to disk.

  • title (str) – Title of the figure.

  • results (list, SLiCAPinstruction.instruction) – Results of the execution of an instruction, or a list with SLiCAPinstruction.instruction objects. The data type of these instructions should be ‘poles’, ‘zeros’ or ‘pz’.

  • xmin (int, float, str) – Minimum value of the x axis; defaults to None.

  • xmax (int, float, str) – Maximum value of the x axis; defaults to None.

  • ymin (int, float, str) – Minimum value of the y axis; defaults to None.

  • ymax (int, float, str) – Maximum value of the y axis; defaults to None.

  • xscale (str) – x axis scale factor; defaults to ‘’.

  • yscale (str) – y axis scale factor; defaults to ‘’.

  • show (bool) – If ‘True’ the plot will be shown in the workspace. Defaults to False.

  • save – If ‘True’ the plot will be saved to the img folder in both pdf and svg format. Defaults to True.

Returns:

fig

Return type:

SLiCAPplots.figure

plotSweep(fileName, title, results, sweepStart, sweepStop, sweepNum, sweepVar='auto', sweepScale='', xVar='auto', xScale='', xUnits='', xLim=[], yLim=[], axisType='auto', funcType='auto', yVar='auto', yScale='', yUnits='', noiseSources=None, show=False, save=True, cursors=True)

Plots a function by sweeping one variable and optionally stepping another.

The function to be plotted depends on the arguments ‘yVar’ and ‘funcType’:

  • If funcType == ‘params’, the variable ‘yVar’ must be the name of a circuit parameter, or a list with circuit parameters.

  • If funcType == ‘auto’, the default function that will be plotted depends on the data type of the instruction:

    • data type == ‘noise’: funcType = ‘onoise’

    • data type == ‘laplace’, ‘numer’ or ‘denom’: funcType = ‘mag’

    • data type == ‘time’, ‘impulse’ or ‘step’: funcType = ‘time’

The variable plotted along the x-axis defaults to the sweep variable. However, for multivariate functions obtained with data type ‘params’, the x variable can be choosen from all circuit parameters.

  • If sweepVar == ‘auto’, the sweep variable will be determined from the data type:

    • data type == ‘noise’, ‘laplace’, ‘numer’ or ‘denom’: sweepVar = ini.frequency for data types ‘laplace’, ‘numer’ or ‘denom’ the laplace variable will be replaced with sympy.i*ini.frequency or with 2*sympy.pi*sympy.i*ini.frequency before sweeping, when ini.hz == False, or ini.hz== True, respectively.

    • dataType == ‘time’, ‘impulse’ or ‘step’: sweepVar = sympy.Symbol(‘t’)

The type of axis can be ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.

Parameters:
  • fileName (str) – Name of the file for saving it to disk.

  • title (str) – Title of the figure.

  • results (list, SLiCAPinstruction.instruction) – Results of the execution of an instruction, or a list with SLiCAPinstruction.instruction objects.

  • sweepStart (float, int, str) – Start value of the sweep parameter

  • sweepStop (float, int, str) – Stop value of the sweep parameter

  • sweepNum (int) – Number of points of the sweep parameter

  • sweepVar (sympy.Symbol, str) – Name of the sweep variable

  • sweepScale (str) – Scale factor of the sweep variable. Both the start and the stop value will be multiplied with a factor that corresponds with this scale factor.

  • xVar – Name of the variable to be plotted along the x axis

  • xScale (str) – Scale factor of the x axis variable.

  • xUnits (str) – Units of the x axis variable.

  • xLim (list) – Limits for the x-axis scale: [<xmin>, <xmax>]

  • axisType (str) – Type of axis: ‘lin’, ‘log’, ‘semilogx’, ‘semilogy’ or ‘polar’.

  • funcType (str) – Type of function can be: ‘mag’, ‘dBmag’, ‘phase’, ‘delay’, ‘time’, ‘onoise’, ‘inoise’ or ‘param’.

  • yVar (str, list) – if funcType = param, yVar should be the name of a circuit parameter or list with names of circuit parameters. In other cases yVar should be ‘auto’.

  • yScale (str) – Scale factor of the y axis variable.

  • yUnits (str) – Units of the y axis variable.

  • yLim (list) – Limits for the y-axis scale: [<ymin>, <ymax>]

  • noiseSources (list, str) – Noise sources of which the contribution to the detector- referred noise (funcType = ‘onoise’) or the source- referred noise (funcType = ‘inoise’) should be plotted. Can be ‘all’, a list with names of noise sources or an ID of a noise source.

  • show (bool) – If ‘True’ the plot will be shown in the workspace.

  • save (bool) – If ‘True’ the plot will be saved to the img folder in both pdf and svg format. Defaults to True.

  • cursors (bool) – If ‘True’, the shown figure’s toolbar offers A/B cursors and a crosshair (inactive until enabled there). Defaults to True.

Returns:

fig

Return type:

SLiCAPplots.figure

plot_defaults(result, funcType='auto', axisType='auto', sweepVar='auto', yVar='auto')

Resolves the presentation defaults that follow from a SLiCAP result.

This is the “no user programming required” behaviour of plotSweep() made queryable: which function is plotted, on which type of axis, with which axis scales. plotSweep() uses it, and a GUI can call it to PRE-FILL its fields from the selected result instead of presenting empty ones.

Error messages are printed here, exactly as plotSweep() printed them, and None is returned.

Parameters:
  • result (SLiCAPinstruction.instruction) – instruction result object.

  • funcType (str) – requested function type, or ‘auto’ to derive it from the result’s dataType. Defaults to ‘auto’.

  • axisType (str) – requested axis type, or ‘auto’ to derive it from the function type. Defaults to ‘auto’.

  • sweepVar (str) – name of the sweep variable; only checked for funcType=’param’. Defaults to ‘auto’.

  • yVar (str) – parameter plotted along the y axis; only checked for funcType=’param’. Defaults to ‘auto’.

Returns:

dictionary with the resolved settings, or None on error:

  • dataType: the result’s data type

  • funcType: resolved function type

  • axisType: resolved axis type

  • xAxisScale: ‘lin’ or ‘log’ for the x axis

  • yAxisScale: ‘lin’ or ‘log’ for the y axis

  • polar: True for a polar axis

  • funcTypes: the selectable function types

  • axisTypes: the selectable axis types

Return type:

dict, NoneType

polar_readout(line, idx, theta, r, radial_label='')

The text a polar-cursor click shows for point idx of line.

A designer reads a polar gain plot by asking WHERE on the contour a point sits, so the first line is the sweep value - the frequency the renderer stashed on the line (_slicap_param). What it used to print was idx=157, which says nothing, and it went to the console, flooding the log panel.

Parameters:
  • line – the matplotlib line that was hit.

  • idx – index of the snapped point.

  • theta – its angle in radians.

  • r – its radius.

  • radial_label – the axis’ radial label, e.g. ‘magnitude [dB]’; its bracket names the radius units.

Returns:

the read-out text.

Return type:

str

pzAxis(title, results, xmin=None, xmax=None, ymin=None, ymax=None, xscale='', yscale='')

Creates a pole-zero scatter axis, WITHOUT creating a figure.

This is plotPZ() without the figure: same arguments and the same automatic behaviour, returning the axis object so that it can be placed on a figure of any layout with makeFigure().

Note that plotPZ() also makes its figure square (axisWidth = axisHeight); that is a figure property, so a pole-zero axis placed on a shared figure keeps that figure’s aspect ratio.

For the arguments see plotPZ().

Returns:

axis object, or False when the result cannot be plotted.

Return type:

SLiCAPplots.axis, bool

pz_readout(line, x, y, xlabel='', ylabel='')

The text a point-snap click shows: the point’s x-y value.

Vertical A/B cursors mean nothing on a scatter plot; a pole or zero is a POINT, so the read-out names it and gives both coordinates in the axis units (the brackets of ‘Re [Hz]’ / ‘Im [Hz]’).

Parameters:
  • line – the matplotlib line that was hit.

  • x – the point’s x value (already in axis units).

  • y – the point’s y value.

  • xlabel – the axis x label, its bracket holding the units.

  • ylabel – the axis y label.

Returns:

the read-out text.

Return type:

str

stepParams(results, xVar, yVar, sVar, sweepList)

Returns parameter values as a result of sweeping and stepping parameters.

Called by SLiCAPplots.plotSweep() in cases in which funcType = ‘param’.

  • If parameter stepping is enabled it returns a tuple with two dictionaries:

    1. {stepVal[j]: [xVal[i] for i in range(len(sweepValues))], …}

    2. {stepVal[j]: [yVal[i] for i in range(len(sweepValues))], …}

  • If parameter stepping is disabled it returns a tuple with two lists:

    1. [xVal[i] for i in range(len(sweepValues))]

    2. [yVal[i] for i in range(len(sweepValues))]

Parameters:
  • results (SLiCAPinstruction.instruction) – Results of the execution of an instruction with data type ‘params’.

  • xVar – Name of the parameter to be plotted along the x axis

  • yVar – Name of the parameter to be plotted along the y axis

  • sVar – Name of the sweep parameter

  • sweepList (list, numpy.array) – Array-like sweep values.

Returns:

parameter values as a result of sweeping and stepping parameters.

Return type:

tuple

sweepAxis(title, results, sweepStart, sweepStop, sweepNum, sweepVar='auto', sweepScale='', xVar='auto', xScale='', xUnits='', xLim=[], yLim=[], axisType='auto', funcType='auto', yVar='auto', yScale='', yUnits='', noiseSources=None, name='', traces=None)

Creates an axis with traces of a swept (and optionally stepped) SLiCAP result, WITHOUT creating a figure - the fully AUTOMATIC route: funcType, axis scales, labels and gain colours all follow from the result, exactly as plotSweep() has always done (plotSweep is this function plus the figure).

traces adds ready trace objects to the same axis - a trace, a trace dictionary, or a list of either, as traceAxis() takes them - so a measured NGspice curve can sit beside the SLiCAP transfers. The axis scale factors apply to them identically: trace data is in base units on both routes.

This is plotSweep() without the figure: same arguments, same automatic behaviour - funcType, sweep variable, axis type, units, axis labels, trace labels and colours all follow from the result - but it returns the axis object, so it can be placed on a figure of any layout with makeFigure(); a magnitude and a phase axis on one figure, for instance.

Parameters:
  • title (str) – Title of the axis.

  • name (str) – Name used in warning messages only; plotSweep() passes the figure file name. Defaults to ‘’.

For all other arguments see plotSweep().

Returns:

axis object, or False when the result cannot be plotted.

Return type:

SLiCAPplots.axis, bool

sweepData(results, sweepStart, sweepStop, sweepNum, sweepMethod='auto', sweepVar='auto')

Evaluates a SLiCAP result over a sweep and returns the numbers as a SLiCAPtraces.dataset, ready for SLiCAPtraces.make_traces() and SLiCAPtraces.measure().

A SLiCAP result is SYMBOLIC - laplace is an expression in s - so it has no sweep of its own; NGspice hands over numbers, SLiCAP hands over a formula. This function supplies the missing sweep, which is why the traces dialog asks for start / stop / points

It lives here, with the rest of the plot machinery, and it DEPENDS on SLiCAPtraces rather than the other way round: producers -> traces -> plots.

The signals are the result’s own attributes, which are already Python identifiers, so no name mapping is needed:

  • laplace, numer, denom: COMPLEX arrays, s replaced by 2*pi*j*f (ini.hz) or j*omega, so dB(...), phase(...), delay(...) and magnitude-by-default all work on them;

  • noise: onoise and inoise (V^2/Hz), plus one signal per noise source from onoiseTerms / inoiseTerms, named onoise_<source> - the symbolic counterpart of NGspice’s onoise_r1;

  • time, impulse, step: real arrays over t.

A stepped result carries one expression per run, so its signals become 2-D (n_runs, n_sweep) and step_params holds the step values - exactly like a stepped NGspice sweep. The circuit’s numeric parameter definitions become dataset.params.

Trace data stays in BASE UNITS (Hz, s, V): scaling belongs to the axis, never to the trace, so this function has no counterpart of plotSweep’s sweepScale.

Parameters:
  • results (SLiCAPinstruction.instruction) – result of one SLiCAP instruction.

  • sweepStart (str, float, int) – start of the sweep; SLiCAP notation (‘10’, ‘1M’).

  • sweepStop (str, float, int) – end of the sweep.

  • sweepNum (str, int) – number of points.

  • sweepMethod (str) – ‘lin’ or ‘log’; ‘auto’ takes ‘log’ for a frequency sweep and ‘lin’ for a time sweep.

  • sweepVar (str) – name of the swept parameter for dataType='params'; ‘auto’ for the frequency or time sweep of the other data types.

Returns:

the evaluated data, or None when the result cannot be swept.

Return type:

SLiCAPtraces.dataset, NoneType

Example:

>>> D   = sl.sweepData(LAPLACE1, 10, "1M", 200)
>>> TR  = sl.make_traces(D, [{"y": "dB(laplace)"}])
>>> A_0 = sl.measure(D, "Y_AT_X(dB(laplace), 1e3)", units="dB")
traceAxis(title, axisType, plotData, xName='', xScale='', xUnits='', yName='', yScale='', yUnits='', xLim=[], yLim=[])

Creates an axis holding ready traces, WITHOUT creating a figure.

This is plot() without the figure: plotData is a dictionary with trace objects or [xData, yData] lists, exactly as for plot(), OR a LIST of such dictionaries - an axis combines trace sets, e.g. [TR1, TR2], in drawing order. It returns the axis object, so it can be placed on a figure of any layout with makeFigure().

For the arguments see plot().

Returns:

axis object, or False for an unknown axis type.

Return type:

SLiCAPplots.axis, bool

traces2fig(traceDict, figObject, axis=[0, 0])

Adds traces generated from another application to an existing figure.

Parameters:
  • traceDict (dict) –

    Dictionary with key-value pairs:

    • key: str: label of the trace

    • value: SLiCAPplots.trace trace object

  • figObject (SLiCAPplots.figure) – figure object to which the traces must be added

  • axis (list) – List with x position and y position of the axis to which the traces must be added. Defaults to [0, 0]

Returns:

Updated figure object

Return type:

SLiCAPplots.figure