[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-user: gnucap, hspice output -> python

There have been a few python-based tools for analysis of simulation data
posted here, e.g. "oscopy" and "dataplot".  Here is another to
complement them.

To use python and numpy's arrays as the working format for signal
analysis requires conversion or import from a simulator's usual output.
Current gnucap output is an easy-to-read ascii format with

Converting HSPICE output is a different story...  There are several out
there but I have settled on the "sp2sp" utility from gwave as it can
output an ascii format, again read into python via "numpy.genfromtxt()".

All this is great until (#files * size-each) gets large (GB in one of my
usage cases).  Using sp2sp + numpy.genfromtxt results in files being
read twice, written once, then read entirely into RAM as a numpy.array.
This gets slow.

Solution: cache the data in a ".npy" file.  It's a binary format and,
most importantly, allows numpy to memory-map the data.  Caching the data
(for memmap read) does not allow other metadata in the file like column
headers and sweep variables/values.  This must be saved separately to
re-read the data.

Enter "pyspice.spicereader" and an extension to "sp2sp":
The gwave branch "guile-gnome-platform-branch" rev 245 patch now
includes an option to directly convert to a ".npy" file with a trick to
include metadata.

Usage is:
sp2sp -t ascii -c numpy -o out_file.npy in_file.dat
sp2sp -t hspice -c numpy -o out_file.npy in_file.tr0

The resulting ".npy" file has extra bytes appended to the normal
numpy.save() file: a string representation of a dict of column labels
and sweep info, ending in a little endian uint16 giving the length of
the appended info.

The attached numpy2ascii.py gives an example how to read the file by
converting the data back to the gnucap ascii format.

My module pyspice.spicereader presents the data as named attributes and
makes sweep handling and plotting easy.  Now I can do:

    from pylab import *
    from pyspice.spicereader import loadSimData

    d = loadSimData('channel.tr0')
    print d.siglist
    plot(d.x, d.Ivsupply)

loadSimData caches the data by running sp2sp and mem-maps the file which
makes subsequent reads very fast.

The spicereader.py is part of my "pyspice" project (but not dependent
on other parts of it).  The pyspice module was written to cleanup LVS
extracted layouts for simulation, it likely does not work as-is; I
haven't used it for a few years.

Repeat: this requires the SVN branch guile-gnome-platform-branch of
gwave's utility "sp2sp".





geda-user mailing list