Package generic_fns :: Module frq
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.frq

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Module for manipulating the spectrometer frequency of experiments.""" 
 24   
 25  # Python module imports. 
 26  from warnings import warn 
 27   
 28  # relax module imports. 
 29  from generic_fns import pipes 
 30  from relax_errors import RelaxError 
 31  from relax_warnings import RelaxWarning 
 32   
 33   
34 -def get_values():
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 # No frequency data. 42 if not hasattr(cdp, 'frq'): 43 return [] 44 45 # The frequency values. 46 values = cdp.frq.values() 47 48 # Build a list of the unique frequencies. 49 frq = [] 50 for value in values: 51 if value not in frq: 52 frq.append(value) 53 54 # Return the frqs. 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 # Test if the current data pipe exists. 70 pipes.test() 71 72 # Set up the dictionary data structure if it doesn't exist yet. 73 if not hasattr(cdp, 'frq'): 74 cdp.frq = {} 75 76 # Test the frequency has not already been set. 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 # Unit conversion. 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 # Set the frequency. 93 cdp.frq[id] = frq * conv 94 95 # Warnings. 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