Changes in trunk/python/linecatalog.py [1826:1865]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/linecatalog.py
r1826 r1865 1 """ 1 """\ 2 2 A representation of a spectral line catalog. 3 4 Author: Malte Marquarding5 6 3 """ 7 4 __revision__ = "$Revision$" 8 5 from asap._asap import linecatalog as lcbase 9 from asap.parameters import rcParams10 6 from asap.logging import asaplog 11 7 import os 12 8 13 9 class linecatalog(lcbase): 14 """ 10 """\ 15 11 This class is a warpper for line catalogs. These can be either ASCII tables 16 12 or the tables saved from this class. 13 17 14 ASCII tables have the following restrictions: 18 Comments can be present through lines starting with '#'. 19 The first column contains the name of the Molecule. This can't contain spaces, 20 if it does it has to be wrapped in "" 21 The second column contains the frequency of the transition. 22 The third column contains the error in frequency. 23 The fourth column contains a value describing the intensity 15 16 * Comments can be present through lines starting with '#'. 17 18 * The first column contains the name of the Molecule. This can't contain 19 spaces, if it does it has to be wrapped in double-quotes. 20 21 * The second column contains the frequency of the transition. 22 23 * The third column contains the error in frequency. 24 25 * The fourth column contains a value describing the intensity. 26 24 27 """ 25 28 … … 30 33 else: 31 34 msg = "File '%s' not found" % fpath 32 if rcParams['verbose']: 33 #print msg 34 asaplog.push( msg ) 35 print_log( 'ERROR' ) 36 return 37 else: 38 raise IOError(msg) 35 raise IOError(msg) 39 36 40 37 def __repr__(self): … … 52 49 53 50 def set_name(self, name, mode="pattern"): 54 """ 51 """\ 55 52 Set a name restriction on the table. This can be a standard unix-style 56 53 pattern or a regular expression. 54 57 55 Parameters: 56 58 57 name: the name patterrn/regex 58 59 59 mode: the matching mode, i.e. "pattern" (default) or "regex" 60 60 61 """ 61 62 validmodes = "pattern regex".split() … … 65 66 66 67 def set_frequency_limits(self, fmin=1.0, fmax=120.0, unit="GHz"): 67 """ 68 """\ 68 69 Set frequency limits on the table. 70 69 71 Parameters: 72 70 73 fmin: the lower bound 74 71 75 fmax: the upper bound 76 72 77 unit: the frequency unit (default "GHz") 73 78 74 Note: 75 The underlying table conatins frequency values in MHz 79 .. note:: The underlying table contains frequency values in MHz 76 80 """ 77 81 base = { "GHz": 1000.0, "MHz": 1.0 } … … 82 86 83 87 def set_strength_limits(self, smin, smax): 84 """ 88 """\ 85 89 Set line strength limits on the table (arbitrary units) 90 86 91 Parameters: 92 87 93 smin: the lower bound 94 88 95 smax: the upper bound 96 89 97 """ 90 98 lcbase.set_strength_limits(self, smin, smax) 91 99 92 100 def save(self, name, overwrite=False): 93 """ 101 """\ 94 102 Save the subset of the table to disk. This uses an internal data format 95 103 and can be read in again. … … 99 107 if not overwrite: 100 108 msg = "File %s exists." % name 101 if rcParams['verbose']: 102 #print msg 103 asaplog.push( msg ) 104 print_log( 'ERROR' ) 105 return 106 else: 107 raise IOError(msg) 109 raise IOError(msg) 108 110 lcbase.save(self, name) 109 111 110 112 def reset(self): 111 """ 112 Reset the table to its initial state, i.e. undo all calls to set_113 """\ 114 Reset the table to its initial state, i.e. undo all calls to ``set_``. 113 115 """ 114 116 lcbase.reset(self) 115 117 116 118 def get_row(self, row=0): 119 """\ 120 Get the values in a specified row of the table. 121 122 Parameters: 123 124 row: the row to retrieve 125 117 126 """ 118 Get the values in a specified row of the table. 119 Parameters: 120 row: the row to retrieve 121 """ 127 if row < 0 or row > len(self)-1: 128 raise IndexError("Row index out of bounds.") 122 129 freq = lcbase.get_frequency(self, row) 123 130 name = lcbase.get_name(self, row) … … 128 135 129 136 def __getitem__(self, k): 130 if k < 0: k = self.nrow()-k 137 if k < 0: 138 k = self.nrow()-k 131 139 return self.get_row(k)
Note:
See TracChangeset
for help on using the changeset viewer.