Skip to content
Snippets Groups Projects
Commit 550818da authored by Chenxi Fu's avatar Chenxi Fu
Browse files

ngspice画图代码整理

parent 05865e4e
No related branches found
No related tags found
1 merge request!27ngspice画图代码整理
#!/usr/bin/env python3
# TODO: Need to be TOTALLY rewritten
import ROOT
import numpy
def read_file(file_path,file_name):
with open(file_path + file_name) as f:
lines = f.readlines()
time,volt = [],[]
for line in lines:
time.append(float(line.split()[0])*1e9)
volt.append(float(line.split()[1]))
time = numpy.array(time,dtype='float64')
volt = numpy.array(volt,dtype='float64')
return time,volt
def main():
file_path = 'output/elec/'
#file_name = 'drs4_analog.raw'
file_name = 'ABCStar_fe.raw'
com_name=file_name.split('.')[0]
fig_name=file_path + com_name + '.pdf'
time,volt = [],[]
time,volt = read_file(file_path,file_name)
length = len(time)
ROOT.gROOT.SetBatch()
c = ROOT.TCanvas('c','c',700,600)
f1 = ROOT.TGraph(length,time,volt)
f1.SetTitle(' ')
f1.SetLineColor(2)
f1.SetLineWidth(2)
f1.GetXaxis().SetTitle('Time [ns]')
# f1.GetXaxis().SetLimits(0,5)
f1.GetXaxis().SetLimits(0,30)
f1.GetXaxis().CenterTitle()
f1.GetXaxis().SetTitleSize(0.05)
f1.GetXaxis().SetTitleOffset(0.8)
f1.GetYaxis().SetTitle('Voltage [V]')
f1.GetYaxis().SetLimits(0,-1)
f1.GetYaxis().CenterTitle()
f1.GetYaxis().SetTitleSize(0.05)
f1.GetYaxis().SetTitleOffset(0.93)
c.cd()
f1.Draw('AL')
c.SaveAs(fig_name)
print("figure has been saved in " , fig_name)
if __name__ == '__main__':
main()
import os
def main(kwargs): def main(kwargs):
label = kwargs['label'] label = kwargs['label']
os.makedirs('output/elec', exist_ok=True)
if label == 'ngspice_t1': if label == 'ngspice_t1':
import subprocess import subprocess
subprocess.run(['ngspice -b output/elec/T1_tmp.cir'], shell=True) subprocess.run(['ngspice -b output/elec/T1_tmp.cir'], shell=True)
elif label == 'ngspice_ABCStar_fe': elif label.startswith('ngspice_'):
import subprocess
subprocess.run(['ngspice -b param_file/circuit/ABCStar_fe.cir'], shell=True)
elif label == 'drs4_get_analog':
import subprocess import subprocess
subprocess.run(['ngspice -b param_file/circuit/drs4_analog.cir'], shell=True) elec_name = label.replace('ngspice_', '')
elif label == 'drs4_get_fig': subprocess.run(['ngspice -b param_file/circuit/{}.cir'.format(elec_name)], shell=True)
from . import drs4_get_fig elif label.endswith('_get_fig'):
drs4_get_fig.main() from . import ngspice_get_fig
elif label == 'ABCStar_fe_get_fig': ngspice_get_fig.main(label.replace('_get_fig', ''))
from . import ABCStar_fe_get_fig
ABCStar_fe_get_fig.main()
else: else:
from . import readout from . import readout
readout.main(label) readout.main(label)
#!/usr/bin/env python3
# TODO: Need to be TOTALLY rewritten
import ROOT
import numpy
def read_file(file_path,file_name):
with open(file_path + file_name) as f:
lines = f.readlines()
time,volt = [],[]
for line in lines:
time.append(float(line.split()[0])*1e9)
volt.append(float(line.split()[1]))
time = numpy.array(time,dtype='float64')
volt = numpy.array(volt,dtype='float64')
return time,volt
def main():
file_path = 'output/elec/'
file_name = 'drs4_analog.raw'
com_name=file_name.split('.')[0]
fig_name=file_path + com_name + '.pdf'
time,volt = [],[]
time,volt = read_file(file_path,file_name)
length = len(time)
ROOT.gROOT.SetBatch()
c = ROOT.TCanvas('c','c',700,600)
f1 = ROOT.TGraph(length,time,volt)
f1.SetTitle(' ')
f1.SetLineColor(2)
f1.SetLineWidth(2)
f1.GetXaxis().SetTitle('Time [ns]')
f1.GetXaxis().SetLimits(0,5)
f1.GetXaxis().CenterTitle()
f1.GetXaxis().SetTitleSize(0.05)
f1.GetXaxis().SetTitleOffset(0.8)
f1.GetYaxis().SetTitle('Voltage [V]')
f1.GetYaxis().SetLimits(0,-1)
f1.GetYaxis().CenterTitle()
f1.GetYaxis().SetTitleSize(0.05)
f1.GetYaxis().SetTitleOffset(0.93)
c.cd()
f1.Draw('AL')
c.SaveAs(fig_name)
print("figure has been saved in " , fig_name)
if __name__ == '__main__':
main()
#!/usr/bin/env python3 #!/usr/bin/env python3
import ROOT
import sys import sys
import os
import numpy import numpy
import ROOT
from util.output import output
# TODO: Need to be TOTALLY rewritten # TODO: Need to be TOTALLY rewritten
def read_file(file_path,file_name): def read_file(file_path,file_name):
with open(file_path + '/' + file_name) as f: with open(file_path + '/' + file_name) as f:
...@@ -18,15 +23,14 @@ def read_file(file_path,file_name): ...@@ -18,15 +23,14 @@ def read_file(file_path,file_name):
return time,volt return time,volt
def main(): def main(elec_name):
file_path = 'output/elec/ngspice_fig' file_path = output(__file__)
file_name = sys.argv[1] fig_name = os.path.join(file_path, elec_name+'.pdf')
com_name=file_name.split('.')[0]
fig_name=file_path + com_name + '.pdf'
time,volt = [],[] time,volt = [],[]
time,volt = read_file(file_path,file_name) time,volt = read_file(file_path, elec_name+'.raw')
length = len(time) length = len(time)
t_min, t_max = time[0], time[-1]
ROOT.gROOT.SetBatch() ROOT.gROOT.SetBatch()
c = ROOT.TCanvas('c','c',700,600) c = ROOT.TCanvas('c','c',700,600)
...@@ -37,13 +41,12 @@ def main(): ...@@ -37,13 +41,12 @@ def main():
f1.SetLineWidth(2) f1.SetLineWidth(2)
f1.GetXaxis().SetTitle('Time [ns]') f1.GetXaxis().SetTitle('Time [ns]')
f1.GetXaxis().SetLimits(0,20) f1.GetXaxis().SetLimits(t_min, t_max)
f1.GetXaxis().CenterTitle() f1.GetXaxis().CenterTitle()
f1.GetXaxis().SetTitleSize(0.05) f1.GetXaxis().SetTitleSize(0.05)
f1.GetXaxis().SetTitleOffset(0.8) f1.GetXaxis().SetTitleOffset(0.8)
f1.GetYaxis().SetTitle('Voltage [mV]') f1.GetYaxis().SetTitle('Voltage [mV]')
f1.GetYaxis().SetLimits(0,-5)
f1.GetYaxis().CenterTitle() f1.GetYaxis().CenterTitle()
f1.GetYaxis().SetTitleSize(0.05) f1.GetYaxis().SetTitleSize(0.05)
f1.GetYaxis().SetTitleOffset(0.7) f1.GetYaxis().SetTitleOffset(0.7)
...@@ -51,7 +54,6 @@ def main(): ...@@ -51,7 +54,6 @@ def main():
c.cd() c.cd()
f1.Draw('AL') f1.Draw('AL')
c.SaveAs(fig_name) c.SaveAs(fig_name)
print("figure has been saved in " , fig_name)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment