-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBruKitchen.py
More file actions
64 lines (54 loc) · 2.25 KB
/
BruKitchen.py
File metadata and controls
64 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
#
# utilities to work with bruker NMR/MRI systems
#
# (c)2016 Michael Tesch. tesch1@gmail.com
#
import logging
import math
class Spectrometer(object):
''' Spectrometer hardware and setup functionality '''
log = logging.getLogger('Spectrometer')
def __init__(self):
self.tsversion = 2.1
def SetCalibration(self, pw, dBW = None, refAtt = None, flip = 90):
''' set the calibration of the current coil, given :
pulse width[us]
pulse power[dBW], or refAtt[dB]
flip[deg]
'''
if dBW == None and refAtt == None:
raise ValueError('SetCalibration: must provide dBW or refAtt')
if dBW != None and refAtt != None:
raise ValueError('SetCalibration: only provide dBW or refAtt')
if refAtt:
# convert old-style dB values into new-style dBW values
dBW = self.W2dBW(self.db2W(refAtt))
Hz = (flip/360.0) / (pw * 1e-6)
V = math.sqrt(self.dBW2W(dBW))
self._cal_pw = pw
self._cal_dBW = dBW
self._cal_Hz_per_V = Hz / V
self.log.info('calibration: {0} us, {1} dBW, {2} deg, := {3} Hz, {4} Hz/V'
.format(pw, dBW, flip, Hz, self._cal_Hz_per_V))
def CalcPwFromFlip(self, flip, dBW):
''' calculate the pw for a desired flip angle[deg] at a give power[dBW] '''
V = math.sqrt(self.dBW2W(dBW))
Hz = self._cal_Hz_per_V * V
return 1e6 * (flip / 360.0) / Hz
def dBW2W(self, dBW):
''' convert -dBW to Watts -- used in topspin >= 3.0 '''
return pow(10, -dBW/10.0)
def W2dBW(self, W):
''' convert Watts to -dBW -- used in topspin >= 3.0 '''
return -10.0 * math.log10(W)
def dB2W(self, dB, MaxW = 70):
''' convert dB to Watts -- used in topspin < 3.0 '''
# in old topspin, max amplifier Wattage was system-dependent, just default to 70W here
return math.pow(MaxW * 10.0, -((dB + 6) / 10.0))
def W2dB(self, W, MaxW = 70):
''' convert Watts to dB -- used in topspin < 3.0 '''
# in old topspin, max amplifier Wattage was system-dependent, just default to 70W here
return -(10.0 * math.log10(P / MaxW) + 6.0);
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)