Skip to content

Instantly share code, notes, and snippets.

@tspspi
Created March 2, 2023 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspspi/6c802e7e8f0819667a1fef52d859aed7 to your computer and use it in GitHub Desktop.
Save tspspi/6c802e7e8f0819667a1fef52d859aed7 to your computer and use it in GitHub Desktop.
Fitting function for QUAK/ESR bias amplifiers
import matplotlib.pyplot as plt
import numpy as np
import sys
from time import sleep
from pymso5000.mso5000 import MSO5000
from pyka3005p.ka3005pserial import KA3005PSerial
scanchannel = 2
nScans = 5
scanrange = np.linspace(0, 10, 11*10)
with MSO5000(address = "10.0.0.123", useNumpy = True) as mso:
mso.set_channel_enable(scanchannel, True)
with KA3005PSerial('/dev/ttyU0', False) as psu:
fig, ax = plt.subplots(2, figsize=(6.4*10, 4.8*2*10))
psu.setVoltage(0)
psu.setCurrent(0.1)
sleep(0.5)
psu.setChannelEnable(True)
# Now run nScans scans
voltagesIn = scanrange
voltagesOut = np.zeros((nScans, len(voltagesIn)))
voltagesOutStd = np.zeros((len(voltagesIn),))
voltagesOutMean = np.zeros((len(voltagesIn),))
for iScan in range(nScans):
for iPoint, pt in enumerate(voltagesIn):
psu.setVoltage(pt)
sleep(0.5)
# Measure on MSO
mso.force_trigger()
sleep(0.2)
data = mso.query_waveform(scanchannel-1, stats = [ "mean" ])
# Why does stats = mean not work?!?!
voltagesOut[iScan, iPoint] = np.mean(data['y'])
ax[0].plot(voltagesIn, voltagesOut[iScan], label = f"Scan {iScan}")
for iP in range(len(voltagesIn)):
voltagesOutStd[iP] = np.std(voltagesOut[:,iP])
voltagesOutMean[iP] = np.mean(voltagesOut[:,iP])
data = {
"voltageIn" : voltagesIn,
f"voltageOut{scanchannel}raw" : voltagesOut,
f"voltageOut{scanchannel}mean" : voltagesOutMean,
f"voltageOut{scanchannel}std" : voltagesOutStd
}
np.savez(f"channel{scanchannel}.", **data)
ax[1].errorbar(voltagesIn, voltagesOutMean, voltagesOutStd)
ax[0].set_xlabel("Voltage In [V]")
ax[0].set_ylabel("Voltage Out [V]")
ax[0].set_title("Measurements")
ax[0].grid()
ax[1].set_xlabel("Voltage In [V]")
ax[1].set_ylabel("Voltage Out [V]")
ax[1].set_title("Average")
ax[1].grid()
plt.savefig(f"channel{scanchannel}.png")
plt.savefig(f"channel{scanchannel}.svg")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment