source: branches/Release2.1.1/python/selector.py@ 2337

Last change on this file since 2337 was 1045, checked in by mar637, 19 years ago

Bug fix for default value in set_*

File size: 5.7 KB
Line 
1from asap._asap import selector as _selector
2from asap import unique, _to_list
3
4class selector(_selector):
5 """
6 A selection object to be applied to scantables to restrict the
7 scantables to specific rows.
8 """
9 def __init(self):
10 _selector.__init__(self)
11
12 def reset(self):
13 """
14 Unset all selections.
15 """
16 self._reset()
17
18 def is_empty(self):
19 """
20 Has anything been set?
21 """
22 return self._empty()
23
24 def set_polarisations(self, pols=[]):
25 """
26 Set the polarisations to be selected in the scantable.
27 Parameters:
28 pols: a list of integers of 0-3, or strings, e.g ["I","Q"].
29 Default [] is no selection
30 Example:
31 sel = selector()
32 # These are equivalent if data is 'linear'
33 sel.set_polarisations(["XX","Re(XY)"])
34 sel.set_polarisations([0,2])
35 # reset the polarisation selection
36 sel.set_polarisations()
37
38 """
39 vec = _to_list(pols, str) or _to_list(pols, int)
40 if isinstance(vec, list): # is an empty and/or valid vector
41 if len(vec) and isinstance(vec[-1],str):
42 self._setpolstrings(vec)
43 return
44 self._setpols(vec)
45 else:
46 raise TypeError('Unknown pol type. Please use [0,1...] or ["XX","YY"...]')
47
48 def set_ifs(self, ifs=[]):
49 """
50 Set a sequence of IF numbers (0-based).
51 Parameters:
52 ifs: a list of integers. Default [] is to unset the selection.
53 """
54 vec = _to_list(ifs, int)
55 if isinstance(vec,list):
56 self._setifs(vec)
57 else:
58 raise TypeError('Unknown IFno type. Use lists of integers.')
59
60 def set_scans(self, scans=[]):
61 """
62 Set a sequence of Scan numbers (0-based).
63 Parameters:
64 scans: a list of integers. Default [] is to unset the selection.
65 """
66 vec = _to_list(scans, int)
67 if isinstance(vec,list):
68 self._setscans(vec)
69 else:
70 raise TypeError('Unknown Scan number type. Use lists of integers.')
71
72 def set_beams(self, beams=[]):
73 """
74 Set a sequence of Beam numbers (0-based).
75 Parameters:
76 beams: a list of integers. Default [] is to unset the selection.
77 """
78 vec = _to_list(beams, int)
79 if isinstance(vec,list):
80 self._setbeams(vec)
81 else:
82 raise TypeError('Unknown Beam number type. Use lists of integers.')
83
84 def set_cycles(self, cycles=[]):
85 """
86 Set a sequence of IF numbers (0-based).
87 Parameters:
88 cycless: a list of integers. Default [] is to unset the selection.
89 """
90 vec = _to_list(cycles, int)
91 if isinstance(vec,list):
92 self._setcycles(vec)
93 else:
94 raise TypeError('Unknown Cycle number type. Use lists of integers.')
95
96
97 def set_name(self, name):
98 """
99 Set a selection based on a name. This can be a unix pattern , e.g. "*_R"
100 Parameters:
101 name: a string containing a source name or pattern
102 Examples:
103 # select all reference scans which start with "Orion"
104 selection.set_name("Orion*_R")
105 """
106 if isinstance(name, str):
107 self._setname(name)
108 else:
109 raise TypeError('name must be a string')
110
111 def set_tsys(self, tsysmin=0.0, tsysmax=None):
112 """
113 Select by Tsys range.
114 Parameters:
115 tsysmin: the lower threshold. Default 0.0
116 tsysmax: the upper threshold. Default None.
117 Examples:
118 # select all spectra with Tsys <= 500.0
119 selection.set_tsys(tsysmax=500.0)
120
121 """
122 taql = "SELECT FROM $1 WHERE TSYS[0] >= %f" % (tsysmin)
123 if isinstance(tsysmax, float):
124 taql = taql + " AND TSYS[0] <= %f" % ( tsysmax)
125 self._settaql(taql)
126
127 def set_query(self, query):
128 """
129 Select by Column query. Power users only!
130 Example:
131 # select all off scans with integration times over 60 seconds.
132 selection.set_query("SRCTYPE == 1 AND INTERVAL > 60.0")
133 """
134 taql = "SELECT FROM $1 WHERE " + query
135 self._settaql(taql)
136
137 def set_order(self, order):
138 """
139 Set the order the scantable should be sorted by.
140 Parameters:
141 order: The list of column names to sort by in order
142 """
143 self._setorder(order)
144
145 def get_scans(self):
146 return list(self._getscans())
147 def get_cycles(self):
148 return list(self._getcycles())
149 def get_beams(self):
150 return list(self._getbeams())
151 def get_ifs(self):
152 return list(self._getifs())
153 def get_pols(self):
154 return list(self._getpols())
155 def get_poltypes(self):
156 return list(self._getpoltypes())
157 def get_order(self):
158 return list(self._getorder())
159 def get_taql(self):
160 return self._gettaql()
161 def get_name(self):
162 print "NYI"
163 s = self._gettaql()
164 return ""
165
166 def __add__(self, other):
167 """
168 Merge two selections.
169 """
170 union = selector()
171 gets = [[self._getscans(), other._getscans(), union._setscans],
172 [self._getcycles(), other._getcycles(),union._setcycles],
173 [self._getbeams(), other._getbeams(), union._setbeams],
174 [self._getifs(), other._getifs(), union._setifs],
175 [self._getpols(), other._getpols(), union._setpols]]
176 for v in gets:
177 vec = list(v[0]+v[1])
178 vec.sort()
179 v[2](unique(vec))
180 union._settaql(other._gettaql())
181 return union
Note: See TracBrowser for help on using the repository browser.