aboutsummaryrefslogtreecommitdiff
path: root/examples/lock_eit.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lock_eit.py')
-rw-r--r--examples/lock_eit.py294
1 files changed, 155 insertions, 139 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py
index cc0a1aa..7a3a846 100644
--- a/examples/lock_eit.py
+++ b/examples/lock_eit.py
@@ -34,7 +34,7 @@ def getConfig(apparatus):
config[n]=i.getConfig()
return config
-def initLog():
+def initLog(extra_tags={}):
errorTrace = Trace("error")
errorTrace.config['unit']='V'
timeTrace = Trace("time")
@@ -76,6 +76,7 @@ def initLog():
log.addTrace(eitLog)
log.addTrace(rfPoutLog)
log.config['tags']['apparatus']=getConfig(apparatus)
+ log.config['tags'].update(extra_tags)
return log
async def feedbackLoop(apparatus, nsteps):
@@ -110,6 +111,151 @@ def adjustRFandLog(apparatus):
log.addPointToTrace(rfPout, "rfPout")
log.addPointToTrace(eit, "eit")
+async def initial_lock_to_eit(apparatus, extra_tags={}):
+ rfPout = apparatus.getRFAmplitude()
+ apparatus.state = f'Initial lock RF power {rfPout} dBm'
+ logger.info(apparatus.state)
+ update_webpage(apparatus=apparatus)
+
+ ai = apparatus.instruments
+ apparatus.gui_log.setTraces( initLog(extra_tags=extra_tags) )
+ ai['pid'].reset()
+ ai['pid'].setEnable(True)
+ apparatus.runStatus = True
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=50)
+ )
+
+async def calibratingLockin(apparatus, extra_tags={}):
+ ai = apparatus.instruments
+ rfPout = apparatus.getRFAmplitude()
+ apparatus.state = f'Calibrating lockin response at RF power {rfPout} dBm'
+ logger.info(apparatus.state)
+ update_webpage(apparatus=apparatus)
+ ai['pid'].setEnable(False)
+ ai['pid'].reset()
+ apparatus.gui_log.setTraces( initLog(extra_tags=extra_tags) )
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=20)
+ )
+
+ fr0 = ai['rfgen'].getFreqFixed()
+ df = 10
+ ai['pid'].setEnable(False)
+ ai['pid'].reset()
+ apparatus.setRFreq(fr0+df)
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=20)
+ )
+ apparatus.setRFreq(fr0)
+
+ log = apparatus.gui_log.traces
+ trE=log.getTrace('error')
+
+ e1 = np.mean(trE.y.values[0:20])
+ e2 = np.mean(trE.y.values[20:])
+ dE = e2-e1
+ slope = dE/df
+ apparatus.setLockinSlope(slope)
+
+ logger.info(f'dE = {dE}')
+ logger.info(f'lockin error signal slope = {slope} V/Hz')
+
+ apparatus.getBCurrent(); # this automatically logs value to TSDB
+
+ return float(slope)
+
+async def responseToChangeOfBfieldControlVoltage(apparatus, extra_tags={}):
+ ai = apparatus.instruments
+ rfPout = apparatus.getRFAmplitude()
+ apparatus.state = f'Calibrating lockin response to change of Bfield control voltage, {rfPout} dBm'
+ logger.info(apparatus.state)
+ update_webpage(apparatus=apparatus)
+ ai['pid'].setEnable(True)
+ ai['pid'].reset()
+ apparatus.gui_log.setTraces( initLog(extra_tags=extra_tags) )
+ dV = 0.01
+ ai['lockin'].AuxOut1=dV
+ apparatus.getBCurrent(); # this automatically logs value to TSDB
+
+ # initial lock
+ ai['pid'].setEnable(True)
+ ai['pid'].reset()
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=20)
+ )
+
+ # this is for the money lock
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=30)
+ )
+
+ fr0 = ai['rfgen'].getFreqFixed()
+ apparatus.getBCurrent(); # this automatically logs value to TSDB
+
+ # this is for the money lock
+ ai['lockin'].AuxOut1=0
+ ai['pid'].setEnable(True)
+ ai['pid'].reset()
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=30)
+ )
+ fr1 = ai['rfgen'].getFreqFixed()
+
+ log = apparatus.gui_log.traces
+ trE=log.getTrace('error')
+
+ df = fr0 - fr1
+ slope = df/dV
+
+ logger.info(f'df = {df}')
+ logger.info(f'response to magnetic control voltage = {slope} Hz/V')
+
+ apparatus.getBCurrent(); # this automatically logs value to TSDB
+
+ # relock to default state
+ ai['lockin'].AuxOut1=0
+ ai['pid'].setEnable(True)
+ ai['pid'].reset()
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=20)
+ )
+
+ return float(slope)
+
+async def longTermLock(apparatus, extra_tags={}):
+ ai = apparatus.instruments
+ rfPout = apparatus.getRFAmplitude()
+ apparatus.state = f'Long term lock RF power {rfPout} dBm'
+ logger.info(apparatus.state)
+ apparatus.gui_log.setTraces( initLog(extra_tags=extra_tags) )
+ apparatus.runStatus = True
+ ai['pid'].setEnable(True)
+ update_webpage(apparatus=apparatus)
+
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=10000000)
+ )
+ return res
+
+async def sweepRFPower(apparatus, extra_tags={}, rfPowerList=[]):
+ apparatus.gui_log.setTraces( initLog(extra_tags=extra_tags) )
+ ai = apparatus.instruments
+ # for p in np.linspace(-10,10, 110):
+ ai['pid'].setEnable(True)
+ for p in rfPowerList:
+ ai['rfgen'].setRFAmplitude(p)
+ rfPout = ai['rfgen'].getRFAmplitude()
+ apparatus.state = f'lock with RF power {rfPout} dBm'
+ logger.info(apparatus.state)
+ update_webpage(apparatus=apparatus)
+ ai['pid'].reset()
+ apparatus.runStatus = True
+ res = await asyncio.gather(
+ feedbackLoop(apparatus, nsteps=50)
+ )
+ return res
+
freqZero = 6834686400
freqDeltaMp2 = 6835387100
@@ -180,150 +326,20 @@ async def main():
d=getConfig(apparatus)
instruments_config=gui.QOLDictionary(a=wp, name='Instruments configs', container=d)
+ extra_tags={}
- logger.info('========== Initial lock ===========')
- rfPout = apparatus.getRFAmplitude()
- apparatus.state = f'Initial lock RF power {rfPout} dBm'
- logger.info(apparatus.state)
- update_webpage(apparatus=apparatus)
- apparatus.gui_log.setTraces( initLog() )
- ai['pid'].reset()
- ai['pid'].setEnable(True)
- apparatus.runStatus = True
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=50)
- )
-
- async def calibratingLockin():
- apparatus.state = f'Calibrating lockin response at RF power {rfPout} dBm'
- logger.info(apparatus.state)
- update_webpage(apparatus=apparatus)
- ai['pid'].setEnable(False)
- ai['pid'].reset()
- apparatus.gui_log.setTraces( initLog() )
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=20)
- )
-
- fr0 = ai['rfgen'].getFreqFixed()
- df = 10
- ai['pid'].setEnable(False)
- ai['pid'].reset()
- apparatus.setRFreq(fr0+df)
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=20)
- )
- apparatus.setRFreq(fr0)
+ await initial_lock_to_eit(apparatus, extra_tags=extra_tags)
- log = apparatus.gui_log.traces
- trE=log.getTrace('error')
+ lockin_slope= await calibratingLockin(apparatus, extra_tags=extra_tags)
+ extra_tags.update( {'error_signal_response_to_eit_detuning_in_V_per_Hz' : lockin_slope } )
- e1 = np.mean(trE.y.values[0:20])
- e2 = np.mean(trE.y.values[20:])
- dE = e2-e1
- slope = dE/df
- apparatus.setLockinSlope(slope)
+ B_response= await responseToChangeOfBfieldControlVoltage(apparatus, extra_tags=extra_tags)
+ extra_tags.update( {'EIT_shift_to_B_control_Voltage_in_Hz_per_V' : B_response } )
- logger.info(f'dE = {dE}')
- logger.info(f'lockin error signal slope = {slope} V/Hz')
+ # await sweepRFPower(apparatus, extra_tags=extra_tags, rfPowerList=rfPowerList)
- apparatus.getBCurrent(); # this automatically logs value to TSDB
+ await longTermLock(apparatus, extra_tags=extra_tags)
- return slope
-
- lockin_slope= await calibratingLockin()
-
- async def responseToChangeOfBfieldControlVoltage():
- apparatus.state = f'Calibrating lockin response to change of Bfield control voltage, {rfPout} dBm'
- logger.info(apparatus.state)
- update_webpage(apparatus=apparatus)
- ai['pid'].setEnable(True)
- ai['pid'].reset()
- apparatus.gui_log.setTraces( initLog() )
- dV = 0.01
- ai['lockin'].AuxOut1=dV
- apparatus.getBCurrent(); # this automatically logs value to TSDB
-
- # initial lock
- ai['pid'].setEnable(True)
- ai['pid'].reset()
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=20)
- )
-
- # this is for the money lock
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=30)
- )
-
- fr0 = ai['rfgen'].getFreqFixed()
- apparatus.getBCurrent(); # this automatically logs value to TSDB
-
- # this is for the money lock
- ai['lockin'].AuxOut1=0
- ai['pid'].setEnable(True)
- ai['pid'].reset()
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=30)
- )
- fr1 = ai['rfgen'].getFreqFixed()
-
- log = apparatus.gui_log.traces
- trE=log.getTrace('error')
-
- df = fr0 - fr1
- slope = df/dV
-
- logger.info(f'df = {df}')
- logger.info(f'response to magnetic control voltage = {slope} Hz/V')
-
- apparatus.getBCurrent(); # this automatically logs value to TSDB
-
- # relock to default state
- ai['lockin'].AuxOut1=0
- ai['pid'].setEnable(True)
- ai['pid'].reset()
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=20)
- )
-
- return slope
-
- B_response= await responseToChangeOfBfieldControlVoltage()
-
- logger.info('========= Long term lock ===========')
- apparatus.gui_log.setTraces( initLog() )
- apparatus.gui_log.traces.config['tags']['lockin_slope']=float(lockin_slope)
- apparatus.runStatus = True
-
- async def longTermLock():
- apparatus.state = f'Long term lock RF power {rfPout} dBm'
- ai['pid'].setEnable(True)
- logger.info(apparatus.state)
- update_webpage(apparatus=apparatus)
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=10000000)
- )
- return res
-
- async def sweepRFPower():
- # for p in np.linspace(-10,10, 110):
- ai['pid'].setEnable(True)
- for p in rfPowerList:
- ai['rfgen'].setRFAmplitude(p)
- rfPout = ai['rfgen'].getRFAmplitude()
- apparatus.state = f'Long term lock RF power {rfPout} dBm'
- logger.info(apparatus.state)
- update_webpage(apparatus=apparatus)
- ai['pid'].reset()
- apparatus.runStatus = True
- res = await asyncio.gather(
- feedbackLoop(apparatus, nsteps=50)
- )
- return res
-
- # await sweepRFPower()
- await longTermLock()
apparatus.state = 'Done working with hardware'
logger.info(apparatus.state)