#!/usr/bin/python
 #script for setting the offsets of the transmon QPDs when you have found a better location for the soft offsets, and moving the offsets from the loops to the QPDS

import ezca
ezca=ezca.Ezca(logger=False)
import cdsutils

#set long TRAMPS so you can ramp down the soft loop offsets while you ramp on the QPD offsets

for arm in ['X', 'Y']:
    for qpd in ['A', 'B']:
        for dof in ['PIT', 'YAW']:
             ezca['ASC-%s_TR_%s_%s_TRAMP' % (arm, qpd, dof)]= 60

for soft_loop in ['CSOFT', 'DSOFT']:
    for dof in ['P', 'Y']:
        ezca['ASC-%s_%s_TRAMP'%(soft_loop,dof)]=60

#take averages of the QPD values that you like
mydict={}

for arm in ['X', 'Y']:
    for qpd in ['A', 'B']:
        for dof in ['PIT', 'YAW']:
            mydict['ASC-%s_TR_%s_%s_OFFSET' % (arm, qpd, dof)] = -1* cdsutils.avg(5, 'ASC-%s_TR_%s_%s_INMON'%(arm,qpd,dof))

#put the QPD offsets in and remove the soft offsets
for arm in ['X', 'Y']:
    for qpd in ['A', 'B']:
        for dof in ['PIT', 'YAW']:
             ezca['ASC-%s_TR_%s_%s_OFFSET' % (arm, qpd, dof)]= mydict['ASC-%s_TR_%s_%s_OFFSET' % (arm, qpd, dof)]

for soft_loop in ['CSOFT', 'DSOFT']:
    for dof in ['P', 'Y']:
        ezca.switch('ASC-%s_%s'%(soft_loop,dof), 'OFFSET', 'OFF')


#set TRAMPS back to something reasonable

for arm in ['X', 'Y']:
    for qpd in ['A', 'B']:
        for dof in ['PIT', 'YAW']:
             ezca['ASC-%s_TR_%s_%s_TRAMP' % (arm, qpd, dof)]= 2

for soft_loop in ['CSOFT', 'DSOFT']:
    for dof in ['P', 'Y']:
        ezca['ASC-%s_%s_TRAMP'%(soft_loop,dof)]=2
