master3_plot.py 3.23 KB
Newer Older
1
2
3
4
5
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

6
7
8
9
10
11
12
13
14
15
16
17
from pykat import finesse
from pykat.commands import *
import pylab as pl
import numpy as np
import shelve
import sys

import matplotlib
formatter = matplotlib.ticker.EngFormatter(unit='', places=0)
formatter.ENG_PREFIXES[-6] = 'u'

import matplotlib.backends.backend_pdf
18
19
def printPDF(self, filename):
        pdfp = matplotlib.backends.backend_pdf.PdfPages(filename)
20
21
22
23
        pdfp.savefig(self,dpi=300,bbox_inches='tight')
        pdfp.close()

def main():
24
    print("""
25
26
27
    --------------------------------------------------------------
    Example file for using PyKat to automate Finesse simulations
    Finesse: http://www.gwoptics.org/finesse
28
    PyKat:   http://www.gwoptics.org/pykat
29
        
30
31
    Run this file to plot the data generated with master3.py.
        
32
    Andreas Freise 16.01.2014
33
    --------------------------------------------------------------
34
    """)
35
36
37
38
39
40
41
42
43
44
45
    
    # 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
        
46
47
    print("--------------------------------------------------------")
    print(" Plotting ASC signals for large misalignments")
48
49
    asc_large('ITM')
    asc_large('ETM')
50
51
    

52
def asc_large(mir_name):
53
54
    xscale = 1e6
    yscale = 1e6
55
56
57
58
59
60
61
    if mir_name == 'ITM':
        ysign = 1.0
    else:
        ysign = -1.0
        
    tmpfilename = "datashelf_{0}.dat".format(mir_name)
    backupname = "datashelf_{0}.dat.bck".format(mir_name)
62
63
64

    try:
        tmpfile = shelve.open(tmpfilename)
65
66
        out=tmpfile[str('out')]
        maxtems=tmpfile[str('maxtems')]
67
68
69
70
71
72
73
74
75
        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
76
    for i, tem in enumerate(maxtems):
77
78
79
        data=out[str(tem)]
        WFS1_idx=data.ylabels.index("WFS1_I")
        WFS2_idx=data.ylabels.index("WFS2_I")
80
81
        pl.plot(xscale*data.x,ysign*yscale*data.y[:,WFS1_idx],'-', color= color_cycle[i], linewidth=lw[i], label='maxtem {0}'.format(tem))
        line, = pl.plot(xscale*data.x,ysign*yscale*data.y[:,WFS2_idx],'-', color = color_cycle[i], linewidth=lw[i])
82
83
        #line.set_dashes([12, 4]) 

84
    osc1=np.loadtxt("OSCAR_large_tilt_{0}.txt".format(mir_name),comments='%')
85
86
87
88
89
90

    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')
91
    pl.xlabel("{0} vertical misalignment [urad]".format(mir_name))
92
    pl.ylabel("Alignment signal [uW]")
93
94
95
96
97
98
99
100
    if mir_name == 'ITM':
        pl.annotate('WFS1',xy=[0.42,70])
        pl.annotate('WFS2',xy=[0.62,5])
        pl.legend(loc=2)
    else:
        pl.annotate('WFS1',xy=[0.42,10])
        pl.annotate('WFS2',xy=[0.62,-70])
        pl.legend(loc=3)
101
102
103
104
    pl.xlim([0,1])
    pl.grid()
    pl.draw()
    pl.show(block=0)
105
    printPDF(fig, "large_{0}.pdf".format(mir_name))
106
107
108
109
    

if __name__ == '__main__':
    main()