diff --git a/examples/asc_test/master2.py b/examples/asc_test/master2.py index 204c6d6b87dcdf0c78b9ef7def1003e6e30bff57..4af7eaa4acfca1511f1918c269e5983a7046379a 100644 --- a/examples/asc_test/master2.py +++ b/examples/asc_test/master2.py @@ -115,6 +115,8 @@ def main(): tmpfile.close() +#----------------------------------------------------------------------------------- + def asc_signal(tmpkat): kat = copy.deepcopy(tmpkat) diff --git a/examples/asc_test/master3.py b/examples/asc_test/master3.py index 44821c739df47156c37baa2704d50c6f28bf7cb9..12fb88d2b6ea638a6320e52fdf9ace3c0bef2083 100644 --- a/examples/asc_test/master3.py +++ b/examples/asc_test/master3.py @@ -40,9 +40,8 @@ def main(): # %reset -f # making these global during testing and debugging - global kat - global out - global result + #global kat + #global out kat = finesse.kat(tempdir=".",tempname="test") kat.verbose = False @@ -57,12 +56,8 @@ def main(): tmpfile.close() except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) - # overwriting some variables - kat.maxtem=3 - Lambda=1064.0e-9 - print "--------------------------------------------------------" - print " 9. ASC signals for large misalignments" + print " 9. ASC signals for large misalignments (ITM)" asc_large(kat) diff --git a/examples/asc_test/master3_plot.py b/examples/asc_test/master3_plot.py index ff9e961af30f426881cad2348275f1bf43b26fdf..8b09d8037b6e44dd7e2d1e3306f0f6b7f4a8f824 100644 --- a/examples/asc_test/master3_plot.py +++ b/examples/asc_test/master3_plot.py @@ -60,7 +60,7 @@ def main(): except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) print "--------------------------------------------------------" - print " 9. ASC signals for large misalignments" + print " 9. Plotting ASC signals for large misalignments" asc_large() diff --git a/examples/asc_test/master4.py b/examples/asc_test/master4.py new file mode 100644 index 0000000000000000000000000000000000000000..d49f8f0988ba4763526f9904102fbdb807907893 --- /dev/null +++ b/examples/asc_test/master4.py @@ -0,0 +1,144 @@ +from pykat import finesse +from pykat.commands import * +import pylab as pl +import numpy as np +import shelve +import copy +import sys +import shutil + +from itertools import cycle +import matplotlib +from matplotlib import rc +import matplotlib.pyplot as plt +formatter = matplotlib.ticker.EngFormatter(unit='', places=0) +formatter.ENG_PREFIXES[-6] = 'u' + + +def main(): + + print """ + -------------------------------------------------------------- + Example file for using PyKat to automate Finesse simulations + Finesse: http://www.gwoptics.org/finesse + PyKat: https://pypi.python.org/pypi/PyKat/ + + The file runs through the various pykat files which are used + to generate the Finesse results reported in the document: + `Comparing Finesse simulations, analytical solutions and OSCAR + simulations of Fabry-Perot alignment signals', LIGO-T1300345 + + Run this file to create the data and master4_plot.py to plot + the results. Results are saved after each step and plots can + be created at any time. + + Andreas Freise 06.12.2013 + -------------------------------------------------------------- + """ + + # shall we clear the workspace? + # %reset -f + + # making these global during testing and debugging + #global kat + #global out + + kat = finesse.kat(tempdir=".",tempname="test") + kat.verbose = False + + tmpresultfile = 'myshelf2.dat' + + # loading data saved by master.py + kat.loadKatFile('asc_base3.kat') + try: + tmpfile = shelve.open(tmpresultfile) + result=tmpfile['result'] + tmpfile.close() + except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) + + print "--------------------------------------------------------" + print " 10. ASC signals for large misalignments (ETM)" + asc_large(kat) + + +def asc_large(tmpkat): + kat = copy.deepcopy(tmpkat) + + code_lock = """ + set err PDrefl_p re + lock z $err 900 1p + put* ETM phi $z + noplot z + """ + + kat.parseKatCode(code_lock) + kat.parseKatCode('yaxis abs') + kat.parseKatCode('xaxis ETM ybeta lin 0 1u 100') + maxtems = [1, 3, 7, 20] + #kat.verbose=1 + xscale = 1e6 + yscale = 1e6 + global out + tmpfilename = "datashelf2.dat" + backupname = "datashelf2.dat.bck" + out={} + done_maxtems = [] + + for tem in maxtems: + done_maxtems.append(tem) + print " Calculating maxtem = %d " % tem + kat.maxtem = tem + out[str(tem)] = kat.run(printout=0,printerr=1) + import os.path + if os.path.isfile(tmpfilename): + shutil.copyfile(tmpfilename, backupname) + + print " current results saved in: {0}".format(tmpfilename) + tmpfile = shelve.open(tmpfilename) + tmpfile['out']=out + tmpfile['maxtems']=done_maxtems + tmpfile.close() + +def asc_signal(tmpkat): + kat = copy.deepcopy(tmpkat) + + code_lock = """ + set err PDrefl_p re + lock z $err 900 1p + put* ETM phi $z + noplot z + """ + + kat.parseKatCode(code_lock) + kat.parseKatCode('yaxis abs') + kat.noxaxis = True + kat.maxtem=1 + + signal=np.zeros((2, 2)) + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + out = kat.run(printout=0,printerr=0) + WFS1_idx=out.ylabels.index("WFS1_I") + WFS2_idx=out.ylabels.index("WFS2_I") + signal[0,0] = out.y[WFS1_idx] + signal[1,0] = out.y[WFS2_idx] + + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + out = kat.run(printout=0,printerr=0) + signal[0,1] = out.y[WFS1_idx] + signal[1,1] = out.y[WFS2_idx] + signal = signal *1e10 + sensors=('WFS1', 'WFS2') + mirrors=('ITM', 'ETM') + print " ASC Matrix:" + for i in range(2): + print " ", sensors[i], " ", + for j in range(2): + print "%12.10g" % signal[i,j], + print mirrors[i] + return signal + + +if __name__ == '__main__': + main() diff --git a/examples/asc_test/master4_plot.py b/examples/asc_test/master4_plot.py new file mode 100644 index 0000000000000000000000000000000000000000..852a704d7fe68ea4c3d3a67998af3a049de3c6f6 --- /dev/null +++ b/examples/asc_test/master4_plot.py @@ -0,0 +1,115 @@ +from pykat import finesse +from pykat.commands import * +import pylab as pl +import numpy as np +import shelve +import copy +import sys +import shutil + +from itertools import cycle +import matplotlib +from matplotlib import rc +import matplotlib.pyplot as plt +formatter = matplotlib.ticker.EngFormatter(unit='', places=0) +formatter.ENG_PREFIXES[-6] = 'u' + +import matplotlib.backends.backend_pdf +def printPDF(self): + filename = 'test.pdf' + pdfp = matplotlib.backends.backend_pdf.PdfPages('large_ETM.pdf') + pdfp.savefig(self,dpi=300,bbox_inches='tight') + pdfp.close() + +def main(): + + print """ + -------------------------------------------------------------- + Example file for using PyKat to automate Finesse simulations + Finesse: http://www.gwoptics.org/finesse + PyKat: https://pypi.python.org/pypi/PyKat/ + + The file runs through the various pykat files which are used + to generate the Finesse results reported in the document: + `Comparing Finesse simulations, analytical solutions and OSCAR + simulations of Fabry-Perot alignment signals', LIGO-T1300345 + + Run this file to plot the data generated with master4.py. + + Andreas Freise 06.12.2013 + -------------------------------------------------------------- + """ + + # shall we clear the workspace? + # %reset -f + # maybe close all plot windows? + # close('all') + + # making these global during testing and debugging + #global kat + #global out + #global result + + tmpresultfile = 'myshelf2.dat' + + # loading data saved by master.py + try: + tmpfile = shelve.open(tmpresultfile) + result=tmpfile['result'] + tmpfile.close() + except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) + + print "--------------------------------------------------------" + print " 10. Plotting ASC signals for large misalignments (ETM)" + asc_large() + + +def asc_large(): + xscale = 1e6 + yscale = -1e6 + tmpfilename = "datashelf2.dat" + backupname = "datashelf2.dat.bck" + + try: + tmpfile = shelve.open(tmpfilename) + out=tmpfile['out'] + maxtems=tmpfile['maxtems'] + tmpfile.close() + except: raise Exception("Could not open temprary results file {0}".format(tmpfilename)) + + fig=pl.figure() + color_cycle=['b', 'c', 'r', 'k'] + N=len(maxtems) + lw=np.ones(N)*3 + lw[-2]=2 + lw[-1]=1 + for i, tem in zip(range(len(maxtems)), maxtems): + data=out[str(tem)] + WFS1_idx=data.ylabels.index("WFS1_I") + WFS2_idx=data.ylabels.index("WFS2_I") + pl.plot(xscale*data.x,yscale*data.y[:,WFS1_idx],'-', color= color_cycle[i], linewidth=lw[i], label='maxtem {0}'.format(tem)) + line, = pl.plot(xscale*data.x,yscale*data.y[:,WFS2_idx],'-', color = color_cycle[i], linewidth=lw[i]) + #line.set_dashes([12, 4]) + + osc1=np.loadtxt("OSCAR_large_tilt_ETM.txt",comments='%') + + x=xscale*osc1[:,0] + y=-1.0*yscale*osc1[:,1] + pl.scatter(x,y,s=80,facecolors='none', edgecolors='k', label='OSCAR') + y=-1.0*yscale*osc1[:,2] + pl.scatter(x,y,s=80,facecolors='none', edgecolors='k') + pl.xlabel("ETM ybeta [urad]") + pl.ylabel("Alignment signal [uW]") + pl.annotate('WFS1',xy=[0.42,10]) + pl.annotate('WFS2',xy=[0.62,-70]) + pl.xlim([0,1]) + pl.legend(loc=3) + pl.grid() + pl.draw() + pl.show(block=0) + printPDF(fig) + + + +if __name__ == '__main__': + main()