From 550818da55bb3e2d06c468402bd0f39c735aac63 Mon Sep 17 00:00:00 2001 From: fuchenxi <1256257282@qq.com> Date: Thu, 26 Sep 2024 22:11:52 +0800 Subject: [PATCH] =?UTF-8?q?ngspice=E7=94=BB=E5=9B=BE=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elec/ABCStar_fe_get_fig.py | 59 -------------------------------------- elec/__init__.py | 20 ++++++------- elec/drs4_get_fig.py | 57 ------------------------------------ elec/ngspice_get_fig.py | 22 +++++++------- 4 files changed, 20 insertions(+), 138 deletions(-) delete mode 100755 elec/ABCStar_fe_get_fig.py delete mode 100755 elec/drs4_get_fig.py diff --git a/elec/ABCStar_fe_get_fig.py b/elec/ABCStar_fe_get_fig.py deleted file mode 100755 index dc63432..0000000 --- a/elec/ABCStar_fe_get_fig.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/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() - diff --git a/elec/__init__.py b/elec/__init__.py index 3d9a1d6..9292bbe 100644 --- a/elec/__init__.py +++ b/elec/__init__.py @@ -1,22 +1,18 @@ - +import os def main(kwargs): label = kwargs['label'] + os.makedirs('output/elec', exist_ok=True) if label == 'ngspice_t1': import subprocess subprocess.run(['ngspice -b output/elec/T1_tmp.cir'], shell=True) - elif label == 'ngspice_ABCStar_fe': - import subprocess - subprocess.run(['ngspice -b param_file/circuit/ABCStar_fe.cir'], shell=True) - elif label == 'drs4_get_analog': + elif label.startswith('ngspice_'): import subprocess - subprocess.run(['ngspice -b param_file/circuit/drs4_analog.cir'], shell=True) - elif label == 'drs4_get_fig': - from . import drs4_get_fig - drs4_get_fig.main() - elif label == 'ABCStar_fe_get_fig': - from . import ABCStar_fe_get_fig - ABCStar_fe_get_fig.main() + elec_name = label.replace('ngspice_', '') + subprocess.run(['ngspice -b param_file/circuit/{}.cir'.format(elec_name)], shell=True) + elif label.endswith('_get_fig'): + from . import ngspice_get_fig + ngspice_get_fig.main(label.replace('_get_fig', '')) else: from . import readout readout.main(label) diff --git a/elec/drs4_get_fig.py b/elec/drs4_get_fig.py deleted file mode 100755 index a27c891..0000000 --- a/elec/drs4_get_fig.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/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() - diff --git a/elec/ngspice_get_fig.py b/elec/ngspice_get_fig.py index 9026dbc..130765e 100644 --- a/elec/ngspice_get_fig.py +++ b/elec/ngspice_get_fig.py @@ -1,8 +1,13 @@ #!/usr/bin/env python3 -import ROOT import sys +import os + import numpy +import ROOT + +from util.output import output + # TODO: Need to be TOTALLY rewritten def read_file(file_path,file_name): with open(file_path + '/' + file_name) as f: @@ -18,15 +23,14 @@ def read_file(file_path,file_name): return time,volt -def main(): - file_path = 'output/elec/ngspice_fig' - file_name = sys.argv[1] - com_name=file_name.split('.')[0] - fig_name=file_path + com_name + '.pdf' +def main(elec_name): + file_path = output(__file__) + fig_name = os.path.join(file_path, elec_name+'.pdf') time,volt = [],[] - time,volt = read_file(file_path,file_name) + time,volt = read_file(file_path, elec_name+'.raw') length = len(time) + t_min, t_max = time[0], time[-1] ROOT.gROOT.SetBatch() c = ROOT.TCanvas('c','c',700,600) @@ -37,13 +41,12 @@ def main(): f1.SetLineWidth(2) f1.GetXaxis().SetTitle('Time [ns]') - f1.GetXaxis().SetLimits(0,20) + f1.GetXaxis().SetLimits(t_min, t_max) f1.GetXaxis().CenterTitle() f1.GetXaxis().SetTitleSize(0.05) f1.GetXaxis().SetTitleOffset(0.8) f1.GetYaxis().SetTitle('Voltage [mV]') - f1.GetYaxis().SetLimits(0,-5) f1.GetYaxis().CenterTitle() f1.GetYaxis().SetTitleSize(0.05) f1.GetYaxis().SetTitleOffset(0.7) @@ -51,7 +54,6 @@ def main(): c.cd() f1.Draw('AL') c.SaveAs(fig_name) - print("figure has been saved in " , fig_name) if __name__ == '__main__': main() -- GitLab