Skip to content

astorguy/py4spice

Repository files navigation

Python-for-Spice (py4spice)

Lightweight Python package interface to Ngspice

Motivation

Ngspice is an open source electrical circuit simulator. It typically executes in batch mode using an archaic script interface. The Python-for-Spice package facilitates Ngspice execution using Python scripts. You can launch multiple analyses and convert the results to NumPy arrays, enabling downstream computation or plotting with Matplotlib.

Python-for-Spice is not an API for Ngspice. Nor does it use the API provided by Ngspice. Instead, it offers a set of helper classes to make it easier to run Ngspice in batch process fashion.

A modest knowledge of Ngspice and Python is required.

Learning Ngspice and Python-for-Spices

The learn_ngspice respository offers an efficient way to learn Ngspice and Python-for-Spice with a set of example circuits.

Installation

Install Ngspice

Ngspice must be installed. For most Linux distributions, Ngspice can be installed with a package manager. As an example, for Debian-based Linux use these commands:

sudo apt update
sudo apt install ngspice

Install py4spice

py4spice is installed in the customary way for a PyPI package.

pip install py4spice

Package Modules

Module Description
analyses Prepares analysis command that will go into control file and be executed during simulation
control Generate control file to for a simulation
kicad_netlist Create and execute a Kicad netlist export from a schematic
netlist Create, modify, and combine netlists to prepare for an Ngspice simulation
plot Matplotlib plot of numpy results from simulation
print_section Section off text so it is easier to read in terminal
sim_results Create objects for results extracted from simulation text files. Depending on the analysis type, the data are stored in different ways: either a plot or a table (dictionary)
simulate Setup or run an Ngspice simulation
step_info Perform variable measurements from step analyses. (i.e. rise-time, frequency, ...)
vectors Vector set of signals for which to gather data, plot, ...
waveforms Waveforms with a single x value and one or more y values in a 2D numpy array. Header defines the column names

About

py4spice: Python for Ngspice

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors