Commit 723ce0c3 authored by Daniel Brown's avatar Daniel Brown
Browse files

Merge branch 'master' of gitmaster.atlas.aei.uni-hannover.de:pykat/pykat

parents 189384dc 5a6cabbc
This folder is part of the PyKat package and contains a set of
files python files which together run through the various
Finesse simulations.
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The master*py files can be 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.
The tasks described in that note were suggested and started at
the an international workshop for commissioning graviational
wave detectors (28.01.2013 - 02.02.2013, Lousiana, US).
The files are provided as part of PyKat because they provide a
rich example for using PyKat to automate Finesse simulations.
To run these files you need to have PyKat installed and
the required dependcies (numpy, scipy, matplotlib, pylab).
We recommend to run the files from ipython. To do so,
start ipython and change your system path to include
PyKat, for example:
import sys,os
sys.path.append("/home/work/git/pykat")
The files must be run in sequence starting with 'master.py':
type `run master.py', which should print various result
to screen. It will also save temporary data files which are
needed for running master2.py. Similarly running master2.py
will print further result and save temporary data files.
master3.py and master4.py both read those temporary files
saved by master2. Both files perform longer running simulations.
Some of the data from these simulations is saved regularly to
output files which can be plotted (afterwards, or at the
same time using a second ipython session) with the files
master3_plot.py and master4_plot.py.
Andreas Freise 16.01.2014
#
#-----------------------------------------------------------------------
# ASC_01.kat
# asc_base.kat
#
# This file is an part of the Finesse ASC signal validation.
#
# Checking setup.
# This file is part of a collection for an alignment signal
# validation as reported in the LIGO document:
# `Comparing Finesse simulations, analytical solutions and OSCAR
# simulations of Fabry-Perot alignment signals', LIGO-T1300345
#
# This file is a Finesse input file meant to be read by
# master.py, which is part of PyKat, see
# http://www.gwoptics.org/pykat
# http://www.gwoptics.org/finesse
#
# 01.02.2013, Andreas Freise
# 16.01.2014, Andreas Freise
#----------------------------------------------------------------------
#
#
l psl 1.0 0 npsl /* toll*/ % P=1W input laser
l psl 1.0 0 npsl
mod EOM 9M 0.001 1 pm 0 npsl nEOM1
s s1 0 nEOM1 npo1
......@@ -32,9 +38,5 @@ s spo1 1n nWFS1 nL1_in
lens L1 1250 nL1_in nL1_out
s spo2 5000 nL1_out nWFS2
%const ETM_phi 22.63754342 % on resonance
% now 0.1/1064*360 + 22.63754342 = 22.6713780064662
%const ETM_phi 22.6713780064662 % 1e-10m off resonance
phase 0
#
#-----------------------------------------------------------------------
# asc_base_bs.kat
#
# This file is an part of the Finesse ASC signal validation.
#
# This file is a Finesse input file mean to be read by
# master.py, which is part of PyKat, see
# http://www.gwoptics.org/pykat
# http://www.gwoptics.org/finesse
#
# This file compares to asc_base.kat, but uses beam splitters
# instead of mirrors to build the main cavity.
#
# 16.01.2014, Andreas Freise
#----------------------------------------------------------------------
#
#
l psl 1.0 0 npsl % P=1W input laser
mod EOM 9M 0.001 1 pm 0 npsl nEOM1
s s1 0 nEOM1 npo1
bs1 po 0.5 0 0 45 npo1 dump1 npo2 dump2 % nWFS1 % 50:50 pick-off mirror
s s2 0 npo2 nL1
lens ITM_TL 10000G nL1 nL2 % thermal lens in ITM
s ITMsub 0 nL2 nITM1
bs1 ITM 0.02 0 0 0 nITM1 nITM1r nITM2 nITM2b
attr ITM Rc -2500
s s_cav_a 5000 nITM2 nETM1
s s_cav_b 5000 nITM2b nETM1b
bs1 ETM 0.001 0 0 0 nETM1 nETM1b nETM2a nETM2b
attr ETM Rc 2700
cav c1 ITM nITM2 ITM nITM2b
# the following is a mirror of the input path,
# here being added separately to allow for an
# independent setting of the beam parameter for
# the reflected light
s ITMsub_r 0 nITM1r nL1r
lens ITM_TL_r 10000G nL1r nL2r % thermal lens in ITM
s spo0 1n nL2r npo1r
bs1 por 0.5 0 0 45 npo1r nWFS1 dump3 dump4
s spo1 0 nWFS1 nL1_in
lens L1 1250 nL1_in nL1_out
s spo2 5000 nL1_out nWFS2
phase 0
......@@ -13,14 +13,16 @@ def main():
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The file runs through the various pykat files which are used
The file runs through the various Finesse simulations
to generate the Finesse results reported in the document:
`Comparing Finesse simulations, analytical solutions and OSCAR
simulations of Fabry-Perot alignment signals', LIGO-T1300345
This file is part of a collection; it outputs the results
shown the document's sections 3 and 4 and saves temporary
data and a new Finesse input file to be read by master2.py.
This file is part of a collection.
Andreas Freise 06.12.2013
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
......@@ -91,10 +93,14 @@ def pd_signal(tmpkat):
kat = copy.deepcopy(tmpkat)
code1="yaxis abs"
code1="""
pd cav nITM2
yaxis abs
"""
kat.parseKatCode(code1)
kat.noxaxis = True
out = kat.run(printout=0,printerr=0)
out = kat.run()
print " Cavity power: {0:.6f}W".format(out.y[2])
return (out.y[0], out.y[1])
def pd_phase(tmpkat):
......@@ -111,7 +117,7 @@ def pd_phase(tmpkat):
# function for root finding
def PD_q_test(x):
kat.PDrefl_q.phi[0]=x
out = kat.run(printout=0,printerr=0)
out = kat.run()
print '\r root finding: function value %g ' % out.y,
sys.stdout.flush()
return out.y
......@@ -153,7 +159,7 @@ def powers(tmpkat):
kat.parseKatCode(code1)
out = kat.run(printout=0,printerr=0)
out = kat.run()
code1 = code1.split("\n")
for i in range(len(out.y)):
......@@ -174,7 +180,7 @@ def resonance(tmpkat):
# function for root finding
def carrier_resonance(x):
kat.ETM.phi=x
out = kat.run(printout=0,printerr=0)
out = kat.run()
phase = (out.y[0]-out.y[1]-90)%360-180
print '\r root finding: function value %g ' % phase ,
sys.stdout.flush()
......
......@@ -2,7 +2,7 @@ from pykat import finesse
from pykat.commands import *
import pylab as pl
import scipy
from scipy.optimize import minimize_scalar
from scipy.optimize import fmin
import numpy as np
import shelve
import copy
......@@ -15,15 +15,18 @@ def main():
Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The file runs through the various pykat files which are used
The file runs through the various Finesse simulations
to generate the Finesse results reported in the document:
`Comparing Finesse simulations, analytical solutions and OSCAR
simulations of Fabry-Perot alignment signals', LIGO-T1300345
This file is part of a collection; it outputs the results
shown the document's sections 5 and 6 and saves temporary
data and a new Finesse input file to be read by master3.py,
and master4.py.
This file is part of a collection.
Andreas Freise 06.12.2013
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
......@@ -63,7 +66,7 @@ def main():
tilt(kat)
print "--------------------------------------------------------"
print " 6. compute beam tilt from center of gravity calculation"
print " 6. compute beam tilt from beam propogation"
gravity_tilt(kat)
print "--------------------------------------------------------"
......@@ -144,7 +147,7 @@ def asc_signal(tmpkat):
signal=np.zeros((2, 2))
kat.ITM.ybeta=1e-10
kat.ETM.ybeta=0.0
out = kat.run(printout=0,printerr=0)
out = kat.run()
WFS1_idx=out.ylabels.index("WFS1_I")
WFS2_idx=out.ylabels.index("WFS2_I")
signal[0,0] = out.y[WFS1_idx]
......@@ -152,7 +155,7 @@ def asc_signal(tmpkat):
kat.ITM.ybeta=0.0
kat.ETM.ybeta=-1e-10
out = kat.run(printout=0,printerr=0)
out = kat.run()
signal[0,1] = out.y[WFS1_idx]
signal[1,1] = out.y[WFS2_idx]
signal = signal *1e10
......@@ -175,8 +178,8 @@ def asc_phases(tmpkat):
kat.maxtem=1
def demod_phase1(x):
kat.WFS1_I.phi[0]=x
out = kat.run(printout=0,printerr=0)
kat.WFS1_I.phi[0]=x[0]
out = kat.run()
WFS1_idx=out.ylabels.index("WFS1_I")
signal = out.y[WFS1_idx]
print '\r minimising: function value %g ' % signal ,
......@@ -184,8 +187,8 @@ def asc_phases(tmpkat):
return -1*abs(signal)
def demod_phase2(x):
kat.WFS2_I.phi[0]=x
out = kat.run(printout=0,printerr=0)
kat.WFS2_I.phi[0]=x[0]
out = kat.run()
WFS2_idx=out.ylabels.index("WFS2_I")
signal = out.y[WFS2_idx]
print '\r minimising: function value %g ' % signal ,
......@@ -194,15 +197,15 @@ def asc_phases(tmpkat):
kat.ITM.ybeta=1e-10
kat.ETM.ybeta=0.0
res = minimize_scalar(demod_phase1, method='brent')
WFS1_phase = res.x
res = fmin(demod_phase1, [0.0], xtol=1e-8, disp=False)
WFS1_phase = res[0]
print ""
print " WFS1 demod phase : %.10g deg" % WFS1_phase
kat.ITM.ybeta=0.0
kat.ETM.ybeta=-1e-10
res = minimize_scalar(demod_phase2, method='brent')
WFS2_phase = res.x
res = fmin(demod_phase2, [0.0], xtol=1e-8, disp=False)
WFS2_phase = res[0]
print ""
print " WFS2 demod phase : %.10g deg" % WFS2_phase
return(WFS1_phase, WFS2_phase)
......@@ -212,7 +215,7 @@ def gravity_tilt(tmpkat):
def compute_gravity_tilt(tmpkat):
kat = copy.deepcopy(tmpkat)
out = kat.run(printout=0,printerr=0)
out = kat.run()
y1 = out["b1"]
y2 = out["b1_1k"]
......@@ -259,7 +262,7 @@ def gravity_tilt(tmpkat):
kat.ETM.ybeta=-1e-10
compute_gravity_tilt(kat)
print " WFS1:"
print " WFS2:"
print " ITM ybeta 0.1nm"
kat = copy.deepcopy(tmpkat)
kat.parseKatCode(code_WFS2)
......@@ -279,7 +282,7 @@ def tilt(tmpkat):
def compute_tilt(tmpkat):
kat = copy.deepcopy(tmpkat)
out = kat.run(printout=0,printerr=0)
out = kat.run()
# compute data x range in meters
beamsize = out["w0y"][0,0]
......
......@@ -13,19 +13,17 @@ def main():
Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The file runs through the various pykat files which are used
The file runs through the various Finesse simulations
to generate the Finesse results reported in the document:
`Comparing Finesse simulations, analytical solutions and OSCAR
simulations of Fabry-Perot alignment signals', LIGO-T1300345
This file is part of a collection. Run this after master2.py
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.
Run this file after master2.py to create data which can be
plotted using master3_plot.py. Results are saved after
each step and plots can be created at any time.
Andreas Freise 06.12.2013
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
......@@ -55,13 +53,20 @@ def main():
print "--------------------------------------------------------"
print " 9. ASC signals for large misalignments (ITM)"
asc_large(kat)
asc_large(kat, 'ITM')
print "--------------------------------------------------------"
print " 10. ASC signals for large misalignments (ETM)"
asc_large(kat, 'ETM')
#-----------------------------------------------------------------------------------
def asc_large(tmpkat):
def asc_large(tmpkat, mir_name):
kat = copy.deepcopy(tmpkat)
assert(mir_name == 'ITM' or mir_name == 'ETM')
code_lock = """
set err PDrefl_p re
lock z $err 900 1p
......@@ -71,20 +76,20 @@ def asc_large(tmpkat):
kat.parseKatCode(code_lock)
kat.parseKatCode('yaxis abs')
kat.parseKatCode('xaxis ITM ybeta lin 0 1u 100')
kat.parseKatCode('xaxis {0} ybeta lin 0 1u 100'.format(mir_name))
maxtems = [1, 3, 5]
#kat.verbose=1
xscale = 1e6
yscale = 1e6
global out
tmpfilename = "datashelf1.dat"
backupname = "datashelf1.dat.bck"
tmpfilename = "datashelf_{0}.dat".format(mir_name)
backupname = "datashelf_{0}.dat.bck".format(mir_name)
out={}
done_maxtems = []
for tem in maxtems:
done_maxtems.append(tem)
print " Calculating maxtem = %d " % tem
print " Calculating maxtem = %d " % tem
kat.maxtem = tem
out[str(tem)] = kat.run(printout=0,printerr=1)
import os.path
......
......@@ -10,8 +10,8 @@ formatter = matplotlib.ticker.EngFormatter(unit='', places=0)
formatter.ENG_PREFIXES[-6] = 'u'
import matplotlib.backends.backend_pdf
def printPDF(self):
pdfp = matplotlib.backends.backend_pdf.PdfPages('large_ITM.pdf')
def printPDF(self, filename):
pdfp = matplotlib.backends.backend_pdf.PdfPages(filename)
pdfp.savefig(self,dpi=300,bbox_inches='tight')
pdfp.close()
......@@ -21,15 +21,10 @@ def main():
Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/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
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
......@@ -44,15 +39,21 @@ def main():
#global result
print "--------------------------------------------------------"
print " 9. Plotting ASC signals for large misalignments"
asc_large()
print " Plotting ASC signals for large misalignments"
asc_large('ITM')
asc_large('ETM')
def asc_large():
def asc_large(mir_name):
xscale = 1e6
yscale = 1e6
tmpfilename = "datashelf1.dat"
backupname = "datashelf1.dat.bck"
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)
try:
tmpfile = shelve.open(tmpfilename)
......@@ -67,33 +68,37 @@ def asc_large():
lw=np.ones(N)*3
lw[-2]=2
lw[-1]=1
for i, tem in zip(range(len(maxtems)), maxtems):
for i, tem in enumerate(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])
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])
#line.set_dashes([12, 4])
osc1=np.loadtxt("OSCAR_large_tilt_ITM.txt",comments='%')
osc1=np.loadtxt("OSCAR_large_tilt_{0}.txt".format(mir_name),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 vertical misalignment [urad]")
pl.xlabel("{0} vertical misalignment [urad]".format(mir_name))
pl.ylabel("Alignment signal [uW]")
pl.annotate('WFS1',xy=[0.42,70])
pl.annotate('WFS2',xy=[0.62,5])
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)
pl.xlim([0,1])
pl.legend(loc=2)
pl.grid()
pl.draw()
pl.show(block=0)
printPDF(fig)
printPDF(fig, "large_{0}.pdf".format(mir_name))
if __name__ == '__main__':
main()
from pykat import finesse
from pykat.commands import *
from pykat.utilities.optics.gaussian_beams import gauss_param
import pylab as pl
import scipy
from scipy.optimize import minimize_scalar
import numpy as np
import shelve
import copy
import sys
import shutil
def set_thermal_lens(kat, f):
kat.ITM_TL.f=f
# if a bs-based cavity is used, we need to set second lens
if "ITM_TL_r" in kat._kat__components:
kat.ITM_TL_r.f=f
return (kat)
def main():
print """
--------------------------------------------------------------
Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The file runs through the various pykat files which are used
PyKat: https://pypi.python.org/pypi/PyKat/
The file runs through the various Finesse simulations
to generate the Finesse results reported in the document:
`Comparing Finesse simulations, analytical solutions and OSCAR
simulations of Fabry-Perot alignment signals', LIGO-T1300345
This file is part of a collection. Run this after master2.py
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
Run this file after master2.py to create data which can be
plotted using master4_plot.py. Results are saved after
each step and plots can be created at any time.
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
......@@ -35,10 +44,10 @@ def main():
# 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
......@@ -49,16 +58,184 @@ def main():
tmpfile.close()
except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile))
# this does not work yet due to the scale command
kat.PDrefl_p.enabled = False
kat.PDrefl_q.enabled = False
kat.WFS1_Q.enables = False
kat.WFS2_Q.enables = False
kat.WFS1_I.enabled = False
kat.WFS1_Q.enabled = False
kat.WFS2_I.enabled = False
kat.WFS2_Q.enabled = False
kat.ETM.phi=result['phi_tuned']
print "--------------------------------------------------------"
print " 11. Do beam tracing to measure beam parameters"
# get beam parameters at nodes: "npsl", "nITM1", "nWFS1", "nWFS2", "npo2"
beam1 = get_qs(kat,1e13)
beam2 = get_qs(kat,50e3)
beam3 = get_qs(kat,5e3)
# starting with cold beam at npsl
kat.psl.npsl.node.setGauss(kat.psl, beam1[0])
kat.parseKatCode("startnode npsl")
global beam1, beam2, beam3
# if we use bs-based cavity we try to set good beam
# parameter for reflected beam, first by
# computing 'average' beam from cold and hot beams
x1=0.70
x2=0.30
if "ITM_TL_r" in kat._kat__components:
beam50 = gauss_param(z=(x1*beam1[1].z+x2*beam2[1].z), w0=(x1*beam1[1].w0+x2*beam2[1].w0))
beam5 = gauss_param(z=(x1*beam1[1].z+x2*beam3[1].z), w0=(x1*beam1[1].w0+x2*beam3[1].w0))
node_text = "at ITM->nITM1r"
t_comp=kat.ITM
t_node=kat.ITM.nITM1r
else:
beam50 = gauss_param(z=(x1*beam1[4].z+x2*beam2[4].z), w0=(x1*beam1[4].w0+x2*beam2[4].w0))
beam5 = gauss_param(z=(x1*beam1[4].z+x2*beam3[4].z), w0=(x1*beam1[4].w0+x2*beam3[4].w0))
node_text = "at s2->npo2"
t_comp=kat.s2
t_node=kat.s2.npo2
kat = set_thermal_lens(kat,50e3)
print "--------------------------------------------------------"
print " 10. ASC signals for large misalignments (ETM)"
asc_large(kat)
print " 12. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f)