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.py92
1 files changed, 70 insertions, 22 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py
index e707223..6ca0452 100644
--- a/examples/lock_eit.py
+++ b/examples/lock_eit.py
@@ -94,18 +94,14 @@ def adjustRFandLog(apparatus):
pid = ai['pid']
log = apparatus.gui_log.traces
- ch1=scope.getTrace(1, decimate=False)
- ch3=scope.getTrace(3, decimate=False)
- err = np.mean(ch1.y.values)
- eit = np.mean(ch3.y.values)
+ err = apparatus.getErr()
+ eit = apparatus.getEIT()
fdbck = pid.feedback(err)
- freq0 = rfgen.getFreqFixed()
- freq = freq0 + fdbck
- rfgen.setFreqFixed(freq)
- # print(f'error = {err}, feedback = {fdbck}, request freq = {freq}')
+ freq0 = apparatus.getRFreq()
+ apparatus.setFeefback(fdbck)
- rfPout = ai['rfgen'].getRFAmplitude()
+ rfPout = apparatus.getRFAmplitude()
log.addPointToTrace(timenow)
log.addPointToTrace(err, "error")
@@ -121,15 +117,8 @@ dfB = freqDeltaMp2 - freqZero
freqDeltaMm2 = freqZero - dfB;
async def main():
- tsdb_client = tsdb.Client('influx', 'http://lumus.physics.wm.edu:8428', database='qolab')
- tsdb_ingester = tsdb.Ingester(tsdb_client, batch=11, measurement_prefix='VAMPIRE.HighPower')
task_wp_update_loop = asyncio.create_task(update_webpage_loop(update_interval=1))
- apparatus.config['Device type'] = 'QOL VAMPIRE HighPower magnetometer'
- apparatus.config['Device model'] = 'v0.1'
- apparatus.config['FnamePrefix'] = 'locked_magnetometer'
- apparatus.config['SavePath'] = '/mnt/qol_grp_data/data.VAMPIRE.HighPower'
- # apparatus.config['SavePath'] = './data'
apparatus.gui_log = gui.QOLTimeLog(a=wp)
apparatus.gui_log.save_controls.getNextDataFile = apparatus.getNextDataFile
@@ -165,20 +154,20 @@ async def main():
ai['rfgen'].stopFrequencySweep()
# ai['rfgen'].setFreqFixed(freqDeltaMm2)
# ai['rfgen'].setFreqFixed(freqZero)
- ai['rfgen'].setFreqFixed(freqDeltaMp2)
+ apparatus.setRFreq(freqDeltaMp2)
rfPstart = -10
rfPstop = 10
rfPowerList = np.linspace(rfPstart, rfPstop, 11)
rfPower0 = rfPstart
rfPower0 = 3.4
- ai['rfgen'].setRFAmplitude(rfPower0)
+ apparatus.setRFAmplitude(rfPower0)
d=getConfig(apparatus)
instruments_config=gui.QOLDictionary(a=wp, name='Instruments configs', container=d)
logger.info('========== Initial lock ===========')
- rfPout = ai['rfgen'].getRFAmplitude()
+ rfPout = apparatus.getRFAmplitude()
apparatus.state = f'Initial lock RF power {rfPout} dBm'
logger.info(apparatus.state)
update_webpage(apparatus=apparatus)
@@ -205,11 +194,11 @@ async def main():
df = 10
ai['pid'].setEnable(False)
ai['pid'].reset()
- ai['rfgen'].setFreqFixed(fr0+df)
+ apparatus.setRFreq(fr0+df)
res = await asyncio.gather(
feedbackLoop(apparatus, nsteps=20)
)
- ai['rfgen'].setFreqFixed(fr0)
+ apparatus.setRFreq(fr0)
log = apparatus.gui_log.traces
trE=log.getTrace('error')
@@ -218,6 +207,7 @@ async def main():
e2 = np.mean(trE.y.values[20:])
dE = e2-e1
slope = dE/df
+ apparatus.setLockinSlope(slope)
logger.info(f'dE = {dE}')
logger.info(f'slope = {slope}')
@@ -288,10 +278,68 @@ async def getPage():
async def jp_startup():
jp.run_task(main())
+
+class Apparatus(BasicInstrument):
+ def __init__(self, *args, **kwds):
+ super().__init__(*args, **kwds)
+ self.setLockinSlope(0)
+
+ @BasicInstrument.tsdb_append
+ def getErr(self):
+ scope = self.instruments['scope']
+ ch1=scope.getTrace(1, decimate=False)
+ err = np.mean(ch1.y.values)
+ return err
+
+ @BasicInstrument.tsdb_append
+ def getEIT(self):
+ scope = self.instruments['scope']
+ ch3=scope.getTrace(3, decimate=False)
+ eit = np.mean(ch3.y.values)
+ return eit
+
+ @BasicInstrument.tsdb_append
+ def setFeefback(self, val):
+ freq0 = self.getRFreq()
+ self.setRFreq(freq0+val)
+
+ @BasicInstrument.tsdb_append
+ def getRFreq(self):
+ rfgen = self.instruments['rfgen']
+ return rfgen.getFreqFixed()
+
+ @BasicInstrument.tsdb_append
+ def setRFreq(self,val):
+ rfgen = self.instruments['rfgen']
+ rfgen.setFreqFixed(val)
+
+ @BasicInstrument.tsdb_append
+ def getRFAmplitude(self):
+ rfgen = self.instruments['rfgen']
+ return rfgen.getRFAmplitude()
+
+ @BasicInstrument.tsdb_append
+ def setRFAmplitude(self, val):
+ rfgen = self.instruments['rfgen']
+ return rfgen.setRFAmplitude(val)
+
+ @BasicInstrument.tsdb_append
+ def setLockinSlope(self, val):
+ self.lockin_slope=val
+
+
if __name__ == '__main__':
logger.info('========== Start up ===========')
+ tsdb_client = tsdb.Client('influx', 'http://lumus.physics.wm.edu:8428', database='qolab')
+ tsdb_ingester = tsdb.Ingester(tsdb_client, batch=11, measurement_prefix='VAMPIRE.HighPower')
+
wp = jp.WebPage(delete_flag=False)
- apparatus = BasicInstrument()
+ apparatus = Apparatus(tsdb_ingester=tsdb_ingester, device_nickname='magnetometer',)
+ apparatus.config['Device type'] = 'QOL VAMPIRE HighPower magnetometer'
+ apparatus.config['Device model'] = 'v0.1'
+ apparatus.config['FnamePrefix'] = 'locked_magnetometer'
+ apparatus.config['SavePath'] = '/mnt/qol_grp_data/data.VAMPIRE.HighPower'
+ # apparatus.config['SavePath'] = './data'
d=jp.Div(text='Magnetometer log', a=wp, classes='text-white bg-blue-500 text-center text-xl')