Post Go back to editing

LTSpice .raw data format

I would like to write a program to automate several simulations from LTSpice and post-process the resulting .raw file data.

Is there a document that is available the describes the LTSpice .raw data file format?

Thank you,

David

Parents
  • Hello David,

    You can use LTspiceXVII in batch mode. See the help pages: Modes of Operation -> Command Line Switches

    When you then use the option -ascii, you will get a raw-file formatted in ASCII-text. This would be the easiest way. It's suitable if you have not too much data points. I remember a colleague who told me that he read the ASCII raw-file with Python for further processing.

    The raw-format is not officially disclosed, but everybody can explore it with a hex editor. In principle the format could change at some day, but it's practically the same since at least 15 years.

    Example for .TRAN
    The time is in double, the voltage and current values are in float. If double precision is forced by .options numdgt=10  (any number >6), then the voltage and current values are stored in double too. Are you aware that the header of the raw-file is in 16bit unicode?

    .....
    .....
    Variables:
        0    time    time
        1    V(a)    voltage
        2    I(R1)    device_current
        3    I(V1)    device_current
    Binary:
    double float float float double float float float double ........

    If you work with Matlab, you could use an available Matlab-script for reading the raw-file.
    There is also a small program ltsputil.exe to convert a raw-file into a text-file.

    Helmut

  • Hello, hope all is fine.

    I actually have sort of the same problem. I scripted a python code so as to generate automatically LTspice netlists since the simulations I run are of very complicated circuits. I have been looking for two days now for a python command that will ask LTspice to simulate the netlist so as to generate the raw file for me to extract data needed. I, unfortunately, did not manage to find one. 

    All suggestions are welcomed and are desperately awaited.

    Thanks in advance.

    Kaoutar Slight smile

Reply
  • Hello, hope all is fine.

    I actually have sort of the same problem. I scripted a python code so as to generate automatically LTspice netlists since the simulations I run are of very complicated circuits. I have been looking for two days now for a python command that will ask LTspice to simulate the netlist so as to generate the raw file for me to extract data needed. I, unfortunately, did not manage to find one. 

    All suggestions are welcomed and are desperately awaited.

    Thanks in advance.

    Kaoutar Slight smile

Children
  • Dear Kaoutar,

    To run LTspice simulations in python you can "import ltspice" module via pip for example and trigger your netlist file via batch which would generate raw files for your simulations and run that raw file in python to make the plots.

    ### create a bat file ### for example 

    "C:\Program Files\LTC\LTspiceXVII\XVIIx64.exe" -b "C:\Users\Desktop\file.net"

    ###################

    ## python code example ##

    import os

    import subprocess #<to run batch file>

    import ltspice #<to run spice simulations on python>

    import matplotlib.pyplot as plt #<to generate plots>

    bathfile= os.chidr("<path where ''file.bat' file stored>")

    netlist = os.chidr("< path where 'file.net' stored>")

    subprocess.call([r"{path}".format(path=batpath))])  # triggers batch file in back end

    rawfile = os.chidr("<path were generated raw file is stored>")

    l = ltspice.Ltspice(rawfile)
    
    l.parse() # Data loading sequence. It may take few minutes.
    time = l.getTime() # creates simulation time data frame

    V_source = l.getData('V(source)')
    I_load= l.getData('I')
    
    plt.plot(time, V_source)
    plt.plot(time, I_load)
    plt.show()
    ################################################### 

    Hope this helps what your looking for.

    Thanks & Regards,
    Goutham
  • Dear Goutham, 

    I used your solution which worked miraculously. However, I started running into some errors. Do you have any idea how can I solve it? 

    >>> l = ltspice.Ltspice('6spires_sans_mutuelle.raw')
    >>> l.parse()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python37\lib\site-packages\ltspice\ltspice.py", line 98, in parse
    self.data_raw = np.reshape(np.array(self.data_raw), (self._point_num, self._variable_num + 1))
    File "<__array_function__ internals>", line 6, in reshape
    File "C:\Python37\lib\site-packages\numpy\core\fromnumeric.py", line 301, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
    File "C:\Python37\lib\site-packages\numpy\core\fromnumeric.py", line 61, in _wrapfunc
    return bound(*args, **kwds)
    ValueError: cannot reshape array of size 0 into shape (104074,69)

    Thanks in advance