2021年4月4日 星期日

一次畫出IBIS當中所有[Model]的[Rising Waveform]跟[Falling Waveform]

 指定IBIS檔案路徑,執行以下腳本即可。

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 4 09:23:17 2021

@author: mlin
"""
import matplotlib.pyplot as plt


def plotWaveform(model_name, waveform):
plt.figure(figsize=(7, 4))
plt.clf()
header = []
_time_, _typ_, _min_, _max_ = [], [], [], []
for i in waveform:
if '=' in i:
header.append(i.strip())
continue
if '|' in i:
continue
try:
_time, _typ, _min, _max = i.strip().split()
_time_.append(float(_time.lower().replace('ps', 'e-12').replace('ns', 'e-9').replace('us', 'e-6')))
_typ_.append(
float(_typ.lower().replace('nv', 'e-9').replace('uv', 'e-6').replace('mv', 'e-3').replace('v', '')))
_min_.append(
float(_min.lower().replace('nv', 'e-9').replace('uv', 'e-6').replace('mv', 'e-3').replace('v', '')))
_max_.append(
float(_max.lower().replace('nv', 'e-9').replace('uv', 'e-6').replace('mv', 'e-3').replace('v', '')))
except:
pass
plt.plot(_time_, _typ_, 'g')
plt.plot(_time_, _min_, 'b')
plt.plot(_time_, _max_, 'r')
plt.title('{}\n{}\n{}\n{}'.format(model_name, ';'.join(header[0:3]), ';'.join(header[3:6]), ';'.join(header[6:9])))
plt.xlabel('Time(sec)')
plt.ylabel('Waveform(v)')
plt.grid()
plt.show()


data = {}
container = None
with open('D:\OneDrive - ANSYS, Inc/Models/IBIS/tpz015lg.ibs') as f:
for i in f:
if i.startswith('[Model]'):
_, model_name = i.strip().split()
data[model_name] = {}
continue

if i.startswith('['):
container = None

if '[rising waveform]' in i.lower():
try:
data[model_name]['rising_waveform'].append([])
except:
data[model_name]['rising_waveform'] = [[]]
finally:
container = data[model_name]['rising_waveform'][-1]
continue

if '[falling waveform]' in i.lower():
try:
data[model_name]['falling_waveform'].append([])
except:
data[model_name]['falling_waveform'] = [[]]
finally:
container = data[model_name]['falling_waveform'][-1]
continue

try:
container.append(i)
except:
pass

for model in data:
try:
for i in data[model]['rising_waveform']:
plotWaveform(model, i)
except:
pass
for model in data:
try:
for i in data[model]['falling_waveform']:
plotWaveform(model, i)
except:
pass
[圖一]畫出所有[Model]的[Rising Waveform]跟[Falling Waveform]


沒有留言:

張貼留言