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

added Plot_DOFs tool to zero_locks, v similar to the one in awc_tools, updated to use ifo functions

parent 4359ae37
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ import matplotlib.pyplot as plt
import matplotlib.cm as cm
import pykat
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.gridspec as gridspec
import AG_tools as ag
......@@ -34,6 +36,13 @@ DOFAccuracy = {#,abs_accuracy,rel_accuracy
"MICH": [10e-11,1e-7],
"SRCL": [10e-11,1e-7]}
DOFPlotting = {#scan_range,
"CARM": [0.001],
"DARM": [0.01],
"PRCL": [0.1],
"MICH": [0.5],
"SRCL": [1]}
def main():
plt.close("all")
print("""
......@@ -57,14 +66,15 @@ def main():
# ## initial tuning
# zero_locks(kat)
# power_ratios(kat)
plot_DOFs(kat,xscale=10)
# ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
#
# ## applying offset
OffS = DC_offset(kat,debug=True,apply=True)
# OffS = DC_offset(kat,debug=True,apply=True)
# power_ratios(kat)
# ag.plot_QNS(kat,plotit=True,show=True,unlock=True)
make_locks(kat,DCoffset=OffS)
# make_locks(kat,DCoffset=OffS)
def zero_locks(_kat,pretune_precision=1e-5):
......@@ -229,8 +239,16 @@ def DC_offset(_kat,debug=False,apply=False):
# Y=out["P_DC_AS"] #*1e3
Y=(np.abs(out["AS0"])**2)*1e3 #converting to power in mW
idxs = []
f1 = interp1d(Y,X)
f2 = interp1d(X,Y)
try:
EMX_out = f1(AS_power)
pow_out = f2(AS_power)
except:
print("\n Interpolation error, using secondary method.")
idxs = []
for y in range(len(Y)-1):
if Y[y] == AS_power:
idxs.append(y)
......@@ -238,18 +256,14 @@ def DC_offset(_kat,debug=False,apply=False):
idxs.append(y+1)# so we always choose the slightly higher AS power. unnessary if single-sided seach.
elif Y[y+1]<= AS_power and Y[y]>=AS_power:#below phi=0
idxs.append(y)
if len(idxs)!=1:
raise pkex.BasePyKatException("Zero or multiple tuning options found. Check x limits and target power.")
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
_kat.ETMY.phi = -EMX_out
print ("""
AS carrier power found = {0:.4g}mW
......@@ -257,7 +271,7 @@ def DC_offset(_kat,debug=False,apply=False):
new tunings:
ETMX: {1} deg
ETMY: {2} deg
""".format(pow_out,EMX_out,EMY_out))
""".format(pow_out,EMX_out,(-EMX_out)))
if debug == True:
plt.semilogy(X,Y)
......@@ -495,6 +509,59 @@ def tune_via_DARM(_kat,_optic,xlimits=[-100,100],steps=200,debug=False,freq=0.1)
return X_out, stepsize
def plot_DOFs(_kat,xscale=1,steps=200):
print("Plotting Error signals")
_kat=_kat.deepcopy()
_kat.verbose=False
_kat.removeBlock('locks')
plt.figure(figsize=(10,8))
gs = gridspec.GridSpec(3,2)
ax = [plt.subplot(gs[0,0]),
plt.subplot(gs[0,1]),
plt.subplot(gs[1,0]),
plt.subplot(gs[1,1]),
plt.subplot(gs[2,:])]
sp = 0
for _dof in DOFs:
kat = _kat.deepcopy()
info=DOFInfo[_dof]
demod_freq = info[0]
demod_phase = info[1]
optics = ifo.make_list_copy(info[2])
factors = ifo.make_list_copy(info[3])
# sig_phases = ifo.make_list_copy(info[4])
node = info[5]
detname = "{0}_Err".format(_dof)
kat.parseCommands("pd1 {0} {1} {2} {3}".format(detname,demod_freq,demod_phase,node))
xlim = DOFPlotting[_dof][0] * xscale
out = ifo.scan_optics(kat, optics, factors, xlimits=[-xlim, xlim], steps=steps,relative=True)
f1 = interp1d(out[detname], out.x)
f2 = interp1d(out.x, out[detname])
try:
title = "0-Crossing = {0:.3g} deg\noffset (at 0) = {1:.3g}".format(float(f1(0)),float(f2(0)))#ugly line with new str formatting, worked with %.3g...
except:
title = None#"Interpolation error"
ax[sp].ticklabel_format(style="sci", scilimits=(1,2))
ax[sp].set_title(title,fontsize=10)
ax[sp].plot(out.x, out[detname])
ax[sp].set_xlim(out.x.min(), out.x.max())
ax[sp].set_xlabel(_dof + " [Deg]")
ax[sp].set_ylabel(detname)
ax[sp].grid()
sp += 1
plt.tight_layout()
plt.show()
def phi_tuning(deltam,lambda0=1064e-9):
return (deltam/lambda0) *360
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment