1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for manipulating the spectrometer frequency of experiments."""
24
25
26 from warnings import warn
27
28
29 from generic_fns import pipes
30 from relax_errors import RelaxError
31 from relax_warnings import RelaxWarning
32
33
35 """Return a list of all the current frequencies.
36
37 @return: The frequency list for the current data pipe.
38 @rtype: list of float
39 """
40
41
42 if not hasattr(cdp, 'frq'):
43 return []
44
45
46 values = cdp.frq.values()
47
48
49 frq = []
50 for value in values:
51 if value not in frq:
52 frq.append(value)
53
54
55 return frq
56
57
58 -def set(id=None, frq=None, units='Hz'):
59 """Set the spectrometer frequency of the experiment.
60
61 @keyword id: The experimental identification string (allowing for multiple experiments per data pipe).
62 @type id: str
63 @keyword frq: The spectrometer frequency in Hertz.
64 @type frq: float
65 @keyword units: The units of frequency. This can be one of "Hz", "kHz", "MHz", or "GHz".
66 @type units: str
67 """
68
69
70 pipes.test()
71
72
73 if not hasattr(cdp, 'frq'):
74 cdp.frq = {}
75
76
77 if id in cdp.frq and cdp.frq[id] != frq:
78 raise RelaxError("The frequency for the experiment '%s' has already been set to %s Hz." % (id, cdp.frq[id]))
79
80
81 if units == 'Hz':
82 conv = 1.0
83 elif units == 'kHz':
84 conv = 1e3
85 elif units == 'MHz':
86 conv = 1e6
87 elif units == 'GHz':
88 conv = 1e9
89 else:
90 raise RelaxError("The frequency units of '%s' are unknown." % units)
91
92
93 cdp.frq[id] = frq * conv
94
95
96 if cdp.frq[id] < 1e8:
97 warn(RelaxWarning("The proton frequency of %s Hz appears to be too low." % cdp.frq[id]))
98 if cdp.frq[id] > 2e9:
99 warn(RelaxWarning("The proton frequency of %s Hz appears to be too high." % cdp.frq[id]))
100