Skip to content
Snippets Groups Projects
Commit 722df66e authored by Andreas Freise's avatar Andreas Freise
Browse files

converting master.py

parent 897c2f39
Branches
Tags
No related merge requests found
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 import finesse
from pykat.commands import * from pykat.commands import *
import copy import copy
...@@ -7,7 +12,7 @@ import scipy.optimize ...@@ -7,7 +12,7 @@ import scipy.optimize
def main(): def main():
print """ print("""
-------------------------------------------------------------- --------------------------------------------------------------
Example file for using PyKat to automate Finesse simulations Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse Finesse: http://www.gwoptics.org/finesse
...@@ -25,7 +30,7 @@ def main(): ...@@ -25,7 +30,7 @@ def main():
Andreas Freise 16.01.2014 Andreas Freise 16.01.2014
-------------------------------------------------------------- --------------------------------------------------------------
""" """)
# for debugging we might need to see the temporay file: # for debugging we might need to see the temporay file:
kat = finesse.kat(tempdir=".",tempname="test") kat = finesse.kat(tempdir=".",tempname="test")
...@@ -40,16 +45,16 @@ def main(): ...@@ -40,16 +45,16 @@ def main():
#global out #global out
#global result #global result
print "--------------------------------------------------------" print("--------------------------------------------------------")
print " 1. tunes ETM position to find resonance" print(" 1. tunes ETM position to find resonance")
kat.ETM.phi=resonance(kat) kat.ETM.phi=resonance(kat)
print "--------------------------------------------------------" print("--------------------------------------------------------")
print " 2. print sideband and carrier powers/amplitudes" print(" 2. print sideband and carrier powers/amplitudes")
powers(kat) powers(kat)
print "--------------------------------------------------------" print("--------------------------------------------------------")
print " 3. determine the optimal phase for the PDH signal" print(" 3. determine the optimal phase for the PDH signal")
(result['p_phase'], result['q_phase']) = pd_phase(kat) (result['p_phase'], result['q_phase']) = pd_phase(kat)
# setting demodulation phase # setting demodulation phase
...@@ -63,24 +68,24 @@ def main(): ...@@ -63,24 +68,24 @@ def main():
kat.PDrefl_p.phi1=result['p_phase'] kat.PDrefl_p.phi1=result['p_phase']
kat.PDrefl_q.phi1=result['q_phase'] kat.PDrefl_q.phi1=result['q_phase']
print "--------------------------------------------------------" print("--------------------------------------------------------")
print " 4. adding a 0.1nm offset to ETM and compute PDH signal" print(" 4. adding a 0.1nm offset to ETM and compute PDH signal")
result['phi_tuned']=float(kat.ETM.phi) result['phi_tuned']=float(kat.ETM.phi)
result['phi_detuned'] = result['phi_tuned'] + 0.1/1064.0*360 result['phi_detuned'] = result['phi_tuned'] + 0.1/1064.0*360
kat.ETM.phi=result['phi_detuned'] kat.ETM.phi=result['phi_detuned']
print " new ETM phi tuning = %g " % kat.ETM.phi print(" new ETM phi tuning = %g " % kat.ETM.phi)
(result['pd_p'], result['pd_q']) = pd_signal(kat) (result['pd_p'], result['pd_q']) = pd_signal(kat)
print " PDH inphase = %e " % result['pd_p'] print(" PDH inphase = %e " % result['pd_p'])
print " PDH quadrtature = %e " % result['pd_q'] print(" PDH quadrtature = %e " % result['pd_q'])
print "--------------------------------------------------------" print("--------------------------------------------------------")
print " Saving results in temp. files to be read by master2.py" print(" Saving results in temp. files to be read by master2.py")
tmpkatfile = "asc_base2.kat" tmpkatfile = "asc_base2.kat"
tmpresultfile = "myshelf1.dat" tmpresultfile = "myshelf1.dat"
print " kat object saved in: {0}".format(tmpkatfile) print(" kat object saved in: {0}".format(tmpkatfile))
print " current results saved in: {0}".format(tmpresultfile) print(" current results saved in: {0}".format(tmpresultfile))
# first the current kat file # first the current kat file
kat.saveScript(tmpkatfile) kat.saveScript(tmpkatfile)
# now the result variables: # now the result variables:
...@@ -100,9 +105,10 @@ def pd_signal(tmpkat): ...@@ -100,9 +105,10 @@ def pd_signal(tmpkat):
""" """
kat.parseKatCode(code1) kat.parseKatCode(code1)
kat.noxaxis = True kat.noxaxis = True
global out
out = kat.run() out = kat.run()
print " Cavity power: {0:.6f}W".format(out.y[2]) print(" Cavity power: {0:.6f}W".format(out.y[2]))
return (out.y[0], out.y[1]) return (out.y[0,0], out.y[0,11])
def pd_phase(tmpkat): def pd_phase(tmpkat):
...@@ -119,7 +125,7 @@ def pd_phase(tmpkat): ...@@ -119,7 +125,7 @@ def pd_phase(tmpkat):
def PD_q_test(x): def PD_q_test(x):
kat.PDrefl_q.phi1=x kat.PDrefl_q.phi1=x
out = kat.run() out = kat.run()
print '\r root finding: function value %g ' % out.y, print('\r root finding: function value %g ' % out.y, end=' ')
sys.stdout.flush() sys.stdout.flush()
return out.y return out.y
...@@ -127,14 +133,14 @@ def pd_phase(tmpkat): ...@@ -127,14 +133,14 @@ def pd_phase(tmpkat):
xtol=1e-8 xtol=1e-8
(result, info)=scipy.optimize.bisect(PD_q_test,80.0,100.0, xtol=xtol, maxiter=500, full_output=True) (result, info)=scipy.optimize.bisect(PD_q_test,80.0,100.0, xtol=xtol, maxiter=500, full_output=True)
print "" print("")
if info.converged: if info.converged:
p_phase=result-90.0 p_phase=result-90.0
q_phase=result q_phase=result
print " Root has been found:" print(" Root has been found:")
print " p_phase %8f" % (p_phase) print(" p_phase %8f" % (p_phase))
print " q_phase %8f" % (q_phase) print(" q_phase %8f" % (q_phase))
print " (%d iterations, %g tolerance)" % (info.iterations, xtol) print(" (%d iterations, %g tolerance)" % (info.iterations, xtol))
return (p_phase, q_phase) return (p_phase, q_phase)
else: else:
raise Exception("Root has not been found") raise Exception("Root has not been found")
...@@ -164,7 +170,7 @@ def powers(tmpkat): ...@@ -164,7 +170,7 @@ def powers(tmpkat):
code1 = code1.split("\n") code1 = code1.split("\n")
for i in range(len(out.y)): for i in range(len(out.y)):
print " %8s: %.4e" % (out.ylabels[i], out.y[i]) print(" %8s: %.4e" % (out.ylabels[i], out.y[0,i]))
def resonance(tmpkat): def resonance(tmpkat):
...@@ -181,9 +187,10 @@ def resonance(tmpkat): ...@@ -181,9 +187,10 @@ def resonance(tmpkat):
# function for root finding # function for root finding
def carrier_resonance(x): def carrier_resonance(x):
kat.ETM.phi=x kat.ETM.phi=x
global out
out = kat.run() out = kat.run()
phase = (out.y[0]-out.y[1]-90)%360-180 phase = (out.y[0,0]-out.y[0,1]-90)%360-180
print '\r root finding: function value %g ' % phase , print('\r root finding: function value %g ' % phase, end=' ')
sys.stdout.flush() sys.stdout.flush()
return phase return phase
...@@ -191,11 +198,11 @@ def resonance(tmpkat): ...@@ -191,11 +198,11 @@ def resonance(tmpkat):
xtol=1e-8 xtol=1e-8
(result, info)=scipy.optimize.bisect(carrier_resonance,0.0,40.0, xtol=xtol, maxiter=500, full_output=True) (result, info)=scipy.optimize.bisect(carrier_resonance,0.0,40.0, xtol=xtol, maxiter=500, full_output=True)
print "" print("")
if info.converged: if info.converged:
print " Root has been found:" print(" Root has been found:")
print " ETM phi %8f" % (result) print(" ETM phi %8f" % (result))
print " (%d iterations, %g tolerance)" % (info.iterations, xtol) print(" (%d iterations, %g tolerance)" % (info.iterations, xtol))
return result return result
else: else:
raise Exception(" Root has not been found") raise Exception(" Root has not been found")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment