Skip to main content

Ltspice result file handler for python

Project description

LTSpice data parsing library for python

Installation

$ pip install ltspice

Usage

import ltspice
filepath = 'Your ltspice output file (.raw)'
l = ltspice.Ltspice(filepath)
l.parse() # Data loading sequence. It may take few minutes.

time = l.getTime()
V1 = l.getData('V(N1)')

Test

01 - RC Circuit

LTSpice file (.asc)

Python code (.py)

import ltspice
import matplotlib.pyplot as plt
import numpy as np
import os

l = ltspice.Ltspice(os.path.dirname(__file__)+'\\01_RC_circuit.raw') 
# Make sure that the .raw file is located in the correct path
l.parse() 

time = l.getTime()
V_source = l.getData('V(source)')
V_cap = l.getData('V(cap)')

plt.plot(time, V_source)
plt.plot(time, V_cap)
plt.show()

Output result

02 - Multi point simulation

LTSpice file (.asc)

Python code (.py)

import ltspice
import matplotlib.pyplot as plt
import numpy as np
import os

l = ltspice.Ltspice(os.path.dirname(__file__)+'\\02_Rectifier.raw') 
# Make sure that the .raw file is located in the correct path
l.parse() 

time = l.getTime()
V_source = l.getData('V(source)')
V_cap_max = []

plt.plot(time, V_source)
for i in range(l.c_number): # Iteration in simulation cases 
    time = l.getTime(i)
    # Case number starts from zero
    # Each case has different time point numbers
    V_cap = l.getData('V(cap,pgnd)',i)
    V_cap_max.append(max(V_cap))
    plt.plot(time, V_cap)

print(V_cap_max)

plt.xlim((0, 1e-3))
plt.ylim((-15, 15))
plt.grid()
plt.show()

Output result

$ [8.299080580472946, 7.855469107627869, 7.391375303268433, 6.944645524024963, 6.529755532741547]

03 - Multi point simulation 2d

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ltspice, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size ltspice-0.3.3.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page