From a9f61348496fa67383847c4c8f670ccaba5ae9d0 Mon Sep 17 00:00:00 2001
From: Andreas Freise <adf@star.bham.ac.uk>
Date: Sun, 5 Jan 2014 21:47:22 +0000
Subject: [PATCH] first compute and plor script pair.

---
 examples/asc_test/OSCAR_large_tilt_ETM.txt |  12 ++
 examples/asc_test/OSCAR_large_tilt_ITM.txt |  13 ++
 examples/asc_test/master3.py               | 149 +++++++++++++++++++++
 examples/asc_test/master3_plot.py          | 115 ++++++++++++++++
 4 files changed, 289 insertions(+)
 create mode 100644 examples/asc_test/OSCAR_large_tilt_ETM.txt
 create mode 100644 examples/asc_test/OSCAR_large_tilt_ITM.txt
 create mode 100644 examples/asc_test/master3.py
 create mode 100644 examples/asc_test/master3_plot.py

diff --git a/examples/asc_test/OSCAR_large_tilt_ETM.txt b/examples/asc_test/OSCAR_large_tilt_ETM.txt
new file mode 100644
index 0000000..f2d285e
--- /dev/null
+++ b/examples/asc_test/OSCAR_large_tilt_ETM.txt
@@ -0,0 +1,12 @@
+%ETM_tilt	WFS1	WFS2
+0	 -3.465644e-019	 3.797567e-019
+0.1E-6	-2.023423e-07 	-1.52444e-05
+0.2E-6	-4.356855e-07	-3.010061e-05
+0.3E-6	-7.269388e-07	-4.419695e-05
+0.4E-6	-1.095792e-06	-5.719374e-05
+0.5E-6	-1.553044e-06	-6.879677e-05
+0.6E-6	-2.100566e-06	-7.876738e-05
+0.7E-6	-2.732976e-06	-8.692871e-05
+0.8E-6	-3.439824e-06	-9.316885e-05
+0.9E-6	-4.19318e-06	-9.745507e-05
+1E-6	-4.752869e-06	 -0.0001000194
diff --git a/examples/asc_test/OSCAR_large_tilt_ITM.txt b/examples/asc_test/OSCAR_large_tilt_ITM.txt
new file mode 100644
index 0000000..7c9420b
--- /dev/null
+++ b/examples/asc_test/OSCAR_large_tilt_ITM.txt
@@ -0,0 +1,13 @@
+%ITM_tilt	WFS1	WFS2
+0	 -3.465644e-019	 3.797567e-019
+0.1E-6	1.442776e-005	-1.90612e-007
+0.2E-6	2.859277e-005	-3.947172e-007
+0.3E-6	4.223356e-005	-6.221067e-007
+0.4E-6	5.510833e-005	-8.827575e-007
+0.5E-6	6.699603e-005	-1.183257e-006
+0.6E-6	7.770424e-005	-1.526835e-006
+0.7E-6	8.70751e-005	 -1.913302e-006
+0.8E-6	9.499032e-005 	 -2.339361e-006
+0.9E-6	0.0001013728 	 -2.798201e-006
+1E-6	0.0001061641	 -3.268848e-006
+
diff --git a/examples/asc_test/master3.py b/examples/asc_test/master3.py
new file mode 100644
index 0000000..44821c7
--- /dev/null
+++ b/examples/asc_test/master3.py
@@ -0,0 +1,149 @@
+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 master3_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
+    global result
+    
+    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))
+        
+    # overwriting some variables
+    kat.maxtem=3
+    Lambda=1064.0e-9
+        
+    print "--------------------------------------------------------"
+    print " 9. ASC signals for large misalignments"
+    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 ITM ybeta lin 0 1u 100')
+    maxtems = [1, 3, 7, 20]
+    #kat.verbose=1
+    xscale = 1e6
+    yscale = 1e6
+    global out
+    tmpfilename = "datashelf1.dat"
+    backupname = "datashelf1.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/master3_plot.py b/examples/asc_test/master3_plot.py
new file mode 100644
index 0000000..ff9e961
--- /dev/null
+++ b/examples/asc_test/master3_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_ITM.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 master3.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 " 9. ASC signals for large misalignments"
+    asc_large()
+    
+
+def asc_large():
+    xscale = 1e6
+    yscale = 1e6
+    tmpfilename = "datashelf1.dat"
+    backupname = "datashelf1.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_ITM.txt",comments='%')
+
+    x=xscale*osc1[:,0]
+    y=yscale*osc1[:,1]
+    pl.scatter(x,y,s=80,facecolors='none', edgecolors='k', label='OSCAR')
+    y=yscale*osc1[:,2]
+    pl.scatter(x,y,s=80,facecolors='none', edgecolors='k')
+    pl.xlabel("ITM ybeta [urad]")
+    pl.ylabel("Alignment signal [uW]")
+    pl.annotate('WFS1',xy=[0.42,70])
+    pl.annotate('WFS2',xy=[0.62,5])
+    pl.xlim([0,1])
+    pl.legend(loc=2)
+    pl.grid()
+    pl.draw()
+    pl.show(block=0)
+    printPDF(fig)
+    
+
+    
+if __name__ == '__main__':
+    main()
-- 
GitLab