Package qtcm :: Module num_settings
[hide private]
[frames] | no frames]

Source Code for Module qtcm.num_settings

  1  #!/usr/bin/python -tt 
  2  #======================================================================= 
  3  #                        General Documentation 
  4   
  5  """Choose and import using numpy, Numeric, or numarray modules. 
  6   
  7     Sets the following module variables accordingly: 
  8   
  9        N    = All numpy/Numeric/numarray functions, usage e.g.  
 10               N.arange(4). 
 11        MA   = All numpy/Numeric/numarray masked array functions,  
 12               usage e.g.  MA.masked_array(data). 
 13        MLab = All numpy/Numeric/numarray Matlab compatibility  
 14               functions, usage e.g. MLab.squeeze(data).  For numpy, 
 15               (it appears) many of these function are in the regular 
 16               core library, so MLab for numpy is just numpy. 
 17        isscalar = Function to emulate numpy's isscalar function. 
 18        typecode = Function to emulate Numeric's typecode() method 
 19               for Numeric objects. 
 20        typecodes = Dictionary, with additions, that builds off of a 
 21               copy of the N.typecodes dictionary. 
 22   
 23     Thus, by importing using this package you will be able to code 
 24     to a generic naming convention, regardless of what array package 
 25     is used.  The module tries importing numpy first, then numarray, 
 26     and finally Numeric.  The later packages are imported only if 
 27     the earlier ones return an ImportError.  Currently, if you have 
 28     numpy installed, MA and MLab will not be defined, since aliases 
 29     for the numpy versions of those packages have not yet been 
 30     programmed into this module. 
 31  """ 
 32   
 33  #----------------------------------------------------------------------- 
 34  #                       Additional Documentation 
 35  # 
 36  # RCS Revision Code: 
 37  #   $Id: num_settings.py 35 2008-07-14 22:27:39Z jlin $ 
 38  # 
 39  # Modification History: 
 40  # - 28 Aug 2004:  Original by Johnny Lin, Computation Institute, 
 41  #   University of Chicago.  Passed passably reasonable visual tests. 
 42  # 
 43  # Notes: 
 44  # - Written for Python 2.2. 
 45  # - See import statements throughout module for dependencies. 
 46  # 
 47  # Copyright (c) 2004-2008 by Johnny Lin.  For licensing, distribution  
 48  # conditions, contact information, and additional documentation see 
 49  # the URL http://www.johnny-lin.com/py_pkgs/qtcm/doc/. 
 50  #======================================================================= 
 51   
 52   
 53   
 54   
 55  #---------------- Module General Import and Declarations --------------- 
 56   
 57  #- If you're importing this module in testing mode, or you're running 
 58  #  pydoc on this module via the command line, import user-specific 
 59  #  settings to make sure any non-standard libraries are found: 
 60   
 61  import os, sys 
 62  if (__name__ == "__main__") or \ 
 63     ("pydoc" in os.path.basename(sys.argv[0])): 
 64      import user 
 65  del os, sys 
 66   
 67   
 68  #- Import package version and set module version to package version: 
 69   
 70  import package_version as _package_version 
 71  __version__ = _package_version.version 
 72  __author__  = _package_version.author 
 73  __date__    = _package_version.date 
 74  __credits__ = _package_version.credits 
 75   
 76   
 77   
 78   
 79  #--------------------------- Module Variables -------------------------- 
 80  # 
 81  # Import numpy/Numeric/numarray as module variables.  Set the module 
 82  # functions for each array type:  typecode. 
 83   
 84  try: 
 85      import numpy as N 
 86      try: 
 87          import numpy.core.ma as MA 
 88      except ImportError: 
 89          import numpy.ma as MA 
 90      import numpy as MLab 
91 - def typecode(arg):
92 """Return typecode of arg if arg was a numpy array. 93 94 Input argument: 95 * arg: Any argument that can be read converted by numpy into 96 an array. 97 """ 98 return N.array(arg).dtype.char
99 100 except ImportError: 101 try: 102 import numarray 103 import numarray.ma.MA as MA 104 import numarray.linear_algebra.mlab as MLab 105 import numarray as N 106 del numarray
107 - def typecode(arg):
108 """Return typecode of arg if arg was a numarray array. 109 110 Input argument: 111 * arg: Any argument that can be read converted by Numeric 112 into an array. 113 """ 114 return N.array(arg).typecode()
115 - def isscalar(arg):
116 raise ValueError, 'isscalar not yet implemented for numarray'
117 118 except ImportError: 119 try: 120 import Numeric as N 121 import MA 122 import MLab
123 - def typecode(arg):
124 """Return typecode of arg if arg was a Numeric array. 125 126 Input argument: 127 * arg: Any argument that can be read converted by Numeric 128 into an array. 129 """ 130 return N.array(arg).typecode()
131 - def isscalar(arg):
132 raise ValueError, 'isscalar not yet implemented for Numeric'
133 134 except: 135 raise ImportError, 'No array packages found' 136 137 138 #- Set typecodes module variable dictionary and make additions: 139 140 typecodes = N.typecodes 141 if 'S' not in typecodes['Character']: 142 typecodes['Character'] = typecodes['Character'] + 'S' 143 if 'c' not in typecodes['Character']: 144 typecodes['Character'] = typecodes['Character'] + 'c' 145 146 147 148 149 #-------------------------- Main: Test Module ------------------------- 150 151 if __name__ == "__main__": 152 """Test the module documentation strings.""" 153 import doctest, sys, os 154 sys.path.append(os.pardir) 155 doctest.testmod(sys.modules[__name__]) 156 157 158 159 160 # ===== end file ===== 161