# 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

  polar

    (bool) True if a polar axis is required. 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.

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.

  fileName

    File name of the figure.

  fileType

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

  plot()

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

  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.

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

  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.

  Returns:

    fig

  Return type:

    SLiCAPplots.figure

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

  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.

  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)

  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.frequency == False, or ini.frequency== 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.

  Returns:

    fig

  Return type:

    SLiCAPplots.figure

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

class trace(traceData)

  Trace prototype.

  Traces are plotted on axes, which are part of a figure.

  Parameters:

    traceData (list) – list with list array-like X and Y data of the trace.

  Example:

      >>> x_data = np.linspace(0, 2*np.pi, 50)
      >>> y_data = np.sin(x_data)
      >>> sin_trace = trace([x_data, y_data])

  color

    Trace color (str) in matplotlib format. Defaults to False.

  label

    Trace label (str) that will be displayed in legend box. Defaults to ‘’.

  lineType

    Line type (str) in matplotlib format. Defaults to ‘-‘.

  lineWidth

    Line width (int) in pixels. Defaults to 2.

  makeTable()

    Returns a table with trace data in CSV format.

    Returns:

      table: CSV table with column headings and x-data and y-data in columns

    Return type:

      str

    Example:

        >>> x_data = np.linspace(0, 2*np.pi, 10)
        >>> y_data = np.sin(x_data)
        >>> sin_trace = trace([x_data, y_data])
        >>> sin_trace.yName = 'sin(x)'
        >>> print(sin_trace.makeTable())
        x,sin(x)
          0.000000000000e+00,   0.000000000000e+00
          6.981317007977e-01,   6.427876096865e-01
          1.396263401595e+00,   9.848077530122e-01
          2.094395102393e+00,   8.660254037844e-01
          2.792526803191e+00,   3.420201433257e-01
          3.490658503989e+00,  -3.420201433257e-01
          4.188790204786e+00,  -8.660254037844e-01
          4.886921905584e+00,  -9.848077530122e-01
          5.585053606382e+00,  -6.427876096865e-01
          6.283185307180e+00,  -2.449293598295e-16

  marker

    Marker type (str) in matplotlib format. Defaults to False.

  markerColor

    Marker color (str) in matplotlib format. Defaults to False.

  markerFaceColor

    Marker face color (str) in matplotlib format. Defaults to ‘none’.

  markerSize

    Marker size (int). Defaults to 7.

  xData

    Array-like data for the x-axis of the trace. On a polar axes this is the angle in radians.

  xName

    Heading (str) for the x column of a table. Defaults to ‘x’.

  yData

    Array-like data for the y-axis of the trace. On a polar axes this is the radius.

  yName

    Heading (str) for the y column of a table. Defaults to ‘y’.

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