Commit 85254c16 authored by Andreas Freise's avatar Andreas Freise
Browse files

merging p23 into master

parents 01841b0f a8866232
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pykat import finesse
from pykat.commands import *
import copy
......@@ -7,87 +12,87 @@ import scipy.optimize
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 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,
freely available online: http://arxiv.org/abs/1401.5727
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.
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
# for debugging we might need to see the temporay file:
kat = finesse.kat(tempdir=".",tempname="test")
kat.verbose = False
kat.loadKatFile('asc_base.kat')
kat.maxtem=3
Lambda=1064.0e-9
result = {}
# defining variables as global for debugging
#global kat
#global out
#global result
print "--------------------------------------------------------"
print " 1. tunes ETM position to find resonance"
kat.ETM.phi=resonance(kat)
print "--------------------------------------------------------"
print " 2. print sideband and carrier powers/amplitudes"
powers(kat)
print "--------------------------------------------------------"
print " 3. determine the optimal phase for the PDH signal"
(result['p_phase'], result['q_phase']) = pd_phase(kat)
# setting demodulation phase
code_det = """
pd1 PDrefl_p 9M 0 nWFS1
scale 2 PDrefl_p
pd1 PDrefl_q 9M 90 nWFS1
scale 2 PDrefl_q
"""
kat.parseKatCode(code_det)
kat.PDrefl_p.phi1=result['p_phase']
kat.PDrefl_q.phi1=result['q_phase']
print "--------------------------------------------------------"
print " 4. adding a 0.1nm offset to ETM and compute PDH signal"
result['phi_tuned']=float(kat.ETM.phi)
result['phi_detuned'] = result['phi_tuned'] + 0.1/1064.0*360
kat.ETM.phi=result['phi_detuned']
print " new ETM phi tuning = %g " % kat.ETM.phi
(result['pd_p'], result['pd_q']) = pd_signal(kat)
print " PDH inphase = %e " % result['pd_p']
print " PDH quadrtature = %e " % result['pd_q']
print "--------------------------------------------------------"
print " Saving results in temp. files to be read by master2.py"
tmpkatfile = "asc_base2.kat"
tmpresultfile = "myshelf1.dat"
print " kat object saved in: {0}".format(tmpkatfile)
print " current results saved in: {0}".format(tmpresultfile)
# first the current kat file
kat.saveScript(tmpkatfile)
# now the result variables:
tmpfile = shelve.open(tmpresultfile)
tmpfile['result']=result
tmpfile.close()
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 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,
freely available online: http://arxiv.org/abs/1401.5727
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.
Andreas Freise 16.01.2014
--------------------------------------------------------------
""")
# for debugging we might need to see the temporay file:
kat = finesse.kat(tempdir=".",tempname="test")
kat.verbose = False
kat.loadKatFile('asc_base.kat')
kat.maxtem=3
Lambda=1064.0e-9
result = {}
# defining variables as global for debugging
#global kat
#global out
#global result
print("--------------------------------------------------------")
print(" 1. tunes ETM position to find resonance")
kat.ETM.phi=resonance(kat)
print("--------------------------------------------------------")
print(" 2. print sideband and carrier powers/amplitudes")
powers(kat)
print("--------------------------------------------------------")
print(" 3. determine the optimal phase for the PDH signal")
(result['p_phase'], result['q_phase']) = pd_phase(kat)
# setting demodulation phase
code_det = """
pd1 PDrefl_p 9M 0 nWFS1
scale 2 PDrefl_p
pd1 PDrefl_q 9M 90 nWFS1
scale 2 PDrefl_q
"""
kat.parseKatCode(code_det)
kat.PDrefl_p.phi1=result['p_phase']
kat.PDrefl_q.phi1=result['q_phase']
print("--------------------------------------------------------")
print(" 4. adding a 0.1nm offset to ETM and compute PDH signal")
result['phi_tuned']=float(kat.ETM.phi)
result['phi_detuned'] = result['phi_tuned'] + 0.1/1064.0*360
kat.ETM.phi=result['phi_detuned']
print(" new ETM phi tuning = %g " % kat.ETM.phi)
(result['pd_p'], result['pd_q']) = pd_signal(kat)
print(" PDH inphase = %e " % result['pd_p'])
print(" PDH quadrtature = %e " % result['pd_q'])
print("--------------------------------------------------------")
print(" Saving results in temp. files to be read by master2.py")
tmpkatfile = "asc_base2.kat"
tmpresultfile = "myshelf1.dat"
print(" kat object saved in: {0}".format(tmpkatfile))
print(" current results saved in: {0}".format(tmpresultfile))
# first the current kat file
kat.saveScript(tmpkatfile)
# now the result variables:
tmpfile = shelve.open(tmpresultfile, flag="c")
tmpfile[str('result')]=result
tmpfile.close()
#---------------------------------------------------------------------------
def pd_signal(tmpkat):
......@@ -102,106 +107,108 @@ def pd_signal(tmpkat):
kat.noxaxis = True
#global out
out = kat.run()
print " Cavity power: {0:.6f}W".format(out.y[0,2])
print(" Cavity power: {0:.6f}W".format(out.y[0,2]))
return (out.y[0,0], out.y[0,1])
def pd_phase(tmpkat):
kat = copy.deepcopy(tmpkat)
code_det = """
pd1 PDrefl_q 9M 90 nWFS1
"""
kat.parseKatCode(code_det)
kat.noxaxis= True
# function for root finding
def PD_q_test(x):
kat.PDrefl_q.phi1=x
out = kat.run()
print '\r root finding: function value %g ' % out.y,
sys.stdout.flush()
return out.y
# do root finding
xtol=1e-8
(result, info)=scipy.optimize.bisect(PD_q_test,80.0,100.0, xtol=xtol, maxiter=500, full_output=True)
print ""
if info.converged:
p_phase=result-90.0
q_phase=result
print " Root has been found:"
print " p_phase %8f" % (p_phase)
print " q_phase %8f" % (q_phase)
print " (%d iterations, %g tolerance)" % (info.iterations, xtol)
return (p_phase, q_phase)
else:
raise Exception("Root has not been found")
kat = copy.deepcopy(tmpkat)
code_det = """
pd1 PDrefl_q 9M 90 nWFS1
"""
kat.parseKatCode(code_det)
kat.noxaxis= True
# function for root finding
def PD_q_test(x):
kat.PDrefl_q.phi1=x
out = kat.run()
print('\r root finding: function value %g ' % out.y, end=' ')
sys.stdout.flush()
return out.y
# do root finding
xtol=1e-8
(result, info)=scipy.optimize.bisect(PD_q_test,80.0,100.0, xtol=xtol, maxiter=500, full_output=True)
print("")
if info.converged:
p_phase=result-90.0
q_phase=result
print(" Root has been found:")
print(" p_phase %8f" % (p_phase))
print(" q_phase %8f" % (q_phase))
print(" (%d iterations, %g tolerance)" % (info.iterations, xtol))
return (p_phase, q_phase)
else:
raise Exception("Root has not been found")
def powers(tmpkat):
kat = copy.deepcopy(tmpkat)
code1 = """
ad EOM_up 9M nEOM1
ad EOM_low -9M nEOM1
pd cav_pow nITM2
ad cav_c 0 nITM2
ad WFS1_u 9M nWFS1
ad WFS1_l -9M nWFS1
ad WFS1_c 0 nWFS1
ad WFS2_u 9M nWFS2
ad WFS2_l -9M nWFS2
ad WFS2_c 0 nWFS2
noxaxis
"""
kat = copy.deepcopy(tmpkat)
code1 = """
ad EOM_up 9M nEOM1
ad EOM_low -9M nEOM1
pd cav_pow nITM2
ad cav_c 0 nITM2
ad WFS1_u 9M nWFS1
ad WFS1_l -9M nWFS1
ad WFS1_c 0 nWFS1
ad WFS2_u 9M nWFS2
ad WFS2_l -9M nWFS2
ad WFS2_c 0 nWFS2
noxaxis
"""
kat.parseKatCode(code1)
kat.parseKatCode(code1)
out = kat.run()
global out
out = kat.run()
code1 = code1.split("\n")
for i in range(len(out.y)):
print(" %8s: %.4e" % (out.ylabels[i], out.y[0,i]))
code1 = code1.split("\n")
for i in range(len(out.y)):
print " %8s: %.4e" % (out.ylabels[i], out.y[0,i])
def resonance(tmpkat):
kat = copy.deepcopy(tmpkat)
code1 = """
ad carr2 0 nITM1*
ad carr3 0 nITM2
yaxis deg
"""
kat.parseKatCode(code1)
kat.noxaxis = True
# function for root finding
def carrier_resonance(x):
kat.ETM.phi=x
out = kat.run()
phase = (out.y[0,0]-out.y[0,1]-90)%360-180
print '\r root finding: function value %g ' % phase ,
sys.stdout.flush()
return phase
# do root finding
xtol=1e-8
(result, info)=scipy.optimize.bisect(carrier_resonance,0.0,40.0, xtol=xtol, maxiter=500, full_output=True)
print ""
if info.converged:
print " Root has been found:"
print " ETM phi %8f" % (result)
print " (%d iterations, %g tolerance)" % (info.iterations, xtol)
return result
else:
raise Exception(" Root has not been found")
kat = copy.deepcopy(tmpkat)
code1 = """
ad carr2 0 nITM1*
ad carr3 0 nITM2
yaxis deg
"""
kat.parseKatCode(code1)
kat.noxaxis = True
# function for root finding
def carrier_resonance(x):
kat.ETM.phi=x
global out
out = kat.run()
phase = (out.y[0,0]-out.y[0,1]-90)%360-180
print('\r root finding: function value %g ' % phase, end=' ')
sys.stdout.flush()
return phase
# do root finding
xtol=1e-8
(result, info)=scipy.optimize.bisect(carrier_resonance,0.0,40.0, xtol=xtol, maxiter=500, full_output=True)
print("")
if info.converged:
print(" Root has been found:")
print(" ETM phi %8f" % (result))
print(" (%d iterations, %g tolerance)" % (info.iterations, xtol))
return result
else:
raise Exception(" Root has not been found")
if __name__ == '__main__':
main()
main()
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pykat import finesse
from pykat.commands import *
import pylab as pl
......@@ -10,343 +15,344 @@ import sys
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 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,
freely available online: http://arxiv.org/abs/1401.5727
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.
Andreas Freise 16.01.2014
--------------------------------------------------------------
"""
# 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 = 'myshelf1.dat'
# loading data saved by master.py
kat.loadKatFile('asc_base2.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
# disable PDH photo diode as we won't need it for most of this
kat.PDrefl_p.enabled = False
kat.PDrefl_q.enabled = False
# simulating a tuned cavity
kat.ETM.phi=result['phi_tuned']
print "--------------------------------------------------------"
print " 5. checking wavefronts for ITM/ETM tilt of 0.1nrad"
tilt(kat)
print "--------------------------------------------------------"
print " 6. compute beam tilt from beam propogation"
gravity_tilt(kat)
print "--------------------------------------------------------"
print " 7. compute optimal demodulation phase of WFS1 and WFS2"
# adding wave front sensors to global kat object, will need them later
# on as well.
code_WFS1 = """
pd1 WFS1_I 9M 0 nWFS1
pdtype WFS1_I y-split
pd1 WFS1_Q 9M 90 nWFS1
pdtype WFS1_Q y-split
scale 2 WFS1_I % compensate the 0.5 gain of the demodulation
scale 2 WFS1_Q % compensate the 0.5 gain of the demodulation
"""
code_WFS2 = """
pd1 WFS2_I 9M 0 nWFS2
pdtype WFS2_I y-split
pd1 WFS2_Q 9M 90 nWFS2
pdtype WFS2_Q y-split
scale 2 WFS2_I % compensate the 0.5 gain of the demodulation
scale 2 WFS2_Q % compensate the 0.5 gain of the demodulation
"""
kat.parseKatCode(code_WFS1)
kat.parseKatCode(code_WFS2)
(WFS1_phase, WFS2_phase) = asc_phases(kat)
kat.WFS1_I.phi1=WFS1_phase
kat.WFS1_Q.phi1=WFS1_phase+90.0
kat.WFS2_I.phi1=WFS2_phase
kat.WFS2_Q.phi1=WFS2_phase+90.0
result['WFS1_phase']=WFS1_phase
result['WFS2_phase']=WFS2_phase
print "--------------------------------------------------------"
print " 8. compute ASC signal matrix at WFS1 and WFS2"
signal = asc_signal(kat)
print "--------------------------------------------------------"
print " Saving results in temp. files to be read by master3.py"
# re-enable PDH photo diode for savinf
kat.PDrefl_p.enabled = True
kat.PDrefl_q.enabled = True
tmpkatfile = "asc_base3.kat"
tmpresultfile = "myshelf2.dat"
print " kat object saved in: {0}".format(tmpkatfile)
print " current results saved in: {0}".format(tmpresultfile)
# first the current kat file
kat.saveScript(tmpkatfile)
# now the result variables:
tmpfile = shelve.open(tmpresultfile)
tmpfile['result']=result
tmpfile.close()
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 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,
freely available online: http://arxiv.org/abs/1401.5727
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.
Andreas Freise 16.01.2014
--------------------------------------------------------------
""")
# 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 = "myshelf1.dat"
# loading data saved by master.py
kat.loadKatFile('asc_base2.kat')
try:
tmpfile = shelve.open(tmpresultfile, flag="c")
result=tmpfile[str('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
# disable PDH photo diode as we won't need it for most of this
kat.PDrefl_p.enabled = False
kat.PDrefl_q.enabled = False
# simulating a tuned cavity
kat.ETM.phi=result['phi_tuned']
print("--------------------------------------------------------")
print(" 5. checking wavefronts for ITM/ETM tilt of 0.1nrad")
tilt(kat)
print("--------------------------------------------------------")
print(" 6. compute beam tilt from beam propogation")
gravity_tilt(kat)
print("--------------------------------------------------------")
print(" 7. compute optimal demodulation phase of WFS1 and WFS2")
# adding wave front sensors to global kat object, will need them later
# on as well.
code_WFS1 = """
pd1 WFS1_I 9M 0 nWFS1
pdtype WFS1_I y-split
pd1 WFS1_Q 9M 90 nWFS1
pdtype WFS1_Q y-split
scale 2 WFS1_I % compensate the 0.5 gain of the demodulation
scale 2 WFS1_Q % compensate the 0.5 gain of the demodulation
"""
code_WFS2 = """
pd1 WFS2_I 9M 0 nWFS2
pdtype WFS2_I y-split
pd1 WFS2_Q 9M 90 nWFS2
pdtype WFS2_Q y-split
scale 2 WFS2_I % compensate the 0.5 gain of the demodulation
scale 2 WFS2_Q % compensate the 0.5 gain of the demodulation
"""
kat.parseKatCode(code_WFS1)
kat.parseKatCode(code_WFS2)
(WFS1_phase, WFS2_phase) = asc_phases(kat)
kat.WFS1_I.phi1=WFS1_phase
kat.WFS1_Q.phi1=WFS1_phase+90.0
kat.WFS2_I.phi1=WFS2_phase
kat.WFS2_Q.phi1=WFS2_phase+90.0
result['WFS1_phase']=WFS1_phase
result['WFS2_phase']=WFS2_phase
print("--------------------------------------------------------")
print(" 8. compute ASC signal matrix at WFS1 and WFS2")
signal = asc_signal(kat)
print("--------------------------------------------------------")
print(" Saving results in temp. files to be read by master3.py")