RawRead

class PyLTSpice.raw.raw_read.RawRead(raw_filename: str, traces_to_read: Optional[Union[str, List[str], Tuple[str, ...]]] = '*', **kwargs)[source]

Bases: object

Class for reading LTSpice wave Files. It can read all types of Files. If stepped data is detected, it will also try to read the corresponding LOG file so to retrieve the stepped data.

Parameters:
  • raw_filename (str | pahtlib.Path) – The file containing the RAW data to be read

  • traces_to_read (str, list or tuple) – A string or a list containing the list of traces to be read. If None is provided, only the header is read and all trace data is discarded. If a ‘*’ wildcard is given or no parameter at all then all traces are read.

Key headeronly:

Used to only load the header information and skip the trace data entirely. Use headeronly=True.

ACCEPTED_PLOTNAMES = ('AC Analysis', 'DC transfer characteristic', 'Operating Point', 'Transient Analysis', 'Transfer Function', 'Noise Spectral Density', 'Frequency Response Analysis')
export(columns: Optional[list] = None, step: Union[int, List[int]] = -1, **kwargs) Dict[str, list][source]

Returns a native python class structure with the requested trace data and steps. It consists of an ordered dictionary where the columns are the keys and the values are lists with the data.

This function is used by the export functions.

Parameters:
  • step (int) – Step number to retrieve. If not given, it will return all steps

  • columns (list) – List of traces to use as columns. Default is all traces

  • kwargs (**dict) – Additional arguments to pass to the pandas.DataFrame constructor

Returns:

A pandas DataFrame

Return type:

pandas.DataFrame

get_axis(step: int = 0)[source]

This function is equivalent to get_trace(0).get_wave(step) instruction. It also implements a workaround on a LTSpice issue when using 2nd Order compression, where some values on the time trace have a negative value. :param step: Step number :type step: int :returns: Array with the X axis :rtype: list[float] or numpy.array

get_len(step: int = 0) int[source]

Returns the length of the data at the give step index. :param step: Optional parameter the step index. :type step: int :return: The number of data points :rtype: int

get_raw_property(property_name=None)[source]

Get a property. By default, it returns all properties defined in the RAW file.

Parameters:

property_name (str) – name of the property to retrieve.

Returns:

Property object

Return type:

str

Raises:

ValueError if the property doesn’t exist

get_steps(**kwargs)[source]

Returns the steps that correspond to the query set in the * * kwargs parameters. Example:

raw_read.get_steps(V5=1.2, TEMP=25)

This will return all steps in which the voltage source V5 was set to 1.2V and the TEMP parameter is 24 degrees. This feature is only possible if a .log file with the same name as the .raw file exists in the same directory. Note: the correspondence between step numbers and .STEP information is stored on the .log file.

Key kwargs:

key-value arguments in which the key correspond to a stepped parameter or source name, and the value is the stepped value.

Returns:

The steps that match the query

Return type:

list[int]

get_time_axis(step: int = 0)[source]

(Deprecated) Use get_axis method instead

This function is equivalent to get_trace(‘time’).get_time_axis(step) instruction. It’s workaround on a LTSpice issue when using 2nd Order compression, where some values on the time trace have a negative value.

get_trace(trace_ref: Union[str, int])[source]

Retrieves the trace with the requested name (trace_ref).

Parameters:

trace_ref (str or int) – Name of the trace or the index of the trace

Returns:

An object containing the requested trace

Return type:

DataSet subclass

Raises:

IndexError – When a trace is not found

get_trace_names()[source]

Returns a list of exiting trace names of the RAW file.

Returns:

trace names

Return type:

list[str]

get_wave(trace_ref: Union[str, int], step: int = 0)[source]

Retrieves the trace data with the requested name (trace_ref), optionally providing the step number.

Parameters:
  • trace_ref (str or int) – Name of the trace or the index of the trace

  • step (int) – Optional parameter specifying which step to retrieve.

Returns:

A numpy array containing the requested waveform.

Return type:

numpy.array

Raises:

IndexError – When a trace is not found

header_lines = ('Title', 'Date', 'Plotname', 'Output', 'Flags', 'No. Variables', 'No. Points', 'Offset', 'Command', 'Variables', 'Backannotation')
to_csv(filename: Union[str, Path], columns: Optional[list] = None, step: Union[int, List[int]] = -1, separator=',', **kwargs)[source]

Saves the data to a CSV file.

Parameters:
  • filename (str) – Name of the file to save the data to

  • columns (list) – List of traces to use as columns. Default is all traces

  • step (int) – Step number to retrieve. If not given, it

  • separator (str) – separator to use in the CSV file

  • kwargs (**dict) – Additional arguments to pass to the pandas.DataFrame.to_csv function

to_dataframe(columns: Optional[list] = None, step: Union[int, List[int]] = -1, **kwargs)[source]

Returns a pandas DataFrame with the requested data.

Parameters:
  • step (int) – Step number to retrieve. If not given, it

  • columns (list) – List of traces to use as columns. Default is all traces

  • kwargs (**dict) – Additional arguments to pass to the pandas.DataFrame constructor

Returns:

A pandas DataFrame

Return type:

pandas.DataFrame

to_excel(filename: Union[str, Path], columns: Optional[list] = None, step: Union[int, List[int]] = -1, **kwargs)[source]

Saves the data to an Excel file. :param filename: Name of the file to save the data to :type filename: str :param columns: List of traces to use as columns. Default is all traces :type columns: list :param step: Step number to retrieve. If not given, it :type step: int :param kwargs: Additional arguments to pass to the pandas.DataFrame.to_excel function :type kwargs: **dict