The story of reading HSPICE data in Python

Introduction

What I wanted to do. Matrix calculation to read necessary data from HSPICE and use it for machine learning.

DeCiDa library

I found a circuit simulator library called DeCiDa that runs on Python3. By using this library, it is possible to operate the circuit simulator directly from DeCiDa, but this time it was used only for data conversion.

Code

import numpy as np
from scipy import interpolate
from decida.Data import Data

d_sampling = 0.005
s_sampling = 0
e_sampling = 70

n_sampling = int((e_sampling - s_sampling)/d_sampling + 1)
time_r = np.linspace(s_sampling,e_sampling,n_sampling)

#read .tr0
d = Data()
d.read_hspice('xxx.tr0')
rows = d.nrows()
cols = d.ncols()

#delete unnecessary cols
leave_cols = [0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,42]
n_leave_cols = len(leave_cols)

for i in range( cols ):
    j = cols - i
    if not (j in leave_cols) :
        d.delete(j)
#d.delete( tuple of col_name )

#trans to numpy array
original_data = np.empty((n_leave_cols,rows))
for i in range(n_leave_cols):
    original_data[i] = d.get(i)

#delete rows which is not change TIME
k = np.zeros(rows-1)
for i in range(rows-1):
    j = rows-i-1
    if (original_data[0,j] <= original_data[0,j-1] ):
        original_data = np.delete(original_data,j,1)

# resamp
def resamp(y):
    f = interpolate.interp1d(original_data[0], y, kind='linear')
    return f(time_r)

r_data = np.empty((n_leave_cols,n_sampling))
r_data[0] = time_r
r_data[1:] = resamp(original_data[1:])

np.save('rData.npy',r_data)

Code description

It is possible to read the HSPICE simulation result on Python with the Data class of DeCiDa.

variable

・ S_sampling, e_sampling The start and end times of the simulation in Spice. ・ D_sampling Sampling interval at read time.

Data read

d = Data() Data can be stored in d with d.read_hspice ('xxx.xxx'). There are also methods that support CSV and NGSpice.

Erase unnecessary data

I think there is a data array that is not necessary for calculation, d.delete(col) Can be erased with. col can be specified as an integer value or column name. You can erase multiple tuples by passing them. (I had the column names to keep this time, so I deleted them one by one)

You can get the column number from the column name with d.index ("zzz").

Convert to Numpy array

It is available at d.get (col). It seems that you can do it without using the for statement ……. It seems that it can be integrated with the unnecessary data eraser in the above chapter ....

Resampling

Since the time axis of Spice data is not evenly spaced, resampling is performed with SciPy's interpolate. However, if the time data is fogged, resampling cannot be performed, so erasing is performed.

Then, it was linearly complemented and saved as Numpy data.

Summary

I explained the code to convert the analog circuit simulator and Python data. Currently, Spice is turned separately and the data is read from the result, but since DeCiDa itself has a method to operate Spice, I would like to consider improving efficiency by using that method.

Recommended Posts

The story of reading HSPICE data in Python
Let's use the open data of "Mamebus" in Python
The story of Python and the story of NaN
The story of participating in AtCoder
The story of the "hole" in the file
Try scraping the data of COVID-19 in Tokyo with Python
The story of rubyist struggling with python :: Dict data with pycall
[Homology] Count the number of holes in data with Python
Check the behavior of destructor in Python
The story of an error in PyOCR
The story of verifying the open data of COVID-19
The story of making Python an exe
The result of installing python in Anaconda
The story of manipulating python global variables
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
The story of blackjack A processing (python)
Output the number of CPU cores in Python
The story of low learning costs for Python
[Python] Sort the list of pathlib.Path in natural sort
Get the caller of a function in Python
Match the distribution of each group in Python
View the result of geometry processing in Python
the zen of Python
Make a copy of the list in Python
Real-time visualization of thermography AMG8833 data in Python
The story of sys.path.append ()
Find the divisor of the value entered in python
Image processing? The story of starting Python for
The story of finding the optimal n in N fist
Find the solution of the nth-order equation in python
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Output in the form of a python array
The story of viewing media files in Django
Code reading of faker, a library that generates test data in Python
A well-prepared record of data analysis in Python
Get the key for the second layer migration of JSON data in python
Basic story of inheritance in Python (for beginners)
Experience the good calculation efficiency of vectorization in Python
Summary of tools needed to analyze data in Python
Full-width and half-width processing of CSV data in Python
The story of Python without increment and decrement operators.
How to get the number of digits in Python
Power BI visualization of Salesforce data entirely in Python
The story of building the fastest Linux environment in the world
About the inefficiency of data transfer in luigi on-memory
Learn the design pattern "Chain of Responsibility" in Python
Implement the solution of Riccati algebraic equations in Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
[Python] Outputs all combinations of elements in the list
Understand the status of data loss --Python vs. R
Get the URL of the HTTP redirect destination in Python
A reminder about the implementation of recommendations in Python
The story of automatic language conversion of TypeScript / JavaScript / Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Extract the band information of raster data with python
Check the asymptotic nature of the probability distribution in Python