-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_dc_results
executable file
·78 lines (60 loc) · 2.01 KB
/
plot_dc_results
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# Imports {{{1
import re
from textwrap import dedent
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import numpy as np
from docopt import docopt
from inform import Error, Inform, comment, display, done, fatal, os_error
from psf_utils import PSF
from quantiphy import Quantity
from shlib import Run, render_command, set_prefs as shlib_set_prefs, to_path
# Globals {{{1
# plotting preferences {{{2
use_sci_notation = False # alternative is to use SI scale factors
show_power = False # display in V²/Hz if True and V/√Hz otherwise
#####################
# Netlist to plot
#####################
out_file = "input.scs"
spectre_exe = "spectre" # Spectre executable
netlist_file = to_path(out_file) # Spectre netlist file
log_file = netlist_file.with_suffix(".log") # Spectre logfile
results_dir = netlist_file.with_suffix(".raw") # simulation results directory
## Analysis type
psf_file_dc = results_dir / "dc1.dc" # Input PSF file for dc simulation
psf_file_ac = results_dir / "ac1.ac" # Input PSF file for ac simulation
print(psf_file_dc)
#####################
# Plot DC Results
#####################
try:
# Get results from psf file
results = PSF(psf_file_dc, sep=":")
sweep = results.get_sweep()
# Get units Vin
x_name = sweep.name
x_units = sweep.units
# Get sweep data from x axis
v_in = sweep.abscissa
print(v_in)
print("vin len:", len(v_in))
# Get raw data
v_out_raw = results.get_signal("vo")
# Get usable data
v_out = v_out_raw.ordinate
print("vout len:", len(v_out))
v_in = np.linspace(0,1.2,len(v_out))
# Figure size
plt.figure(figsize=(4.5, 3))
plt.title("CS amplifier DC Sweep")
plt.xlabel("Vin, V", fontsize=11)
plt.ylabel('Vout, V', fontsize=11)
plt.plot(v_in, v_out, color='red')
plt.savefig('dc_sweep.svg', format='svg', pad_inches=0, bbox_inches='tight')
#plt.show()
except Error as e:
e.terminate()
except KeyboardInterrupt as e:
done()