Skip to content
Snippets Groups Projects
Commit 4359ae37 authored by Anna Green's avatar Anna Green
Browse files

adding kat code for lock block. working on offset for DARM errsig

parent 83aea161
Branches
No related tags found
No related merge requests found
......@@ -54,17 +54,17 @@ def main():
kat = LIGO1.kat
kat.maxtem=0#'off'
## initial tuning
zero_locks(kat)
power_ratios(kat)
make_locks(kat)
ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
# ## initial tuning
# zero_locks(kat)
# power_ratios(kat)
# ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
#
# ## applying offset
OffS = DC_offset(kat,debug=True,apply=True)
# power_ratios(kat)
# ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
## applying offset
DC_offset(kat)
power_ratios(kat)
ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
make_locks(kat,DCoffset=OffS)
def zero_locks(_kat,pretune_precision=1e-5):
......@@ -210,7 +210,8 @@ def power_ratios(_kat):
def DC_offset(_kat,AS_power = 100,debug=False):
def DC_offset(_kat,debug=False,apply=False):
AS_power = 100
print("""
DC offset:
----------------------------------------------
......@@ -224,7 +225,7 @@ def DC_offset(_kat,AS_power = 100,debug=False):
scale=5e-3
kat.parseCommands("ad AS0 0 nSRM2") # adding a detector just looking at the carrier field.
out=ifo.scan_optics(kat,["ETMX","ETMY"],[1.0,-1.0],xlimits=[phiX0,phiX0+scale])
X=out.x #m_tuning(out.x)*2e12
X=out.x
# Y=out["P_DC_AS"] #*1e3
Y=(np.abs(out["AS0"])**2)*1e3 #converting to power in mW
......@@ -242,10 +243,14 @@ def DC_offset(_kat,AS_power = 100,debug=False):
raise pkex.BasePyKatException("Zero or multiple tuning options found. Check x limits and target power.")
_kat.ETMX.phi = EMX_out = X[idxs[0]]
_kat.ETMY.phi = EMY_out = -X[idxs[0]]
EMX_out = X[idxs[0]]
EMY_out = -X[idxs[0]]
pow_out = Y[idxs[0]]
if apply == True:
_kat.ETMX.phi = EMX_out
_kat.ETMY.phi = EMY_out
print ("""
AS carrier power found = {0:.4g}mW
......@@ -257,7 +262,7 @@ def DC_offset(_kat,AS_power = 100,debug=False):
if debug == True:
plt.semilogy(X,Y)
plt.semilogy(EMX_out,pow_out,'o')
plt.xlabel('DARM')
plt.xlabel('DARM [deg]')
plt.ylabel("AS power [mW]")
plt.xlim(min(X),max(X))
plt.show()
......@@ -265,9 +270,10 @@ def DC_offset(_kat,AS_power = 100,debug=False):
print("""
----------------------------------------------
""")
return EMX_out
def make_locks(_kat,acc="absolute"):
def make_locks(_kat,acc="absolute",debug=False,DCoffset=0):
print("""
MAKE LOCKS:
----------------------------------------------
......@@ -275,35 +281,17 @@ def make_locks(_kat,acc="absolute"):
kat=_kat.deepcopy()
print("Removing components, commands and blocks")
# ifo.remove_components(kat, ["mod1", "lmod2", "mod2", "lmod3"], component_in="lmod1")
kat.removeBlock('locks')
# kat.removeBlock('errsigs')
kat.removeBlock('Powers')
ifo.make_transparent(kat,["BSAR1", "BSAR2"])
### goal here :
### produce this code:
## lock PRCL_lock $PRCL_err -2.769589345492097 10u
## lock MICH_lock $MICH_err 12.029218280984777 10u
## lock CARM_lock $CARM_err 0.0001193478133584417 10u
## lock DARM_lock $DARM_err -0.002325573315055089 10u
## lock SRCL_lock $SRCL_err -4.886172716885925 10u
# print('\nDARM TF with SRM tuning {0}'.format(kat.SRM.phi))
# plt.figure()
# ag.plot_DARMTF(kat, xstart=1e-4, xend=1e4, plotit=True,show=False)
# kat.SRM.phi -= 90
# print('\nrerunning DARM TF with SRM tuning {0}'.format(kat.SRM.phi))
# ag.plot_DARMTF(kat, xstart=1e-4, xend=1e4, plotit=True,show=True)
# kat.SRM.phi +=90
if acc not in ["absolute","relative"]:
raise pkex.BasePyKatException("accuracy group must be in {0}")
print("""
accuracy level selected: {0}
""".format(acc))
DOFLocks=[]
DOF_locks={}
for d in DOFs:
......@@ -316,7 +304,8 @@ def make_locks(_kat,acc="absolute"):
optical gain of err sig TF at 0.1Hz: {1:.4g}
==> lock gain = {2:.4g}""".format(d,OG,LG))
# DOF_TF(kat,d,plot=True)
if debug == True:
DOF_TF(kat,d,plot=True)
##2. accuracies - [W; threshold: posn/gain<this] (all to same scale, DARM highest). Abs and rel values dependent on task
if acc == "absolute":
......@@ -329,31 +318,83 @@ def make_locks(_kat,acc="absolute"):
print(" ==> lock accuracy = {0:.4g}".format(LA))
lockline = "lock {0}_lock ${0}_err {1} {2}".format(d,LG,LA)
DOFLocks.append(lockline)
DOF_locks[d] = [LG,LA]
print("\n ------ lock code (PRELIMINARY)")
for d in DOFLocks:
print(d)
# _kat.parseCommands(d) #once in final form, within lockblock -- via ag.lock_update?
# kat.parseCommands("""
# fsig TFfreq PRM 1 0
# pd2 DOF_TF $f2 13 1 0 nPOP
# put DOF_TF f2 $x1
# xaxis TFfreq f log 1e-2 1e3 200
# yaxis log abs
# """)
# out=kat.run()
# plt.figure()
# plt.loglog(out.x, np.abs(out["DOF_TF"]))
# plt.show()
phi_detune = DCoffset#DC_offset(_kat)
DC_off = phi_detune / DOF_locks["DARM"][0] #units?? want [W], LG is m/W
print("DARM error offset calculation: {0} ---check units!!.".format(DC_off))
write_lockblock(kat,DOF_locks)
print("""
----------------------------------------------
""")
return
def write_lockblock(_kat,DOF_locks):
## all prints() will be updated to _kat.parseCommands() once working
#_kat.removeBlock('locks')
DC_off = '0.728491141201167 #UPDATE<<<<<<<<<<'
print("""
%%% FTblock locks
###########################################################################
set PRCL_err POP_f1_I re
set MICH_err POP_f2_Q re
set CARM_err REFL_f1_I re
set SRCL_err REFL_f2_I re
set AS_f2_I_re AS_f2_I re
func DARM_err = $AS_f2_I_re - {0}
""".format(DC_off))
for d in DOFs:
print(" lock {0}_lock ${0}_err {1} {2}".format(d,DOF_locks[d][0],DOF_locks[d][1]))
print("""
#UPDATE funcs<<<<<<<<<<<<
func mMICH_lock = 0 - $MICH_lock
func ETMX_lock = $CARM_lock + $MICH_lock + $DARM_lock
func ETMY_lock = $CARM_lock - $MICH_lock - $DARM_lock
""")
# put* PRM phi $PRCL_lock
# put* PRMAR phi $PRCL_lock
#
# put* ITMX phi $MICH_lock
# put* ITMXAR phi $MICH_lock
# put* ITMY phi $mMICH_lock
# put* ITMYAR phi $mMICH_lock
#
# put* ETMX phi $ETMX_lock
# put* ETMXAR phi $ETMX_lock
#
# put* ETMY phi $ETMY_lock
# put* ETMYAR phi $ETMY_lock
#
# put* SRM phi $SRCL_lock
print("""
# ADD PUT* functions <<<<<<
noplot PRCL_lock
noplot SRCL_lock
noplot MICH_lock
noplot DARM_lock
noplot CARM_lock
noplot mMICH_lock
noplot ETMX_lock
noplot ETMY_lock
###########################################################################
%%% FTend locks
""")
def DOF_TF(_kat,_dof,plot=False,debug=False,freq=0.1):
......@@ -454,7 +495,7 @@ def tune_via_DARM(_kat,_optic,xlimits=[-100,100],steps=200,debug=False,freq=0.1)
return X_out, stepsize
def phi_accuracy(deltam,lambda0=1064e-9):
def phi_tuning(deltam,lambda0=1064e-9):
return (deltam/lambda0) *360
def m_tuning(phi,lambda0=1064e-9):
......@@ -462,99 +503,3 @@ def m_tuning(phi,lambda0=1064e-9):
if __name__ == '__main__':
main()
\ No newline at end of file
# def DARMandSRM(_kat, xstart=0.5, xend=1e5, ystart=85, yend=95, steps=100, verbose=False):
# import matplotlib.pyplot as pl
# import pykat
#
# kat = _kat.deepcopy()
# kat.verbose = True
#
# kat.parseCommands("""
# fsig darm LXarm 1 0
# fsig darm2 LYarm 1 180
# pd1 Ac 10 nSRM2
# put Ac f1 $x1
# xaxis darm f log {0} {1} {2}
# x2axis SRM phi lin {3} {4} {2}
# yaxis log abs
# """.format(xstart,xend,steps,ystart,yend))
# out = kat.run()
#
# HeatMap(out['Ac'],[xstart,xend],[ystart,yend], xlabel='X vals', ylabel='Y vals', zlabel='Z vals')
#
# # pl.loglog(out.x, out["Ac"],linewidth=2)
# # pl.title('DARM transfer function', fontsize=16)
# # pl.xlabel('GW Frequency [$Hz$]', fontsize=14)
# # pl.ylabel(' Amplitude of TF', fontsize=14)
# # pl.grid(b=True, which='major', color='0.65',linestyle='--')
# # pl.xlim(min(out.x), max(out.x))
# # pl.tight_layout()
# # pl.show()
# def tuning_finder(kat,optic,detector,secondoptic=None,accuracy=1e-7):
# #scan from -100 to +100 deg in 200 steps
# print("""
# tuning {0}:""".format(optic))
# phi,stepsize = scanphi(kat,optic,detector, secondoptic=secondoptic)
# #scan phi +/- zoom in 200 steps
# zoom = 1
# while stepsize > phi_accuracy(accuracy):
# phi,stepsize = scanphi(kat,optic,detector, secondoptic=secondoptic,xmin=phi-zoom, xmax=phi+zoom)
# zoom *= 0.01
# phi_out=phi
# print("""
# ---- final phi value for {0} is {1:g} deg, = {2:g} m
# ----------------------------------------------
# """.format(optic,phi_out, m_tuning(phi_out)))
# return phi_out
# def scanphi(kat,optic,detector,secondoptic=None, xmin=-100, xmax=100, steps=200,minmax='max'):
# from pykat import finesse, commands
# import matplotlib.pyplot as pl
# import peakdetect as pd
#
# kat = kat.deepcopy()
# kat.removeBlock('locks')
#
# kat.parseCommands("""
# xaxis {0} phi lin {1} {2} {3}
# """.format(optic, xmin, xmax, steps))
#
# if secondoptic is not None:
# kat.parseCommands("""
# put {0} phi $x1""".format(secondoptic))
#
# out = kat.run()
#
# stepsize = out.x[1]-out.x[0]
#
# print('stepsize for this run was {0:g}, =max precision on phi'.format(stepsize))
#
# pl.figure()
#
# pl.plot(out.x,out[detector])
#
# _max, _min = pd.peakdetect( out[detector],out.x, 1)
#
# if minmax == 'max':
# X = [p[0] for p in _max]
# Y = [p[1] for p in _max]
# X_out = X[Y.index(max(Y))]
# Y_out = max(Y)
# elif minmax == 'min':
# X = [p[0] for p in _min]
# Y = [p[1] for p in _min]
# X_out = X[Y.index(min(Y))]
# Y_out = min(Y)
# else:
# print("########### error with min/max definition in scanphi()")
# return
#
# pl.plot(X_out,Y_out,'o')
#
# pl.xlabel('{0} tuning [deg]'.format(optic))
# pl.ylabel('{0} output'.format(detector))
# pl.show()
# return X_out,stepsize
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment