diff --git a/examples/asc_test/master.py b/examples/asc_test/master.py index 563965da1b8f0582ef0ed1f116bb6264eaaa999e..d6d492a343916bd974230f83114b03d3e0fe7e25 100644 --- a/examples/asc_test/master.py +++ b/examples/asc_test/master.py @@ -77,7 +77,7 @@ def main(): 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 inphase = %e " % result['pd_p']) print(" PDH quadrtature = %e " % result['pd_q']) print("--------------------------------------------------------") @@ -90,7 +90,7 @@ def main(): kat.saveScript(tmpkatfile) # now the result variables: tmpfile = shelve.open(tmpresultfile) - tmpfile['result']=result + tmpfile[b'result']=result tmpfile.close() #--------------------------------------------------------------------------- @@ -107,7 +107,7 @@ 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): @@ -166,12 +166,13 @@ def powers(tmpkat): kat.parseKatCode(code1) + 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])) - + def resonance(tmpkat): kat = copy.deepcopy(tmpkat) diff --git a/examples/asc_test/master1.py b/examples/asc_test/master1.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/asc_test/master1py b/examples/asc_test/master1py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/asc_test/master2.py b/examples/asc_test/master2.py index ec4fb5e7e730b822e2eba38a3aa1b5d11346c39c..2ba952da658257e4782761d4354e9cb79817e7e6 100644 --- a/examples/asc_test/master2.py +++ b/examples/asc_test/master2.py @@ -1,3 +1,8 @@ +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,345 @@ 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) + result=tmpfile[b'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[b'result']=result + 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) - # need to re-enable the photo diode for lock - kat.PDrefl_p.enabled = True - - 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() - signal[0,0] = out["WFS1_I"] - signal[1,0] = out["WFS2_I"] - - - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - out = kat.run() - signal[0,1] = out["WFS1_I"] - signal[1,1] = out["WFS2_I"] - 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 - - + 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) + # need to re-enable the photo diode for lock + kat.PDrefl_p.enabled = True + + 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() + signal[0,0] = out["WFS1_I"] + signal[1,0] = out["WFS2_I"] + + + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + out = kat.run() + signal[0,1] = out["WFS1_I"] + signal[1,1] = out["WFS2_I"] + signal = signal *1e10 + sensors=('WFS1', 'WFS2') + mirrors=('ITM', 'ETM') + print(" ASC Matrix:") + for i in range(2): + print(" ", sensors[i], " ", end=' ') + for j in range(2): + print("%12.10g" % signal[i,j], end=' ') + print(mirrors[i]) + return signal + + def asc_phases(tmpkat): - kat = copy.deepcopy(tmpkat) - - kat.parseKatCode('yaxis abs') - kat.noxaxis = True - kat.maxtem=1 - - def demod_phase1(x): - kat.WFS1_I.phi1=x[0] - out = kat.run() - signal = out["WFS1_I"] - print '\r minimising: function value %g ' % signal , - sys.stdout.flush() - return -1*abs(signal) - - def demod_phase2(x): - kat.WFS2_I.phi1=x[0] - out = kat.run() - signal = out["WFS2_I"] - print '\r minimising: function value %g ' % signal , - sys.stdout.flush() - return -1*abs(signal) - - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - 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 = 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) - + kat = copy.deepcopy(tmpkat) + + kat.parseKatCode('yaxis abs') + kat.noxaxis = True + kat.maxtem=1 + + def demod_phase1(x): + kat.WFS1_I.phi1=x[0] + out = kat.run() + signal = out["WFS1_I"] + print('\r minimising: function value %g ' % signal, end=' ') + sys.stdout.flush() + return -1*abs(signal) + + def demod_phase2(x): + kat.WFS2_I.phi1=x[0] + out = kat.run() + signal = out["WFS2_I"] + print('\r minimising: function value %g ' % signal, end=' ') + sys.stdout.flush() + return -1*abs(signal) + + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + 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 = 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) + def gravity_tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - - def compute_gravity_tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - out = kat.run() - - y1 = out["b1"] - y2 = out["b1_1k"] - # shift of beam center on detector 1 (as m/w0y) - x1 = np.sum(out.x*y1)/np.sum(y1) - # shift of beam center on detector 2 (as m/w0y) - x2 = np.sum(out.x*y2)/np.sum(y2) - # calibrate this in meter by mutliplying with w0y - # and compute the angle geometrically - w0=out["w0y"][0] - detector_distance = 1000.0 - tilt=w0*(x2-x1)/detector_distance - print " Wavefront tilt : %g nrad" % tilt - - code_WFS1 = """ - beam b1 nWFS1 - beam b1_1k nL1_in - bp w0y y w0 nWFS1 - """ - - code_WFS2 = """ - m md 0 1 0 nWFS2 nWFS2b - s sd 1k nWFS2b nWFS2c - beam b1 nWFS2* - beam b1_1k nWFS2c - bp w0y y w0 nWFS2 - """ - - code_xaxis= """ - xaxis b1 y lin -40 40 800 - put b1_1k y $x1 - yaxis abs - """ - print " WFS1:" - print " ITM ybeta 0.1nm" - kat.parseKatCode(code_WFS1) - kat.parseKatCode(code_xaxis) - kat.spo1.L=1000.0 - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - compute_gravity_tilt(kat) - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - compute_gravity_tilt(kat) - - print " WFS2:" - print " ITM ybeta 0.1nm" - kat = copy.deepcopy(tmpkat) - kat.parseKatCode(code_WFS2) - kat.parseKatCode(code_xaxis) - kat.spo1.L=1.0e-9 - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - compute_gravity_tilt(kat) - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - compute_gravity_tilt(kat) - - + kat = copy.deepcopy(tmpkat) + + def compute_gravity_tilt(tmpkat): + kat = copy.deepcopy(tmpkat) + out = kat.run() + + y1 = out["b1"] + y2 = out["b1_1k"] + # shift of beam center on detector 1 (as m/w0y) + x1 = np.sum(out.x*y1)/np.sum(y1) + # shift of beam center on detector 2 (as m/w0y) + x2 = np.sum(out.x*y2)/np.sum(y2) + # calibrate this in meter by mutliplying with w0y + # and compute the angle geometrically + w0=out["w0y"][0] + detector_distance = 1000.0 + tilt=w0*(x2-x1)/detector_distance + print(" Wavefront tilt : %g nrad" % tilt) + + code_WFS1 = """ + beam b1 nWFS1 + beam b1_1k nL1_in + bp w0y y w0 nWFS1 + """ + + code_WFS2 = """ + m md 0 1 0 nWFS2 nWFS2b + s sd 1k nWFS2b nWFS2c + beam b1 nWFS2* + beam b1_1k nWFS2c + bp w0y y w0 nWFS2 + """ + + code_xaxis= """ + xaxis b1 y lin -40 40 800 + put b1_1k y $x1 + yaxis abs + """ + print(" WFS1:") + print(" ITM ybeta 0.1nm") + kat.parseKatCode(code_WFS1) + kat.parseKatCode(code_xaxis) + kat.spo1.L=1000.0 + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + compute_gravity_tilt(kat) + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + compute_gravity_tilt(kat) + + print(" WFS2:") + print(" ITM ybeta 0.1nm") + kat = copy.deepcopy(tmpkat) + kat.parseKatCode(code_WFS2) + kat.parseKatCode(code_xaxis) + kat.spo1.L=1.0e-9 + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + compute_gravity_tilt(kat) + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + compute_gravity_tilt(kat) + + def tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - - def compute_tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - global out - out = kat.run() - - # compute data x range in meters - beamsize = out["w0y"][0] - xrange = beamsize*(out.x.max()-out.x.min()) - stepsize=xrange/(len(out.x)-1) - print " Beamsize %e m" % beamsize - print " Measurement range: %e m, stepszie: %e m" % (xrange, stepsize) - # compute difference in angle between wavefront of carrier and sidebands - diff_l = (out["PDrefl_low"]-out["PDrefl_car"])/stepsize - diff_u = (out["PDrefl_up"]-out["PDrefl_car"])/stepsize - tilt_l = diff_l[1:-1]-diff_l[0:-2] - tilt_u = diff_u[1:-1]-diff_u[0:-2] - print " Tilt (upper - car), mean: %e m/deg, stddev %e m/deg" % (np.mean(tilt_u), np.std(tilt_u)) - print " Tilt (lower - car), mean: %e m/deg, stddev %e m/deg" % (np.mean(tilt_l), np.std(tilt_l)) - return (np.mean(tilt_l), np.mean(tilt_u)) - - code_WFS1 = """ - beam PDrefl_car 0 nWFS1 - beam PDrefl_up 9M nWFS1 - beam PDrefl_low -9M nWFS1 - bp w0y y w0 nWFS1 - """ - - code_WFS2 = """ - beam PDrefl_car 0 nWFS2 - beam PDrefl_up 9M nWFS2 - beam PDrefl_low -9M nWFS2 - bp w0y y w0 nWFS2 - """ - code_comm = """ - xaxis PDrefl_car y lin -1 1 100 - put PDrefl_up y $x1 - put PDrefl_low y $x1 - yaxis abs:deg - """ - - print " WFS1:" - print " ITM ybeta 0.1nm" - kat.parseKatCode(code_comm) - kat.parseKatCode(code_WFS1) - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - (a1, a2) = compute_tilt(kat) - - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - (a3, a4) = compute_tilt(kat) - - print " WFS2:" - print " ITM ybeta 0.1nm" - kat = copy.deepcopy(tmpkat) - kat.parseKatCode(code_comm) - kat.parseKatCode(code_WFS2) - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - (a5, a6) = compute_tilt(kat) - - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - (a6, a7) = compute_tilt(kat) - - return - + kat = copy.deepcopy(tmpkat) + + def compute_tilt(tmpkat): + global kat + kat = copy.deepcopy(tmpkat) + global out + out = kat.run() + + # compute data x range in meters + beamsize = out["w0y"][0] + deng + xrange = beamsize*(out.x.max()-out.x.min()) + stepsize=xrange/(len(out.x)-1) + print(" Beamsize %e m" % beamsize) + print(" Measurement range: %e m, stepszie: %e m" % (xrange, stepsize)) + # compute difference in angle between wavefront of carrier and sidebands + diff_l = (out["PDrefl_low"]-out["PDrefl_car"])/stepsize + diff_u = (out["PDrefl_up"]-out["PDrefl_car"])/stepsize + tilt_l = diff_l[1:-1]-diff_l[0:-2] + tilt_u = diff_u[1:-1]-diff_u[0:-2] + print(" Tilt (upper - car), mean: %e m/deg, stddev %e m/deg" % (np.mean(tilt_u), np.std(tilt_u))) + print(" Tilt (lower - car), mean: %e m/deg, stddev %e m/deg" % (np.mean(tilt_l), np.std(tilt_l))) + return (np.mean(tilt_l), np.mean(tilt_u)) + + code_WFS1 = """ + beam PDrefl_car 0 nWFS1 + beam PDrefl_up 9M nWFS1 + beam PDrefl_low -9M nWFS1 + bp w0y y w0 nWFS1 + """ + + code_WFS2 = """ + beam PDrefl_car 0 nWFS2 + beam PDrefl_up 9M nWFS2 + beam PDrefl_low -9M nWFS2 + bp w0y y w0 nWFS2 + """ + code_comm = """ + xaxis PDrefl_car y lin -1 1 100 + put PDrefl_up y $x1 + put PDrefl_low y $x1 + yaxis abs:deg + """ + + print(" WFS1:") + print(" ITM ybeta 0.1nm") + kat.parseKatCode(code_comm) + kat.parseKatCode(code_WFS1) + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + (a1, a2) = compute_tilt(kat) + + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + (a3, a4) = compute_tilt(kat) + + print(" WFS2:") + print(" ITM ybeta 0.1nm") + kat = copy.deepcopy(tmpkat) + kat.parseKatCode(code_comm) + kat.parseKatCode(code_WFS2) + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + (a5, a6) = compute_tilt(kat) + + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + (a6, a7) = compute_tilt(kat) + + return + if __name__ == '__main__': - main() + main() diff --git a/examples/asc_test/master3.py b/examples/asc_test/master3.py index fac597ec5f85c380aba2446d30542dd1648686f2..4fddda3c608feff63ce47db5f539fb572b19e6a6 100644 --- a/examples/asc_test/master3.py +++ b/examples/asc_test/master3.py @@ -1,3 +1,8 @@ +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 numpy as np @@ -8,7 +13,7 @@ import shutil def main(): - print """ + print(""" -------------------------------------------------------------- Example file for using PyKat to automate Finesse simulations Finesse: http://www.gwoptics.org/finesse @@ -26,7 +31,7 @@ def main(): Andreas Freise 16.01.2014 -------------------------------------------------------------- - """ + """) # shall we clear the workspace? # %reset -f @@ -44,7 +49,7 @@ def main(): kat.loadKatFile('asc_base3.kat') try: tmpfile = shelve.open(tmpresultfile) - result=tmpfile['result'] + result=tmpfile[b'result'] tmpfile.close() except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) @@ -52,12 +57,12 @@ def main(): kat.WFS1_Q.enables = False kat.WFS2_Q.enables = False - print "--------------------------------------------------------" - print " 9. ASC signals for large misalignments (ITM)" + print("--------------------------------------------------------") + print(" 9. ASC signals for large misalignments (ITM)") asc_large(kat, 'ITM') - print "--------------------------------------------------------" - print " 10. ASC signals for large misalignments (ETM)" + print("--------------------------------------------------------") + print(" 10. ASC signals for large misalignments (ETM)") asc_large(kat, 'ETM') @@ -90,17 +95,17 @@ def asc_large(tmpkat, mir_name): 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 if os.path.isfile(tmpfilename): shutil.copyfile(tmpfilename, backupname) - print " current results saved in: {0}".format(tmpfilename) + print(" current results saved in: {0}".format(tmpfilename)) tmpfile = shelve.open(tmpfilename) - tmpfile['out']=out - tmpfile['maxtems']=done_maxtems + tmpfile[b'out']=out + tmpfile[b'maxtems']=done_maxtems tmpfile.close() diff --git a/examples/asc_test/master3_plot.py b/examples/asc_test/master3_plot.py index 6f64ce987a473e36d3005111e4969ef833d23e18..373a8aeb5abb24e8a4343761e0500dadfbf47841 100644 --- a/examples/asc_test/master3_plot.py +++ b/examples/asc_test/master3_plot.py @@ -1,3 +1,8 @@ +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 @@ -16,7 +21,7 @@ def printPDF(self, filename): pdfp.close() def main(): - print """ + print(""" -------------------------------------------------------------- Example file for using PyKat to automate Finesse simulations Finesse: http://www.gwoptics.org/finesse @@ -26,7 +31,7 @@ def main(): Andreas Freise 16.01.2014 -------------------------------------------------------------- - """ + """) # shall we clear the workspace? # %reset -f @@ -38,8 +43,8 @@ def main(): #global out #global result - print "--------------------------------------------------------" - print " Plotting ASC signals for large misalignments" + print("--------------------------------------------------------") + print(" Plotting ASC signals for large misalignments") asc_large('ITM') asc_large('ETM') @@ -57,8 +62,8 @@ def asc_large(mir_name): try: tmpfile = shelve.open(tmpfilename) - out=tmpfile['out'] - maxtems=tmpfile['maxtems'] + out=tmpfile[b'out'] + maxtems=tmpfile[b'maxtems'] tmpfile.close() except: raise Exception("Could not open temprary results file {0}".format(tmpfilename)) diff --git a/examples/asc_test/master4.py b/examples/asc_test/master4.py index 9ec50ac7052e7676c17087357c8473a17f39beff..a96f2387d70ad099fbfecffdf2606b902ec51188 100644 --- a/examples/asc_test/master4.py +++ b/examples/asc_test/master4.py @@ -1,3 +1,8 @@ +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 * from pykat.optics.gaussian_beams import gauss_param @@ -19,7 +24,7 @@ def set_thermal_lens(kat, f): def main(): - print """ + print(""" -------------------------------------------------------------- Example file for using PyKat to automate Finesse simulations Finesse: http://www.gwoptics.org/finesse @@ -37,7 +42,7 @@ def main(): Andreas Freise 16.01.2014 -------------------------------------------------------------- - """ + """) # shall we clear the workspace? # %reset -f @@ -55,7 +60,7 @@ def main(): kat.loadKatFile('asc_base3.kat') try: tmpfile = shelve.open(tmpresultfile) - result=tmpfile['result'] + result=tmpfile[b'result'] tmpfile.close() except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile)) @@ -69,8 +74,8 @@ def main(): kat.ETM.phi=result['phi_tuned'] - print "--------------------------------------------------------" - print " 11. Do beam tracing to measure beam parameters" + 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) @@ -101,19 +106,19 @@ def main(): t_node=kat.s2.npo2 kat = set_thermal_lens(kat,50e3) - print "--------------------------------------------------------" - print " 12. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f) + print("--------------------------------------------------------") + print(" 12. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f)) - print " Setting compromise beam parameter {0}: w0={1}, z={2}".format(node_text, beam50.w0, beam50.z) + print(" Setting compromise beam parameter {0}: w0={1}, z={2}".format(node_text, beam50.w0, beam50.z)) t_node.node.setGauss(t_comp, beam50) kat.maxtem=8 - print " Calculating maxtem = %d " % kat.maxtem + print(" Calculating maxtem = %d " % kat.maxtem) tmp = gravity_tilt(kat) kat = set_thermal_lens(kat,5e3) - print "--------------------------------------------------------" - print " 13. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f) - print " Setting compromise beam parameter {0}: w0={1}, z={2}".format(node_text, beam5.w0, beam5.z) + print("--------------------------------------------------------") + print(" 13. computing beam tilt with thermal lens (f={0})".format(kat.ITM_TL.f)) + print(" Setting compromise beam parameter {0}: w0={1}, z={2}".format(node_text, beam5.w0, beam5.z)) t_node.node.setGauss(t_comp, beam5) #maxtems = [1, 3, 5, 9, 11, 13, 15, 19, 23, 25, 27, 29] maxtems = [1, 3, 5, 7] @@ -124,16 +129,16 @@ def main(): kat.WFS2_I.enabled = True kat = set_thermal_lens(kat,50e3) - print "--------------------------------------------------------" - print " 12. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f) + print("--------------------------------------------------------") + print(" 12. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f)) t_node.node.setGauss(t_comp, beam50) #maxtems = [1, 3, 5, 9, 11, 13, 15, 17, 19] maxtems = [1, 3, 5, 7] converge_asc(kat, maxtems, 'asc_signals_50.txt') kat = set_thermal_lens(kat,5e3) - print "--------------------------------------------------------" - print " 13. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f) + print("--------------------------------------------------------") + print(" 13. computing alignment signal with thermal lens (f={0})".format(kat.ITM_TL.f)) t_node.node.setGauss(t_comp, beam5) #maxtems = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] maxtems = [1, 3, 5, 7] @@ -146,12 +151,12 @@ def converge_asc(tmpkat, maxtems, filename): savedata = np.zeros([len(maxtems),5]) for idx, tem in enumerate(maxtems): savedata[idx,0]=tem - print " Calculating maxtem = %d " % tem + print(" Calculating maxtem = %d " % tem) kat.maxtem = tem tmp = asc_signal(kat) savedata[idx,1:5]=tmp.reshape([1,4]) - print " Saving results in file: {0}".format(filename) - np.savetxt(filename, savedata[0:idx+1,:], fmt='%.18e', delimiter=' ') + print(" Saving results in file: {0}".format(filename)) + np.savetxt(filename, savedata[0:idx+1,:], fmt=b'%.18e', delimiter=' ') def converge_tilt(tmpkat, maxtems): kat = copy.deepcopy(tmpkat) @@ -159,12 +164,12 @@ def converge_tilt(tmpkat, maxtems): filename = "thermal_gravity.txt" for idx, tem in enumerate(maxtems): savedata[idx,0]=tem - print " Calculating maxtem = %d " % tem + print(" Calculating maxtem = %d " % tem) kat.maxtem = tem tmp = gravity_tilt(kat) savedata[idx,1:5]=tmp - print " Saving results in file: {0}".format(filename) - np.savetxt(filename, savedata[0:idx+1,:], fmt='%.18e', delimiter=' ') + print(" Saving results in file: {0}".format(filename)) + np.savetxt(filename, savedata[0:idx+1,:], fmt=b'%.18e', delimiter=' ') def get_qs(tmpkat,f): kat = copy.deepcopy(tmpkat) @@ -181,17 +186,17 @@ def get_qs(tmpkat,f): def beam_size(tmpkat, f, beam0): kat = copy.deepcopy(tmpkat) - print "setting q param ---------------" + print("setting q param ---------------") kat.psl.npsl.node.setGauss(kat.psl, beam0) - print kat.psl.npsl.node.q + print(kat.psl.npsl.node.q) #kat.parseKatCode("startnode npsl") - print "".join(kat.generateKatScript()) + print("".join(kat.generateKatScript())) # add thermal lens and propagate input beam to ITM kat = set_thermal_lens(kat, f) global out - print "".join(kat.generateKatScript()) + print("".join(kat.generateKatScript())) out = kat.run(printout=0,printerr=0) @@ -221,11 +226,11 @@ def get_qs(tmpkat,f): # computing beam size at pick off q4 = out['w4'] beam4 = gauss_param(q=q4) - print " Input mode beam size with thermal lens f={0}".format(f) - print " - ITM w={0:.6}cm (w0={1}, z={2})".format(100.0*beam1.w,beam1.w0, beam1.z) - print " - WFS1 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam2.w,beam2.w0, beam2.z) - print " - WFS2 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam3.w,beam3.w0, beam3.z) - print " - npo2 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam4.w,beam4.w0, beam4.z) + print(" Input mode beam size with thermal lens f={0}".format(f)) + print(" - ITM w={0:.6}cm (w0={1}, z={2})".format(100.0*beam1.w,beam1.w0, beam1.z)) + print(" - WFS1 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam2.w,beam2.w0, beam2.z)) + print(" - WFS2 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam3.w,beam3.w0, beam3.z)) + print(" - npo2 w={0:.6}cm (w0={1}, z={2})".format(100.0*beam4.w,beam4.w0, beam4.z)) #raw_input("Press enter to continue") return [beam1, beam2, beam3, beam4] @@ -271,12 +276,12 @@ def asc_signal(tmpkat): signal = signal *1e10 sensors=('WFS1', 'WFS2') mirrors=('ITM', 'ETM') - print " ASC Matrix:" + print(" ASC Matrix:") for i in range(2): - print " ", sensors[i], " ", + print(" ", sensors[i], " ", end=' ') for j in range(2): - print "%12.10g" % signal[i,j], - print mirrors[i] + print("%12.10g" % signal[i,j], end=' ') + print(mirrors[i]) return signal def gravity_tilt(tmpkat): @@ -339,10 +344,10 @@ def gravity_tilt(tmpkat): kat.ITM.ybeta=0.0 kat.ETM.ybeta=-1e-10 t4=compute_gravity_tilt(kat) - print " WFS1 ITM {0:.4} nrad".format(t1*1e9) - print " WFS2 ITM {0:.4} nrad".format(t3*1e9) - print " WFS1 ETM {0:.4} nrad".format(t2*1e9) - print " WFS2 ETM {0:.4} nrad".format(t4*1e9) + print(" WFS1 ITM {0:.4} nrad".format(t1*1e9)) + print(" WFS2 ITM {0:.4} nrad".format(t3*1e9)) + print(" WFS1 ETM {0:.4} nrad".format(t2*1e9)) + print(" WFS2 ETM {0:.4} nrad".format(t4*1e9)) return [t1,t2,t3,t4] if __name__ == '__main__': diff --git a/examples/asc_test/master4_plot.py b/examples/asc_test/master4_plot.py index a65e393a1b562a5c4db882297dbc20ffe704a323..a10dcfdbf083b311f7e15a9bf83da3785e9dfbe9 100644 --- a/examples/asc_test/master4_plot.py +++ b/examples/asc_test/master4_plot.py @@ -1,3 +1,8 @@ +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 @@ -15,7 +20,7 @@ def printPDF(self, filename): pdfp.close() def main(): - print """ + print(""" -------------------------------------------------------------- Example file for using PyKat to automate Finesse simulations Finesse: http://www.gwoptics.org/finesse @@ -25,19 +30,19 @@ def main(): Andreas Freise 16.01.2014 -------------------------------------------------------------- - """ + """) # shall we clear the workspace? # %reset -f # maybe close all plot windows? # close('all') - print "--------------------------------------------------------" - print " Plotting beam tilt with thermal lens " + print("--------------------------------------------------------") + print(" Plotting beam tilt with thermal lens ") gravity_tilt() - print "--------------------------------------------------------" - print " Plotting WFS signal with thermal lens " + print("--------------------------------------------------------") + print(" Plotting WFS signal with thermal lens ") asc_signal('asc_signals_5.txt', (0.3,0.15)) asc_signal('asc_signals_50.txt', (0.3,0.15)) diff --git a/examples/asc_test/master5.py b/examples/asc_test/master5.py index 1996b947612cd48389ccceef515c47e6052165ca..1ba6c2ba04be3093046d834298e88e2a241f6609 100644 --- a/examples/asc_test/master5.py +++ b/examples/asc_test/master5.py @@ -1,3 +1,8 @@ +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 * from pykat.optics.gaussian_beams import gauss_param @@ -13,376 +18,371 @@ import sys 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 - - This file is part of a collection. Run this after master2.py - - Andreas Freise 06.12.2013 - -------------------------------------------------------------- - """ - - # 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 = '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 - - # this does not work yet due to the scale command - kat.PDrefl_p.enabled = False - kat.PDrefl_q.enabled = 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'] - - - (beam1, beam2, beam3) = get_qs(kat) - """ - print " Measured beam parameter:" - print " - At front of ITM (no thermal lens) q={0}".format(beam1.q) - print " (eqals w0={0}, z={1})".format(beam1.w0, beam1.z) - print " - At pick of mirror 'po' (50k lens) q={0}".format(beam2.q) - print " (eqals w0={0}, z={1})".format(beam2.w0, beam2.z) - print " - At pick of mirror 'po' (5k lens) q={0}".format(beam3.q) - print " (eqals w0={0}, z={1})".format(beam3.w0, beam3.z) - #print " Setting these now view Gauss command and adding thermal lens" - """ - kat.ITM.nITM1.node.setGauss(kat.ITM,beam1) - - print "--------------------------------------------------------" - print " 11. computing beam sizes with thermal lens" - #beam_size(kat, beam2, beam3) - - kat.ITM_TL.f=50e3 - kat.maxtem = 8 - print "--------------------------------------------------------" - print " 11. computing beam tilt with thermal lens (f={0}, maxtem={1})".format(kat.ITM_TL.f, kat.maxtem) - #gravity_tilt(kat) - - kat.ITM_TL.f=5e3 - kat.maxtem = 23 - - print "--------------------------------------------------------" - print " 12. computing beam tilt with thermal lens (f={0}, maxtem={1})".format(kat.ITM_TL.f, kat.maxtem) - #gravity_tilt(kat) - - - print "--------------------------------------------------------" - print " 12. compute beam center with thermal lens" - - - - - print "--------------------------------------------------------" - print " Saving results in temp. files to be read by master6.py" - tmpkatfile = "asc_base4.kat" - tmpresultfile = "myshelf3.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: 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 + + This file is part of a collection. Run this after master2.py + + Andreas Freise 06.12.2013 + -------------------------------------------------------------- + """) + + # 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 = 'myshelf2.dat' + + # loading data saved by master.py + kat.loadKatFile('asc_base3.kat') + try: + tmpfile = shelve.open(tmpresultfile) + result=tmpfile[b'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 + + # this does not work yet due to the scale command + kat.PDrefl_p.enabled = False + kat.PDrefl_q.enabled = 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'] + + (beam1, beam2, beam3) = get_qs(kat) + """ + print " Measured beam parameter:" + print " - At front of ITM (no thermal lens) q={0}".format(beam1.q) + print " (eqals w0={0}, z={1})".format(beam1.w0, beam1.z) + print " - At pick of mirror 'po' (50k lens) q={0}".format(beam2.q) + print " (eqals w0={0}, z={1})".format(beam2.w0, beam2.z) + print " - At pick of mirror 'po' (5k lens) q={0}".format(beam3.q) + print " (eqals w0={0}, z={1})".format(beam3.w0, beam3.z) + #print " Setting these now view Gauss command and adding thermal lens" + """ + kat.ITM.nITM1.node.setGauss(kat.ITM,beam1) + + print("--------------------------------------------------------") + print(" 11. computing beam sizes with thermal lens") + #beam_size(kat, beam2, beam3) + + kat.ITM_TL.f=50e3 + kat.maxtem = 8 + print("--------------------------------------------------------") + print(" 11. computing beam tilt with thermal lens (f={0}, maxtem={1})".format(kat.ITM_TL.f, kat.maxtem)) + #gravity_tilt(kat) + + kat.ITM_TL.f=5e3 + kat.maxtem = 23 + + print("--------------------------------------------------------") + print(" 12. computing beam tilt with thermal lens (f={0}, maxtem={1})".format(kat.ITM_TL.f, kat.maxtem)) + #gravity_tilt(kat) + + + print("--------------------------------------------------------") + print(" 12. compute beam center with thermal lens") + + + + + print("--------------------------------------------------------") + print(" Saving results in temp. files to be read by master6.py") + tmpkatfile = "asc_base4.kat" + tmpresultfile = "myshelf3.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[b'result']=result + tmpfile.close() #----------------------------------------------------------------------------------- def get_qs(tmpkat): - kat = copy.deepcopy(tmpkat) - nodename0="npsl" - nodename1="nITM1" - nodename2="nWFS1" - nodename3="nWFS2" - # measure beam parameter for the 'cold beam' i.e. the laser beam - # matched to the cavity without any thermal lens - code_bp = "bp w0 y q {0}\nbp w1 y q {1}\nbp w2 y q {2}\nbp w3 y q {3}".format(nodename0,nodename1,nodename2,nodename3) - - kat.parseKatCode(code_bp) - kat.parseKatCode('yaxis re:im') - kat.noxaxis = True - kat.maxtem=0 - - def beam_size(tmpkat, f): - kat = copy.deepcopy(tmpkat) - # 1. run finesse with input laser mode matched to cavity (no thermal lens) - out = kat.run(printout=0,printerr=0) - - # beam at laser when matched to cold cavity - # (note the sign flip of the real part to change direction of gauss param) - q0 = -1.0*out['w0'].conjugate() - beam0 = gauss_param(q=q0) - kat.psl.npsl.node.setGauss(kat.psl, beam0) - kat.parseKatCode("startnode npsl") - - # add thermal lens and propagate input beam to ITM - kat.ITM_TL.f=f - if "ITM_TL_r" in kat._kat__components: - kat.ITM_TL_r.f=f - out = kat.run(printout=0,printerr=0) - - # computing beam size at ITM - # and then we reflect of ITM, an set it as new startnode - q_in = out['w1'] - from pykat.optics.ABCD import apply, mirror_refl - abcd = mirror_refl(1,-2500) - q_out = apply(abcd,q_in,1,1) - beam1 = gauss_param(q=q_out) - kat.removeLine("startnode") - kat.psl.npsl.node.removeGauss() - if "ITM_TL_r" in kat._kat__components: - kat.ITM.nITM1r.node.setGauss(kat.ITM, beam1) - kat.parseKatCode("startnode nITM1r") - else: - kat.ITM.nITM1.node.setGauss(kat.ITM, beam1) - kat.parseKatCode("startnode nITM1") - out = kat.run(printout=0,printerr=0) - - # computing beam size at WFS1 and WFS2 - q2 = out['w2'] - beam2 = gauss_param(q=q2) - q3 = out['w3'] - beam3 = gauss_param(q=q3) - print " Sideband (input mode) beam size with thermal lens f={0}".format(f) - print " - WFS1 w={0:.6}cm".format(100.0*beam2.w) - print " (w0={0}, z={1})".format(beam2.w0, beam2.z) - print " - WFS2 w={0:.6}cm".format(100.0*beam3.w) - print " (w0={0}, z={1})".format(beam3.w0, beam3.z) - raw_input("Press enter to continue") - - return(beam1, beam2, beam3) - - f=50e3 - beam_size(kat,f) - - f=5e3 - (beam1,beam2,beam3)=beam_size(kat,f) - - - return (beam1, beam2,beam3) + kat = copy.deepcopy(tmpkat) + nodename0="npsl" + nodename1="nITM1" + nodename2="nWFS1" + nodename3="nWFS2" + # measure beam parameter for the 'cold beam' i.e. the laser beam + # matched to the cavity without any thermal lens + code_bp = "bp w0 y q {0}\nbp w1 y q {1}\nbp w2 y q {2}\nbp w3 y q {3}".format(nodename0,nodename1,nodename2,nodename3) + + kat.parseKatCode(code_bp) + kat.parseKatCode('yaxis re:im') + kat.noxaxis = True + kat.maxtem=0 + + def beam_size(tmpkat, f): + kat = copy.deepcopy(tmpkat) + # 1. run finesse with input laser mode matched to cavity (no thermal lens) + out = kat.run(printout=0,printerr=0) + + # beam at laser when matched to cold cavity + # (note the sign flip of the real part to change direction of gauss param) + q0 = -1.0*out['w0'].conjugate() + beam0 = gauss_param(q=q0) + kat.psl.npsl.node.setGauss(kat.psl, beam0) + kat.parseKatCode("startnode npsl") + + # add thermal lens and propagate input beam to ITM + kat.ITM_TL.f=f + if "ITM_TL_r" in kat._kat__components: + kat.ITM_TL_r.f=f + out = kat.run(printout=0,printerr=0) + + # computing beam size at ITM + # and then we reflect of ITM, an set it as new startnode + q_in = out['w1'] + from pykat.optics.ABCD import apply, mirror_refl + abcd = mirror_refl(1,-2500) + q_out = apply(abcd,q_in,1,1) + beam1 = gauss_param(q=q_out) + kat.removeLine("startnode") + kat.psl.npsl.node.removeGauss() + if "ITM_TL_r" in kat._kat__components: + kat.ITM.nITM1r.node.setGauss(kat.ITM, beam1) + kat.parseKatCode("startnode nITM1r") + else: + kat.ITM.nITM1.node.setGauss(kat.ITM, beam1) + kat.parseKatCode("startnode nITM1") + out = kat.run(printout=0,printerr=0) + + # computing beam size at WFS1 and WFS2 + q2 = out['w2'] + beam2 = gauss_param(q=q2) + q3 = out['w3'] + beam3 = gauss_param(q=q3) + print(" Sideband (input mode) beam size with thermal lens f={0}".format(f)) + print(" - WFS1 w={0:.6}cm".format(100.0*beam2.w)) + print(" (w0={0}, z={1})".format(beam2.w0, beam2.z)) + print(" - WFS2 w={0:.6}cm".format(100.0*beam3.w)) + print(" (w0={0}, z={1})".format(beam3.w0, beam3.z)) + raw_input("Press enter to continue") + return(beam1, beam2, beam3) + + f=50e3 + beam_size(kat,f) + f=5e3 + (beam1,beam2,beam3)=beam_size(kat,f) + return (beam1, beam2,beam3) 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 - - + 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], " ", end=' ') + for j in range(2): + print("%12.10g" % signal[i,j], end=' ') + print(mirrors[i]) + return signal + + def asc_phases(tmpkat): - kat = copy.deepcopy(tmpkat) - - kat.parseKatCode('yaxis abs') - kat.noxaxis = True - kat.maxtem=1 - - def demod_phase1(x): - kat.WFS1_I.phi[0]=x - out = kat.run(printout=0,printerr=0) - WFS1_idx=out.ylabels.index("WFS1_I") - signal = out.y[WFS1_idx] - print '\r minimising: function value %g ' % signal , - sys.stdout.flush() - return -1*abs(signal) - - def demod_phase2(x): - kat.WFS2_I.phi[0]=x - out = kat.run(printout=0,printerr=0) - WFS2_idx=out.ylabels.index("WFS2_I") - signal = out.y[WFS2_idx] - print '\r minimising: function value %g ' % signal , - sys.stdout.flush() - return -1*abs(signal) - - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - res = minimize_scalar(demod_phase1, method='brent') - WFS1_phase = res.x - 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 - print "" - print " WFS2 demod phase : %.10g deg" % WFS2_phase - return(WFS1_phase, WFS2_phase) - + kat = copy.deepcopy(tmpkat) + + kat.parseKatCode('yaxis abs') + kat.noxaxis = True + kat.maxtem=1 + + def demod_phase1(x): + kat.WFS1_I.phi[0]=x + out = kat.run(printout=0,printerr=0) + WFS1_idx=out.ylabels.index("WFS1_I") + signal = out.y[WFS1_idx] + print('\r minimising: function value %g ' % signal, end=' ') + sys.stdout.flush() + return -1*abs(signal) + + def demod_phase2(x): + kat.WFS2_I.phi[0]=x + out = kat.run(printout=0,printerr=0) + WFS2_idx=out.ylabels.index("WFS2_I") + signal = out.y[WFS2_idx] + print('\r minimising: function value %g ' % signal, end=' ') + sys.stdout.flush() + return -1*abs(signal) + + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + res = minimize_scalar(demod_phase1, method='brent') + WFS1_phase = res.x + 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 + print("") + print(" WFS2 demod phase : %.10g deg" % WFS2_phase) + return(WFS1_phase, WFS2_phase) + def gravity_tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - - def compute_gravity_tilt(tmpkat): - kat = copy.deepcopy(tmpkat) - out = kat.run(printout=0,printerr=0) - - y1 = out["b1"] - y2 = out["b1_1k"] - # shift of beam center on detector 1 (as m/w0y) - x1 = np.sum(out.x*y1)/np.sum(y1) - # shift of beam center on detector 2 (as m/w0y) - x2 = np.sum(out.x*y2)/np.sum(y2) - # calibrate this in meter by mutliplying with w0y - # and compute the angle geometrically - w0=out["w0y"][0] - detector_distance = 1000.0 - tilt=w0*(x2-x1)/detector_distance - print " Wavefront tilt : %g nrad" % tilt - - code_WFS1 = """ - beam b1 nWFS1 - beam b1_1k nL1_in - bp w0y y w0 nWFS1 - """ - - code_WFS2 = """ - m md 0 1 0 nWFS2 nWFS2b - s sd 1k nWFS2b nWFS2c - beam b1 nWFS2* - beam b1_1k nWFS2c - bp w0y y w0 nWFS2 - """ - - code_xaxis= """ - xaxis b1 y lin -40 40 800 - put b1_1k y $x1 - yaxis abs - """ - print " WFS1:" - print " ITM ybeta 0.1nm" - kat.parseKatCode(code_WFS1) - kat.parseKatCode(code_xaxis) - kat.spo1.L=1000.0 - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - compute_gravity_tilt(kat) - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - compute_gravity_tilt(kat) - - print " WFS1:" - print " ITM ybeta 0.1nm" - kat = copy.deepcopy(tmpkat) - kat.parseKatCode(code_WFS2) - kat.parseKatCode(code_xaxis) - kat.spo1.L=1.0e-9 - kat.ITM.ybeta=1e-10 - kat.ETM.ybeta=0.0 - compute_gravity_tilt(kat) - print " ETM ybeta -0.1nm" - kat.ITM.ybeta=0.0 - kat.ETM.ybeta=-1e-10 - compute_gravity_tilt(kat) + kat = copy.deepcopy(tmpkat) + + def compute_gravity_tilt(tmpkat): + kat = copy.deepcopy(tmpkat) + out = kat.run(printout=0,printerr=0) + + y1 = out["b1"] + y2 = out["b1_1k"] + # shift of beam center on detector 1 (as m/w0y) + x1 = np.sum(out.x*y1)/np.sum(y1) + # shift of beam center on detector 2 (as m/w0y) + x2 = np.sum(out.x*y2)/np.sum(y2) + # calibrate this in meter by mutliplying with w0y + # and compute the angle geometrically + w0=out["w0y"][0] + detector_distance = 1000.0 + tilt=w0*(x2-x1)/detector_distance + print(" Wavefront tilt : %g nrad" % tilt) + + code_WFS1 = """ + beam b1 nWFS1 + beam b1_1k nL1_in + bp w0y y w0 nWFS1 + """ + + code_WFS2 = """ + m md 0 1 0 nWFS2 nWFS2b + s sd 1k nWFS2b nWFS2c + beam b1 nWFS2* + beam b1_1k nWFS2c + bp w0y y w0 nWFS2 + """ + + code_xaxis= """ + xaxis b1 y lin -40 40 800 + put b1_1k y $x1 + yaxis abs + """ + print(" WFS1:") + print(" ITM ybeta 0.1nm") + kat.parseKatCode(code_WFS1) + kat.parseKatCode(code_xaxis) + kat.spo1.L=1000.0 + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + compute_gravity_tilt(kat) + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + compute_gravity_tilt(kat) + + print(" WFS1:") + print(" ITM ybeta 0.1nm") + kat = copy.deepcopy(tmpkat) + kat.parseKatCode(code_WFS2) + kat.parseKatCode(code_xaxis) + kat.spo1.L=1.0e-9 + kat.ITM.ybeta=1e-10 + kat.ETM.ybeta=0.0 + compute_gravity_tilt(kat) + print(" ETM ybeta -0.1nm") + kat.ITM.ybeta=0.0 + kat.ETM.ybeta=-1e-10 + compute_gravity_tilt(kat) def beam_size(tmpkat, beam2, beam3): - kat = copy.deepcopy(tmpkat) - - global out - code_bps = """ - bp wWFS1 y w nWFS1 - bp wWFS2 y w nWFS2 - """ - kat.parseKatCode(code_bps) - kat.maxtem = 0 - kat.ITM.R=1.0 - kat.ITM.T=0.0 - - kat.noxaxis = True - kat.ITM_TL.f=50e3 - if "ITM_TL_r" in kat._kat__components: - kat.ITM_TL_r.f=50e3 - - kat.po.nWFS1.node.setGauss(kat.po,beam2) - - out = kat.run(printout=0,printerr=0) - - WFS1_idx=out.ylabels.index("wWFS1") - WFS2_idx=out.ylabels.index("wWFS2") - - - y1 = out.y[WFS1_idx] - y2 = out.y[WFS2_idx] - print " Beam size with thermal lens f={0}".format(kat.ITM_TL.f) - print " WFS1: {0}cm".format(y1*100.0) - print " WFS2: {0}cm".format(y2*100.0) - - kat.ITM_TL.f=5e3 - if "ITM_TL_r" in kat._kat__components: - kat.ITM_TL_r.f=5e3 - kat.po.nWFS1.node.setGauss(kat.po,beam3) - out = kat.run(printout=0,printerr=0) - y1 = out.y[WFS1_idx] - y2 = out.y[WFS2_idx] - print " Beam size with thermal lens f={0}".format(kat.ITM_TL.f) - print " WFS1: {0}cm".format(y1*100.0) - print " WFS2: {0}cm".format(y2*100.0) - - + kat = copy.deepcopy(tmpkat) + + global out + code_bps = """ + bp wWFS1 y w nWFS1 + bp wWFS2 y w nWFS2 + """ + kat.parseKatCode(code_bps) + kat.maxtem = 0 + kat.ITM.R=1.0 + kat.ITM.T=0.0 + + kat.noxaxis = True + kat.ITM_TL.f=50e3 + if "ITM_TL_r" in kat._kat__components: + kat.ITM_TL_r.f=50e3 + + kat.po.nWFS1.node.setGauss(kat.po,beam2) + + out = kat.run(printout=0,printerr=0) + + WFS1_idx=out.ylabels.index("wWFS1") + WFS2_idx=out.ylabels.index("wWFS2") + + + y1 = out.y[WFS1_idx] + y2 = out.y[WFS2_idx] + print(" Beam size with thermal lens f={0}".format(kat.ITM_TL.f)) + print(" WFS1: {0}cm".format(y1*100.0)) + print(" WFS2: {0}cm".format(y2*100.0)) + + kat.ITM_TL.f=5e3 + if "ITM_TL_r" in kat._kat__components: + kat.ITM_TL_r.f=5e3 + kat.po.nWFS1.node.setGauss(kat.po,beam3) + out = kat.run(printout=0,printerr=0) + y1 = out.y[WFS1_idx] + y2 = out.y[WFS2_idx] + print(" Beam size with thermal lens f={0}".format(kat.ITM_TL.f)) + print(" WFS1: {0}cm".format(y1*100.0)) + print(" WFS2: {0}cm".format(y2*100.0)) + + if __name__ == '__main__': - main() + main() diff --git a/pykat/commands.py b/pykat/commands.py index e770408a801d4fbc70c57be0870fc5d7e7dbbc66..9458b5fa49c873a99d7787bf7f70a4adbb0d3c56 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -153,7 +153,7 @@ class xaxis(Command): scale = Scale.linear elif scale == "log": scale = Scale.logarithmic - elif isinstance(scale, str): + elif isinstance(scale, six.string_types): # else we have a string but not a recognisable one raise pkex.BasePyKatException("scale argument '{0}' is not valid, must be 'lin' or 'log'".format(scale)) @@ -172,7 +172,7 @@ class xaxis(Command): self.steps = int(steps) - if isinstance(param, str): + if isinstance(param, six.string_types): self.__param = param if comp == None: raise pkex.BasePyKatException("If parameter is set with a string, the comp argument must set the component name") diff --git a/pykat/components.py b/pykat/components.py index de6b365aa9632589b31f9ebde1fedb82abbf7d3e..8cd8c8142189c9a9abb9cfd99814e2d11f475527 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -9,7 +9,7 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -from pykat import USE_GUI, HAS_OPTIVIS, NoGUIException +from pykat import USE_GUI, NoGUIException import pykat.external.six as six diff --git a/pykat/detectors.py b/pykat/detectors.py index 31bf62cb7e9fbe176c7d7b62d109bf4c58bdd336..acca83ca2b6f3231bd78e0f4d9129e207c4f3c79 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -383,10 +383,9 @@ class pd(Detector1): fs = [self.__f1, self.__f2, self.__f3, self.__f4, self.__f5] ps = [self.__phi1, self.__phi2, self.__phi3, self.__phi4, self.__phi5] - print("-------------------------------------------------------") for i in range(num_demods): f = 'f{0}'.format(i+1) - print("i {0} fs {1} f {2} keys {3}".format(i,len(fs),f, kwargs.keys())) + #print("i {0} fs {1} f {2} keys {3}".format(i,len(fs),f, kwargs.keys())) if f in kwargs: fs[i].value = kwargs[f] diff --git a/pykat/finesse.py b/pykat/finesse.py index 0551f59a899608a7aebc963782a756a9a248037c..62792aee2f92345af9cbfeac3626ea858c0cd8b3 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -99,7 +99,7 @@ def f__lkat_process(callback, cmd, kwargs): callback(lkat, **kwargs) except Exception as ex: - print "Exception caught in python: ", ex.message + print ("Exception caught in python: ", ex.message) finally: # This should always be called no matter what lkat._pykat_finish(0) @@ -514,7 +514,7 @@ class kat(object): @staticmethod def logo(): - print """ ..- + print (""" ..- PyKat {0:7} _ '( \\`.|\\.__...-\"\"""-_." ) ..+-----.._ / ' ` .-' @@ -522,7 +522,7 @@ class kat(object): ( '::;;+;;: `-"' =" /,`"" `) / L. \\`:::a:f c_/ n_' ..`--...___`. . , - `^-....____: +. {1}\n""".format(pykat.__version__, pykat_web) + `^-....____: +. {1}\n""".format(pykat.__version__, pykat_web)) def loadKatFile(self, katfile, blocks=None): commands=open(katfile).read() @@ -730,7 +730,7 @@ class kat(object): self.deriv_h = float(v[1]) elif(first == "gnuterm" or first == "pyterm"): if self.verbose: - print "Ignoring Gnuplot/Python terminal command '{0}'".format(line) + print ("Ignoring Gnuplot/Python terminal command '{0}'".format(line)) elif(first == "fsig"): after_process.append(line) elif(first == "noplot"): @@ -738,7 +738,7 @@ class kat(object): self.__blocks[self.__currentTag].contents.append(line) else: if self.verbose: - print "Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line) + print ("Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line)) obj = line # manually add the line to the block contents @@ -747,13 +747,13 @@ class kat(object): if obj != None and not isinstance(obj, six.string_types): if self.hasNamedObject(obj.name): getattr(self, obj.name).remove() - print "Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line) + print ("Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line)) self.add(obj) except: - print "--------------------------------------------------------" - print "Error parsing line: " + line - print "--------------------------------------------------------" + print ("--------------------------------------------------------") + print ("Error parsing line: " + line) + print ("--------------------------------------------------------") raise @@ -878,7 +878,7 @@ class kat(object): katfile.close() except pkex.BasePyKatException as ex: - print ex + print (ex) def getProcess(self, callback, **kwargs): @@ -931,8 +931,8 @@ class kat(object): if not (os.path.isfile(kat_exec) and os.access(kat_exec, os.X_OK)): raise pkex.MissingFinesse() - if self.verbose: print "--------------------------------------------------------------" - if self.verbose: print "Running kat - Started at " + str(start) + if self.verbose: print ("--------------------------------------------------------------") + if self.verbose: print ("Running kat - Started at " + str(start)) if hasattr(self, "x2axis") and self.noxaxis == False: r = katRun2D() @@ -983,11 +983,13 @@ class kat(object): err = "" #if self.verbose: print "Finesse output:" - for line in iter(p.stderr.readline, ""): + for aline in iter(p.stderr.readline, b""): + line = unicode(aline, "utf-8") if len(line) > 0: # remove any ANSI commands - ansi = re.compile(r'\x1b[^m]*m') - line = ansi.sub('', line) + #ansi = re.compile(r'\x1b[^m]*m') + #line = ansi.sub('', line) + line = re.sub(r'\x1b[^m]*m', '', line, re.UNICODE) # warnings and errors start with an asterisk # so if verbose show them @@ -1016,9 +1018,9 @@ class kat(object): [out,errpipe] = p.communicate() if printout == 1: - print out + print (out) else: - if printerr == 1: print "" + if printerr == 1: print ("") # get the version number ix = out.find('build ') + 6 @@ -1029,7 +1031,7 @@ class kat(object): # If Finesse returned an error, just print that and exit! if p.returncode != 0: - print err + print (err) sys.exit(1) self.__prevrunfilename = katfile.name @@ -1049,20 +1051,20 @@ class kat(object): os.rename(outfile, newoutfile) - if self.verbose: print "\nOutput data saved to '{0}'".format(newoutfile) + if self.verbose: print ("\nOutput data saved to '{0}'".format(newoutfile)) if hasattr(self, "x2axis") and self.noxaxis == False: [r.x,r.y,r.z,hdr] = self.readOutFile(outfile) r.xlabel = hdr[0] r.ylabel = hdr[1] - r.zlabels = [s.strip for s in hdr[2:]] + r.zlabels = [s.strip() for s in hdr[2:]] #r.zlabels = map(str.strip, hdr[2:]) else: [r.x,r.y,hdr] = self.readOutFile(outfile) r.xlabel = hdr[0] - r.ylabels = [s.strip for s in hdr[1:]] + r.ylabels = [s.strip() for s in hdr[1:]] #r.ylabels = map(str.strip, hdr[1:]) // replaced 090415 adf if save_kat: @@ -1077,17 +1079,17 @@ class kat(object): os.rename(katfile.name, newkatfile) - if self.verbose: print "Kat file saved to '{0}'".format(newkatfile) + if self.verbose: print ("Kat file saved to '{0}'".format(newkatfile)) if self.trace != None and self.trace > 0: - #print "{0}".format(out) + #print ("{0}".format(out)) #if self.trace & 1: #search = out.find(' --- highest order of TEM modes') #if search > -1: - #print "Trace 1: {0}".format(out[search:]) + #print ("Trace 1: {0}".format(out[search:])) # for now, just try to print the trace block in full - print out[out.find(' ---') :] + print (out[out.find(' ---') :]) katfile.close() perfData = [] @@ -1104,10 +1106,10 @@ class kat(object): return r except pkex.FinesseRunError as fe: - print fe + print (fe) finally: - if self.verbose: print "" - if self.verbose: print "Finished in " + str(datetime.datetime.now()-start) + if self.verbose: print ("") + if self.verbose: print ("Finished in " + str(datetime.datetime.now()-start)) def remove(self, obj): if not isinstance(obj, pykat.finesse.Signals) and not (obj.name in self.__components or obj.name in self.__detectors or obj.name in self.__commands or obj in self.signals.targets): @@ -1147,7 +1149,7 @@ class kat(object): del nodes #import gc - #print gc.get_referrers(obj) + #print (gc.get_referrers(obj)) def getMatrices(self): @@ -1158,7 +1160,7 @@ class kat(object): self.noxaxis = True self.printmatrix = True - print "".join(self.generateKatScript()) + print ("".join(self.generateKatScript())) self.verbose = True self.run(printout=1) self.printmatrix = None @@ -1230,7 +1232,7 @@ class kat(object): obj._on_kat_add(self) except pkex.BasePyKatException as ex: - print ex + print (ex) def readOutFile(self, filename): @@ -1281,7 +1283,7 @@ class kat(object): for obj in objs: if isinstance(obj, six.string_types): if fragment in obj: - print " ** removing line '{0}'".format(obj) + print (" ** removing line '{0}'".format(obj)) objs.remove(obj) def addLine(self, line, block=NO_BLOCK) : @@ -1311,7 +1313,6 @@ class kat(object): if not found: print("No extra lines were found") ->>>>>>> starting cnversion to pykat2 and 3 compatibility def generateKatScript(self) : """ Generates the kat file which can then be run """ @@ -1565,7 +1566,7 @@ class kat(object): name = com.__class__.__name__ - print getattr(self.__class__, name) + print (getattr(self.__class__, name)) delattr(self.__class__, name) delattr(self, '__com_' + name) diff --git a/pykat/node_network.py b/pykat/node_network.py index ae543e2444da93cdaf64948cec36eb9c1c7a9744..550290e662dfcedb4378ead9002e538facb0a544 100644 --- a/pykat/node_network.py +++ b/pykat/node_network.py @@ -15,6 +15,7 @@ if USE_GUI: import pykat.gui.graphics import pykat.exceptions as pkex +import pykat.external.six as six from pykat.components import Component, NodeGaussSetter from pykat.detectors import BaseDetector as Detector @@ -76,10 +77,10 @@ class NodeNetwork(object): connected to it have changed. """ - if isinstance(node_old, str): + if isinstance(node_old, six.string_types): node_old = self.__kat.nodes[node_old] - if isinstance(node_new, str): + if isinstance(node_new, six.string_types): node_new = self.__kat.nodes[node_new] if isinstance(node_old, NodeGaussSetter): @@ -213,7 +214,7 @@ class NodeNetwork(object): """ - if isinstance(node, str): + if isinstance(node, six.string_types): node = self.__kat.nodes[node] if isinstance(node, NodeGaussSetter): @@ -354,7 +355,7 @@ class NodeNetwork(object): return False elif isinstance(currcomp, pykat.components.isolator): - print "isol" + print ("isol") elif isinstance(currcomp, pykat.components.laser): # if we are at a laser then we can't go any further # and it isn;t this node as we checked before @@ -401,13 +402,13 @@ class NodeNetwork(object): of the components it finds between them. """ - if isinstance(from_node, str): + if isinstance(from_node, six.string_types): from_node = self.__kat.nodes[from_node] if isinstance(from_node, NodeGaussSetter): from_node = from_node.node - if isinstance(to_node, str): + if isinstance(to_node, six.string_types): to_node = self.__kat.nodes[to_node] if isinstance(to_node, NodeGaussSetter): diff --git a/pykat/param.py b/pykat/param.py index 785092a41672f0876480c1008bf25bb034647647..e7ac6a3b4e53db471138538c2ec2526c9f0f0282 100644 --- a/pykat/param.py +++ b/pykat/param.py @@ -155,7 +155,7 @@ class Param(putable, putter): #if this param can be put somewhere we need to check if it is if self.isPutable: for a in self.putees: - print "Removing put from {0} {1} to {2} {3}".format(self.owner.name, self.name, a.owner.name, a.name) + print ("Removing put from {0} {1} to {2} {3}".format(self.owner.name, self.name, a.owner.name, a.name)) a._putter = None self.put_count -= 1 @@ -165,7 +165,7 @@ class Param(putable, putter): # check if we have anything being put to us if self.isPutter: if self._putter != None: - print "Removing put from {0} {1} to {2} {3}".format(self._putter.owner.name, self._putter.name, self.owner.name, self.name) + print ("Removing put from {0} {1} to {2} {3}".format(self._putter.owner.name, self._putter.name, self.owner.name, self.name)) self._putter.put_count -= 1 self._putter.putees.remove(self) self._putter = None