diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-06-02 00:10:19 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-06-02 00:10:19 -0400 |
commit | 78f979e9985b387ae530fe8053ab2440614887cb (patch) | |
tree | 18b345aa0092fcdae517fcc0c3047cd5bf5e66d2 /examples/eit_with_vcsel.py | |
parent | b4c843be5a1d00b561de59383827783ed69b3bfa (diff) | |
download | qolab-78f979e9985b387ae530fe8053ab2440614887cb.tar.gz qolab-78f979e9985b387ae530fe8053ab2440614887cb.zip |
added class to set Bfield
Diffstat (limited to 'examples/eit_with_vcsel.py')
-rw-r--r-- | examples/eit_with_vcsel.py | 126 |
1 files changed, 81 insertions, 45 deletions
diff --git a/examples/eit_with_vcsel.py b/examples/eit_with_vcsel.py index daa021b..25e87fe 100644 --- a/examples/eit_with_vcsel.py +++ b/examples/eit_with_vcsel.py @@ -39,6 +39,80 @@ class Apparatus(BasicInstrument): config[n]=i.getConfig() return config +class BfieldDriver(KeysightE3612A): + """ need to set power supply """ + def __init__(self, *args, **kwds): + super().__init__(*args, **kwds) + self.config['Device model'] = 'B field coil driver based on Keysight E3612A' + self.deviceProperties.add('B') + """" + Rough magnetic field calibration of the 3 axes coils in large magnetic shield + - Ch1: 70mA -> 650 kHz shift for delta m = 2 + - Ch2: 70mA -> 700 kHz shift for delta m = 2 + - Ch2: 70mA -> 659 kHz shift for delta m = 2 + A better calibration obtained on 20220601 see file + 20220601.magnetic_field_callibration/calibration_currentToB.dat + """ + # B response to current in a given channel + self.Bslope_TperA = { + 1: 0.0006574710928926532, + 2: 0.0007064314754023079, + 3: 0.0006635058865577695 + } + # assuming that Ch1 controls Bz, Ch2 -> By, Ch3 -> Bx + self.chX=3; self.chY=2; self.chZ=1 + + def getB(self): + Bslope_TperA = self.Bslope_TperA + chX = self.chX + chY = self.chY + chZ = self.chZ + + Ix = self.getChanIout(chX) + Iy = self.getChanIout(chY) + Iz = self.getChanIout(chZ) + Bx = Ix * Bslope_TperA[chX] + By = Iy * Bslope_TperA[chY] + Bz = Iz * Bslope_TperA[chZ] + Bmag = np.sqrt(Bx*Bx + By*By + Bz*Bz) + theta = np.arccos(Bz/Bmag) + phi = np.arctan2(By, Bx) + return { 'Bmag': float(Bmag), 'theta': float(theta), 'phi': float(phi), + 'Bx': float(Bx), + 'By': float(By), + 'Bz': float(Bz), + } + + def setB(self, Bmag=50e-6, theta=0, phi=0): + """ Sets B field currents based on B (in T) and angles theta, and phi """ + self._Bmag = Bmag + self._theta = theta + self._phi = phi + + Bx = Bmag*np.sin(theta)*np.cos(phi) + By = Bmag*np.sin(theta)*np.sin(phi) + Bz = Bmag*np.cos(theta) + + Bslope_TperA = self.Bslope_TperA + chX = self.chX + chY = self.chY + chZ = self.chZ + + Ix = Bx / Bslope_TperA[chX] + Iy = By / Bslope_TperA[chY] + Iz = Bz / Bslope_TperA[chZ] + + logger.info(f"Setting {chX=} to {Ix}") + logger.info(f"Setting {chY=} to {Iy}") + logger.info(f"Setting {chZ=} to {Iz}") + # self.setChanIout(chX, Ix) + # self.setChanIout(chY, Iy) + # self.setChanIout(chZ, Iz) + return Ix, Iy, Iz + + def setBinDegrees(self, Bmag=50e-6, theta=0, phi=0): + return self.setB(Bmag=Bmag, theta=theta/180*np.pi, phi=phi/180*np.pi) + # TSDB logger setting tsdb_client = tsdb.Client('influx', 'http://lumus.physics.wm.edu:8428', database='qolab') tsdb_ingester = tsdb.Ingester(tsdb_client, batch=11, measurement_prefix='VAMPIRE.VCSEL') @@ -56,7 +130,9 @@ apparatus.config['SavePath'] = './data' logger.info("Accessing hardware") rm = pyvisa.ResourceManager() instr=rm.open_resource('USB0::10893::4354::MY61001869::0::INSTR') -ps = KeysightE3612A(instr, device_nickname='.'.join([app_nickname, 'coil_driver']), tsdb_ingester=tsdb_ingester) +Bfield = BfieldDriver(instr, device_nickname='.'.join([app_nickname, 'b_field_driver']), tsdb_ingester=tsdb_ingester) +ps = Bfield # alias +# ps = KeysightE3612A(instr, device_nickname='.'.join([app_nickname, 'coil_driver']), tsdb_ingester=tsdb_ingester) if platform.system() == 'Linux': rfgen_port='/dev/ttyUSB0' @@ -72,7 +148,7 @@ apparatus.instruments={} ai = apparatus.instruments ai['rfgen'] = rfgen ai['daq'] = daq -ai['coil_driver'] = ps +ai['b_field_driver'] = Bfield logger.info('Setting magnetic field coils currents') @@ -81,46 +157,6 @@ logger.info('Setting magnetic field coils currents') # ps.setChanIout_mA(3, 0) logger.info('Done setting magnetic field coils currents') -def setB(B=50e-6, theta=0, phi=0): - """ Sets B field currents based on B (in T) and angles theta, and phi """ - - """ - Rough magnetic field calibration of the 3 axes coils in large magnetic shield - - Ch1: 70mA -> 650 kHz shift for delta m = 2 - - Ch2: 70mA -> 700 kHz shift for delta m = 2 - - Ch2: 70mA -> 659 kHz shift for delta m = 2 - A better calibration obtained on 20220601 see file - 20220601.magnetic_field_callibration/calibration_currentToB.dat - """ - # B response to current in a given channel - Bslope_TperA = { - 1: 0.0006574710928926532, - 2: 0.0007064314754023079, - 3: 0.0006635058865577695 - } - - Bx = B*np.sin(theta)*np.cos(phi) - By = B*np.sin(theta)*np.sin(phi) - Bz = B*np.cos(theta) - - # assuming that Ch1 controls Bz, Ch2 -> By, Ch3 -> Bx - chX=3; chY=2; chZ=1 - - Ix = Bx / Bslope_TperA[chX] - Iy = By / Bslope_TperA[chY] - Iz = Bz / Bslope_TperA[chZ] - - logger.info(f"Setting {chX=} to {Ix}") - logger.info(f"Setting {chY=} to {Iy}") - logger.info(f"Setting {chZ=} to {Iz}") - # ps.setChanIout(chX, Ix) - # ps.setChanIout(chY, Iy) - # ps.setChanIout(chZ, Iz) - return Ix, Iy, Iz - -def setBdegrees(B=50e-6, theta=0, phi=0): - return setB(B=B, theta=theta/180*np.pi, phi=phi/180*np.pi) - def eitSweep(central_frequency, frequency_span, Np, Nsweeps=1): frList = np.linspace(central_frequency-frequency_span/2, central_frequency+frequency_span/2, Np) trFreq=Trace('Frequency') @@ -177,17 +213,17 @@ def calibrateCoilsCurrent(): def rotateBandGetEITtrace(): Np=100 Nsweeps=1 - B=50e-6 # earth magnetic field in Tesla (0.5 G) + Bmag=50e-6 # earth magnetic field in Tesla (0.5 G) phiStep = 5 thetaStep = 5 phiSet = range(0,90+phiStep, phiStep) thetaSet = range(0,90+thetaStep, thetaStep) for phi in phiSet: for theta in thetaSet: - setBdegrees(B=B, theta=theta, phi=phi) + Bfield.setBinDegrees(Bmag=Bmag, theta=theta, phi=phi) trEIT = eitSweep(central_frequency, frequency_span, Np, Nsweeps=Nsweeps) fn = apparatus.getNextDataFile() - logger.info(f'Data ready for {B=} in {theta=} {phi=}') + logger.info(f'Data ready for {Bmag=} in {theta=} {phi=}') logger.info(f'Data saved to {fn=}') trEIT.save(fn) |