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