Changeset 2349
- Timestamp:
- 11/16/11 13:57:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2348 r2349 180 180 181 181 @asaplog_post_dec 182 #def __init__(self, filename, average=None, unit=None, getpt=None,183 # antenna=None, parallactify=None):184 182 def __init__(self, filename, average=None, unit=None, parallactify=None, 185 183 **args): … … 204 202 in existing scantables 205 203 206 getpt: for MeasurementSet input data only:207 If True, all pointing data are filled.208 The deafult is False, which makes time to load209 the MS data faster in some cases.210 211 204 antenna: for MeasurementSet input data only: 212 Antenna selection. integer (id) or string (name or id). 213 214 parallactify: Indicate that the data had been parallatified. Default 215 is taken from rc file. 205 Antenna selection. integer (id) or string 206 (name or id). 207 208 parallactify: Indicate that the data had been parallactified. 209 Default (false) is taken from rc file. 216 210 217 211 """ 218 212 if average is None: 219 213 average = rcParams['scantable.autoaverage'] 220 #if getpt is None:221 # getpt = True222 #if antenna is not None:223 # asaplog.push("Antenna selection currently unsupported."224 # "Using ''")225 # asaplog.post('WARN')226 #if antenna is None:227 # antenna = ''228 #elif type(antenna) == int:229 # antenna = '%s' % antenna230 #elif type(antenna) == list:231 # tmpstr = ''232 # for i in range( len(antenna) ):233 # if type(antenna[i]) == int:234 # tmpstr = tmpstr + ('%s,'%(antenna[i]))235 # elif type(antenna[i]) == str:236 # tmpstr=tmpstr+antenna[i]+','237 # else:238 # raise TypeError('Bad antenna selection.')239 # antenna = tmpstr.rstrip(',')240 214 parallactify = parallactify or rcParams['scantable.parallactify'] 241 215 varlist = vars() … … 260 234 # do not reset to the default freqframe 261 235 #self.set_freqframe(rcParams['scantable.freqframe']) 262 #elif os.path.isdir(filename) \263 # and not os.path.exists(filename+'/table.f1'):264 236 elif is_ms(filename): 265 237 # Measurement Set … … 269 241 if key in args.keys(): 270 242 opts['ms'][key] = args[key] 271 #self._fill([filename], unit, average, getpt, antenna)272 243 self._fill([filename], unit, average, opts) 273 244 elif os.path.isfile(filename): 274 #self._fill([filename], unit, average, getpt, antenna)275 245 self._fill([filename], unit, average) 246 # # only apply to new data not "copy constructor" 247 # self.parallactify(parallactify) 276 248 else: 277 249 msg = "The given file '%s'is not a valid " \ … … 280 252 elif (isinstance(filename, list) or isinstance(filename, tuple)) \ 281 253 and isinstance(filename[-1], str): 282 #self._fill(filename, unit, average, getpt, antenna)283 254 self._fill(filename, unit, average) 284 255 self.parallactify(parallactify) … … 594 565 595 566 """ 596 if insitu is None: insitu = rcParams['insitu'] 567 if insitu is None: 568 insitu = rcParams['insitu'] 597 569 if not insitu: 598 570 workscan = self.copy() … … 600 572 workscan = self 601 573 # Select a row 602 sel =selector()574 sel = selector() 603 575 sel.set_rows([row]) 604 #sel.set_scans([workscan.getscan(row)])605 #sel.set_cycles([workscan.getcycle(row)])606 #sel.set_beams([workscan.getbeam(row)])607 #sel.set_ifs([workscan.getif(row)])608 #sel.set_polarisations([workscan.getpol(row)])609 #sel.set_name(workscan._getsourcename(row))610 576 workscan.set_selection(sel) 611 577 if not workscan.nrow() == 1: 612 msg = "Cloud not identify single row. %d rows selected."%(workscan.nrow()) 578 msg = "Could not identify single row. %d rows selected." \ 579 % (workscan.nrow()) 613 580 raise RuntimeError(msg) 614 del sel615 581 if insitu: 616 582 self._assign(workscan) … … 868 834 asdatetime: return values as datetime objects rather than strings 869 835 870 prec: number of digits shown. Default -1 to automatic calculation. 836 prec: number of digits shown. Default -1 to automatic 837 calculation. 871 838 Note this number is equals to the digits of MVTime, 872 839 i.e., 0<prec<3: dates with hh:: only, … … 878 845 if prec < 0: 879 846 # automagically set necessary precision +1 880 prec = 7 - numpy.floor(numpy.log10(numpy.min(self.get_inttime(row)))) 847 prec = 7 - \ 848 numpy.floor(numpy.log10(numpy.min(self.get_inttime(row)))) 881 849 prec = max(6, int(prec)) 882 850 else: … … 1236 1204 1237 1205 @asaplog_post_dec 1238 def fft(self, rowno= [], mask=[], getrealimag=False):1206 def fft(self, rowno=None, mask=None, getrealimag=False): 1239 1207 """\ 1240 1208 Apply FFT to the spectra. … … 1244 1212 1245 1213 rowno: The row number(s) to be processed. int, list 1246 and tuple are accepted. By default ( []), FFT1214 and tuple are accepted. By default (None), FFT 1247 1215 is applied to the whole data. 1248 1216 … … 1252 1220 apply different masks. In the latter case, the 1253 1221 length of 'mask' must be the same as that of 1254 'rowno'. The default is [].1222 'rowno'. The default is None. 1255 1223 1256 1224 getrealimag: If True, returns the real and imaginary part … … 1269 1237 respectively. 1270 1238 """ 1239 if rowno is None: 1240 rowno = [] 1241 if mask is None: 1242 mask = [] 1271 1243 if isinstance(rowno, int): 1272 1244 rowno = [rowno] … … 1277 1249 1278 1250 if not (isinstance(mask, list) or isinstance(mask, tuple)): 1279 raise TypeError("The mask must be a boolean list or a list of boolean list.") 1251 raise TypeError("The mask must be a boolean list or a list of " 1252 "boolean list.") 1280 1253 if len(mask) == 0: mask = [True for i in xrange(self.nchan())] 1281 1254 if isinstance(mask[0], bool): mask = [mask] 1282 1255 elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)): 1283 raise TypeError("The mask must be a boolean list or a list of boolean list.") 1256 raise TypeError("The mask must be a boolean list or a list of " 1257 "boolean list.") 1284 1258 1285 1259 usecommonmask = (len(mask) == 1) 1286 1260 if not usecommonmask: 1287 1261 if len(mask) != len(rowno): 1288 raise ValueError("When specifying masks for each spectrum, the numbers of them must be identical.") 1262 raise ValueError("When specifying masks for each spectrum, " 1263 "the numbers of them must be identical.") 1289 1264 for amask in mask: 1290 1265 if len(amask) != self.nchan(): 1291 raise ValueError("The spectra and the mask have different length.") 1266 raise ValueError("The spectra and the mask have different " 1267 "length.") 1292 1268 1293 1269 res = [] … … 1298 1274 nspec = len(fspec) 1299 1275 1300 i=0 1301 v1=[] 1302 v2=[] 1303 reselem = {"real":[],"imag":[]} if getrealimag else {"ampl":[],"phase":[]} 1276 i = 0 1277 v1 = [] 1278 v2 = [] 1279 reselem = {"real":[],"imag":[]} if getrealimag \ 1280 else {"ampl":[],"phase":[]} 1304 1281 1305 1282 while (i < nspec): 1306 1283 v1.append(fspec[i]) 1307 1284 v2.append(fspec[i+1]) 1308 i +=21285 i += 2 1309 1286 1310 1287 if getrealimag: … … 1317 1294 res.append(reselem) 1318 1295 1319 if not usecommonmask: imask += 1 1296 if not usecommonmask: 1297 imask += 1 1320 1298 1321 1299 return res … … 1374 1352 # test if args is a 'list' or a 'normal *args - UGLY!!! 1375 1353 1376 ws = (isinstance(args[-1][-1], int) or isinstance(args[-1][-1], float)) \1377 and args or args[0]1354 ws = (isinstance(args[-1][-1], int) 1355 or isinstance(args[-1][-1], float)) and args or args[0] 1378 1356 for window in ws: 1379 1357 if len(window) == 1: 1380 1358 window = [window[0], window[0]] 1381 1359 if len(window) == 0 or len(window) > 2: 1382 raise ValueError("A window needs to be defined as [start(, end)]") 1360 raise ValueError("A window needs to be defined as " 1361 "[start(, end)]") 1383 1362 if window[0] > window[1]: 1384 1363 tmp = window[0] … … 1429 1408 if not silent: 1430 1409 asaplog.push(msg) 1431 masklist =[]1410 masklist = [] 1432 1411 ist, ien = None, None 1433 1412 ist, ien=self.get_mask_indices(mask) … … 1457 1436 if len(mask) < 2: 1458 1437 raise TypeError("The mask elements should be > 1") 1459 istart=[] 1460 iend=[] 1461 if mask[0]: istart.append(0) 1438 istart = [] 1439 iend = [] 1440 if mask[0]: 1441 istart.append(0) 1462 1442 for i in range(len(mask)-1): 1463 1443 if not mask[i] and mask[i+1]: … … 1465 1445 elif mask[i] and not mask[i+1]: 1466 1446 iend.append(i) 1467 if mask[len(mask)-1]: iend.append(len(mask)-1) 1447 if mask[len(mask)-1]: 1448 iend.append(len(mask)-1) 1468 1449 if len(istart) != len(iend): 1469 1450 raise RuntimeError("Numbers of mask start != mask end.") … … 1475 1456 1476 1457 @asaplog_post_dec 1477 def parse_maskexpr(self, maskstring):1458 def parse_maskexpr(self, maskstring): 1478 1459 """ 1479 1460 Parse CASA type mask selection syntax (IF dependent). … … 1509 1490 selset = currselstr.split(':') 1510 1491 # spw and mask string (may include ~, < or >) 1511 spwmasklist = self._parse_selection(selset[0], typestr='integer',1512 offset=1,minval=min(valid_ifs),1513 maxval=max(valid_ifs))1492 spwmasklist = self._parse_selection(selset[0], typestr='integer', 1493 offset=1, minval=min(valid_ifs), 1494 maxval=max(valid_ifs)) 1514 1495 for spwlist in spwmasklist: 1515 1496 selspws = [] … … 1522 1503 # parse frequency mask list 1523 1504 if len(selset) > 1: 1524 freqmasklist = self._parse_selection(selset[1], typestr='float',1525 offset=0.)1505 freqmasklist = self._parse_selection(selset[1], typestr='float', 1506 offset=0.) 1526 1507 else: 1527 1508 # want to select the whole spectrum … … 1555 1536 offset = 0.5 1556 1537 elif frequnit.find('Hz') > 0: 1557 offset = abs(freqcoord.to_frequency(1,unit=frequnit) 1558 -freqcoord.to_frequency(0,unit=frequnit))*0.5 1538 offset = abs(freqcoord.to_frequency(1, 1539 unit=frequnit) 1540 -freqcoord.to_frequency(0, 1541 unit=frequnit) 1542 )*0.5 1559 1543 elif frequnit.find('m/s') > 0: 1560 offset = abs(freqcoord.to_velocity(1,unit=frequnit) 1561 -freqcoord.to_velocity(0,unit=frequnit))*0.5 1544 offset = abs(freqcoord.to_velocity(1, 1545 unit=frequnit) 1546 -freqcoord.to_velocity(0, 1547 unit=frequnit) 1548 )*0.5 1562 1549 else: 1563 1550 asaplog.post() … … 1592 1579 if len(seldict) == 0: 1593 1580 asaplog.post() 1594 asaplog.push("No valid selection in the mask expression: "+maskstring) 1581 asaplog.push("No valid selection in the mask expression: " 1582 +maskstring) 1595 1583 asaplog.post("WARN") 1596 1584 return None … … 1601 1589 return seldict 1602 1590 1603 def _parse_selection(self,selstr,typestr='float',offset=0.,minval=None,maxval=None): 1591 def _parse_selection(self, selstr, typestr='float', offset=0., 1592 minval=None, axval=None): 1604 1593 """ 1605 1594 Parameters: … … 1671 1660 """ 1672 1661 if ids is None: 1673 rfreqs ={}1662 rfreqs = {} 1674 1663 idlist = self.getmolnos() 1675 1664 for i in idlist: 1676 rfreqs[i] =list(self._getrestfreqs(i))1665 rfreqs[i] = list(self._getrestfreqs(i)) 1677 1666 return rfreqs 1678 1667 else: 1679 if type(ids) ==list or type(ids)==tuple:1680 rfreqs ={}1668 if type(ids) == list or type(ids) == tuple: 1669 rfreqs = {} 1681 1670 for i in ids: 1682 rfreqs[i] =list(self._getrestfreqs(i))1671 rfreqs[i] = list(self._getrestfreqs(i)) 1683 1672 return rfreqs 1684 1673 else: 1685 1674 return list(self._getrestfreqs(ids)) 1686 #return list(self._getrestfreqs(ids)) 1687 1675 1676 @asaplog_post_dec 1688 1677 def set_restfreqs(self, freqs=None, unit='Hz'): 1689 1678 """\ … … 1800 1789 self._add_history("set_restfreqs", varlist) 1801 1790 1791 @asaplog_post_dec 1802 1792 def shift_refpix(self, delta): 1803 1793 """\ … … 1814 1804 1815 1805 """ 1806 varlist = vars() 1816 1807 Scantable.shift_refpix(self, delta) 1808 s._add_history("shift_refpix", varlist) 1817 1809 1818 1810 @asaplog_post_dec … … 1857 1849 raise IOError(msg) 1858 1850 return page(out) 1851 1859 1852 # 1860 1853 # Maths business … … 1863 1856 def average_time(self, mask=None, scanav=False, weight='tint', align=False): 1864 1857 """\ 1865 Return the (time) weighted average of a scan. 1858 Return the (time) weighted average of a scan. Scans will be averaged 1859 only if the source direction (RA/DEC) is within 1' otherwise 1866 1860 1867 1861 *Note*: … … 2034 2028 s = scantable(self._math._freq_align(self, reftime, method)) 2035 2029 s._add_history("freq_align", varlist) 2036 if insitu: self._assign(s) 2037 else: return s 2030 if insitu: 2031 self._assign(s) 2032 else: 2033 return s 2038 2034 2039 2035 @asaplog_post_dec … … 2059 2055 2060 2056 """ 2061 if insitu is None: insitu = rcParams['insitu'] 2057 if insitu is None: 2058 insitu = rcParams['insitu'] 2062 2059 self._math._setinsitu(insitu) 2063 2060 varlist = vars() … … 2066 2063 s = scantable(self._math._opacity(self, tau)) 2067 2064 s._add_history("opacity", varlist) 2068 if insitu: self._assign(s) 2069 else: return s 2065 if insitu: 2066 self._assign(s) 2067 else: 2068 return s 2070 2069 2071 2070 @asaplog_post_dec … … 2083 2082 2084 2083 """ 2085 if insitu is None: insitu = rcParams['insitu'] 2084 if insitu is None: 2085 insitu = rcParams['insitu'] 2086 2086 self._math._setinsitu(insitu) 2087 2087 varlist = vars() … … 2111 2111 2112 2112 """ 2113 if insitu is None: insitu = rcParams['insitu'] 2113 if insitu is None: 2114 insitu = rcParams['insitu'] 2114 2115 self._math._setinsitu(insitu) 2115 2116 varlist = vars() 2116 2117 s = scantable(self._math._resample(self, method, width)) 2117 2118 s._add_history("resample", varlist) 2118 if insitu: self._assign(s) 2119 else: return s 2119 if insitu: 2120 self._assign(s) 2121 else: 2122 return s 2120 2123 2121 2124 @asaplog_post_dec … … 2254 2257 ### Ugly part for legend 2255 2258 for i in [0,1]: 2256 theplot.subplots[0]['lines'].append([theplot.subplots[0]['axes'].lines[i]]) 2259 theplot.subplots[0]['lines'].append( 2260 [theplot.subplots[0]['axes'].lines[i]] 2261 ) 2257 2262 theplot.release() 2258 2263 ### Ugly part for legend … … 2319 2324 minnrow=None, outlog=None, blfile=None): 2320 2325 """\ 2321 Return a scan which has been baselined (all rows) with sinusoidal functions. 2326 Return a scan which has been baselined (all rows) with sinusoidal 2327 functions. 2328 2322 2329 Parameters: 2323 2330 insitu: if False a new scantable is returned. … … 2337 2344 given a float value, the unit is set to sigma. 2338 2345 for string values, allowed formats include: 2339 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 2346 'xsigma' or 'x' (= x-sigma level. e.g., 2347 '3sigma'), or 2340 2348 'topx' (= the x strongest ones, e.g. 'top5'). 2341 2349 default is 3.0 (unit: sigma). … … 2355 2363 and rejwn will NOT be used. default is []. 2356 2364 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2357 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2365 clipniter: maximum number of iteration of 'clipthresh'-sigma 2366 clipping (default is 0) 2358 2367 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2359 2368 plot the fit and the residual. In this each … … 2373 2382 2374 2383 Example: 2375 # return a scan baselined by a combination of sinusoidal curves having2376 # wave numbers in spectral window up to 10,2384 # return a scan baselined by a combination of sinusoidal curves 2385 # having wave numbers in spectral window up to 10, 2377 2386 # also with 3-sigma clipping, iteration up to 4 times 2378 2387 bscan = scan.sinusoid_baseline(addwn='<=10',clipthresh=3.0,clipniter=4) … … 2408 2417 2409 2418 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2410 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2419 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), 2420 str(fftthresh).lower(), 2421 workscan._parse_wn(addwn), 2422 workscan._parse_wn(rejwn), clipthresh, 2423 clipniter, getresidual, 2424 pack_progress_params(showprogress, 2425 minnrow), outlog, 2426 blfile) 2411 2427 workscan._add_history('sinusoid_baseline', varlist) 2412 2428 … … 2421 2437 2422 2438 @asaplog_post_dec 2423 def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None, 2424 addwn=None, rejwn=None, clipthresh=None, clipniter=None, edge=None, threshold=None, 2425 chan_avg_limit=None, plot=None, getresidual=None, showprogress=None, minnrow=None, 2426 outlog=None, blfile=None): 2427 """\ 2428 Return a scan which has been baselined (all rows) with sinusoidal functions. 2439 def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, 2440 fftmethod=None, fftthresh=None, 2441 addwn=None, rejwn=None, clipthresh=None, 2442 clipniter=None, edge=None, threshold=None, 2443 chan_avg_limit=None, plot=None, 2444 getresidual=None, showprogress=None, 2445 minnrow=None, outlog=None, blfile=None): 2446 """\ 2447 Return a scan which has been baselined (all rows) with sinusoidal 2448 functions. 2429 2449 Spectral lines are detected first using linefinder and masked out 2430 2450 to avoid them affecting the baseline solution. … … 2447 2467 given a float value, the unit is set to sigma. 2448 2468 for string values, allowed formats include: 2449 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 2469 'xsigma' or 'x' (= x-sigma level. e.g., 2470 '3sigma'), or 2450 2471 'topx' (= the x strongest ones, e.g. 'top5'). 2451 2472 default is 3.0 (unit: sigma). … … 2465 2486 and rejwn will NOT be used. default is []. 2466 2487 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2467 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2488 clipniter: maximum number of iteration of 'clipthresh'-sigma 2489 clipping (default is 0) 2468 2490 edge: an optional number of channel to drop at 2469 2491 the edge of spectrum. If only one value is … … 2538 2560 2539 2561 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2540 workscan._auto_sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, normalise_edge_param(edge), threshold, chan_avg_limit, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2562 workscan._auto_sinusoid_baseline(mask, applyfft, 2563 fftmethod.lower(), 2564 str(fftthresh).lower(), 2565 workscan._parse_wn(addwn), 2566 workscan._parse_wn(rejwn), 2567 clipthresh, clipniter, 2568 normalise_edge_param(edge), 2569 threshold, chan_avg_limit, 2570 getresidual, 2571 pack_progress_params(showprogress, 2572 minnrow), 2573 outlog, blfile) 2541 2574 workscan._add_history("auto_sinusoid_baseline", varlist) 2542 2575 … … 2550 2583 2551 2584 @asaplog_post_dec 2552 def cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2553 plot=None, getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None): 2554 """\ 2555 Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial). 2585 def cspline_baseline(self, insitu=None, mask=None, npiece=None, 2586 clipthresh=None, clipniter=None, plot=None, 2587 getresidual=None, showprogress=None, minnrow=None, 2588 outlog=None, blfile=None): 2589 """\ 2590 Return a scan which has been baselined (all rows) by cubic spline 2591 function (piecewise cubic polynomial). 2592 2556 2593 Parameters: 2557 2594 insitu: If False a new scantable is returned. … … 2561 2598 npiece: Number of pieces. (default is 2) 2562 2599 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2563 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2600 clipniter: maximum number of iteration of 'clipthresh'-sigma 2601 clipping (default is 0) 2564 2602 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2565 2603 plot the fit and the residual. In this each … … 2579 2617 2580 2618 Example: 2581 # return a scan baselined by a cubic spline consisting of 2 pieces (i.e., 1 internal knot), 2619 # return a scan baselined by a cubic spline consisting of 2 pieces 2620 # (i.e., 1 internal knot), 2582 2621 # also with 3-sigma clipping, iteration up to 4 times 2583 2622 bscan = scan.cspline_baseline(npiece=2,clipthresh=3.0,clipniter=4) … … 2609 2648 2610 2649 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2611 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2650 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, 2651 getresidual, 2652 pack_progress_params(showprogress, 2653 minnrow), outlog, 2654 blfile) 2612 2655 workscan._add_history("cspline_baseline", varlist) 2613 2656 … … 2621 2664 2622 2665 @asaplog_post_dec 2623 def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2624 edge=None, threshold=None, chan_avg_limit=None, getresidual=None, plot=None, 2625 showprogress=None, minnrow=None, outlog=None, blfile=None): 2666 def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, 2667 clipthresh=None, clipniter=None, 2668 edge=None, threshold=None, chan_avg_limit=None, 2669 getresidual=None, plot=None, 2670 showprogress=None, minnrow=None, outlog=None, 2671 blfile=None): 2626 2672 """\ 2627 2673 Return a scan which has been baselined (all rows) by cubic spline … … 2637 2683 npiece: Number of pieces. (default is 2) 2638 2684 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2639 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2685 clipniter: maximum number of iteration of 'clipthresh'-sigma 2686 clipping (default is 0) 2640 2687 edge: an optional number of channel to drop at 2641 2688 the edge of spectrum. If only one value is … … 2779 2826 if plot: 2780 2827 outblfile = (blfile != "") and \ 2781 os.path.exists(os.path.expanduser(os.path.expandvars(blfile))) 2828 os.path.exists(os.path.expanduser( 2829 os.path.expandvars(blfile)) 2830 ) 2782 2831 if outblfile: 2783 2832 blf = open(blfile, "a") … … 2820 2869 f._p = None 2821 2870 2822 if outblfile: blf.close() 2871 if outblfile: 2872 blf.close() 2823 2873 else: 2824 2874 workscan._poly_baseline(mask, order, getresidual, … … 2953 3003 masklist = workscan.get_masklist(f.mask, row=r, silent=True) 2954 3004 #workscan._append_blinfo(blpars, masklist, f.mask) 2955 workscan._setspectrum((f.fitter.getresidual() \ 2956 if getresidual else f.fitter.getfit()), r) 3005 workscan._setspectrum( 3006 (f.fitter.getresidual() if getresidual 3007 else f.fitter.getfit()), r 3008 ) 2957 3009 2958 3010 if outblfile: … … 3137 3189 return s 3138 3190 3139 def set_sourcetype(self, match, matchtype="pattern", 3191 @preserve_selection 3192 def set_sourcetype(self, match, matchtype="pattern", 3140 3193 sourcetype="reference"): 3141 3194 """\ … … 3173 3226 else: 3174 3227 sel.set_query("SRCNAME == %s('%s')" % (matchtype, match)) 3175 self.set_selection(basesel+sel)3176 3228 self._setsourcetype(stype) 3177 self.set_selection(basesel)3178 3229 self._add_history("set_sourcetype", varlist) 3179 3230 … … 3295 3346 s = scantable(self._math._unaryop(self, other, "ADD", False)) 3296 3347 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3297 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3348 if isinstance(other[0], list) \ 3349 or isinstance(other[0], numpy.ndarray): 3298 3350 from asapmath import _array2dOp 3299 3351 s = _array2dOp( self.copy(), other, "ADD", False ) 3300 3352 else: 3301 s = scantable( self._math._arrayop( self.copy(), other, "ADD", False ) ) 3353 s = scantable( self._math._arrayop( self.copy(), other, 3354 "ADD", False ) ) 3302 3355 else: 3303 3356 raise TypeError("Other input is not a scantable or float value") … … 3317 3370 s = scantable(self._math._unaryop(self, other, "SUB", False)) 3318 3371 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3319 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3372 if isinstance(other[0], list) \ 3373 or isinstance(other[0], numpy.ndarray): 3320 3374 from asapmath import _array2dOp 3321 3375 s = _array2dOp( self.copy(), other, "SUB", False ) 3322 3376 else: 3323 s = scantable( self._math._arrayop( self.copy(), other, "SUB", False ) ) 3377 s = scantable( self._math._arrayop( self.copy(), other, 3378 "SUB", False ) ) 3324 3379 else: 3325 3380 raise TypeError("Other input is not a scantable or float value") … … 3339 3394 s = scantable(self._math._unaryop(self, other, "MUL", False)) 3340 3395 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3341 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3396 if isinstance(other[0], list) \ 3397 or isinstance(other[0], numpy.ndarray): 3342 3398 from asapmath import _array2dOp 3343 3399 s = _array2dOp( self.copy(), other, "MUL", False ) 3344 3400 else: 3345 s = scantable( self._math._arrayop( self.copy(), other, "MUL", False ) ) 3401 s = scantable( self._math._arrayop( self.copy(), other, 3402 "MUL", False ) ) 3346 3403 else: 3347 3404 raise TypeError("Other input is not a scantable or float value") … … 3364 3421 s = scantable(self._math._unaryop(self, other, "DIV", False)) 3365 3422 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3366 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3423 if isinstance(other[0], list) \ 3424 or isinstance(other[0], numpy.ndarray): 3367 3425 from asapmath import _array2dOp 3368 3426 s = _array2dOp( self.copy(), other, "DIV", False ) 3369 3427 else: 3370 s = scantable( self._math._arrayop( self.copy(), other, "DIV", False ) ) 3428 s = scantable( self._math._arrayop( self.copy(), other, 3429 "DIV", False ) ) 3371 3430 else: 3372 3431 raise TypeError("Other input is not a scantable or float value") … … 3391 3450 return fit.as_dict() 3392 3451 3452 @preserve_selection 3393 3453 def flag_nans(self): 3394 3454 """\ … … 3404 3464 bnans = [ bool(v) for v in nans] 3405 3465 self.flag(bnans) 3406 self.set_selection(basesel)3407 3466 3408 3467 def get_row_selector(self, rowno): 3409 #return selector(beams=self.getbeam(rowno),3410 # ifs=self.getif(rowno),3411 # pols=self.getpol(rowno),3412 # scans=self.getscan(rowno),3413 # cycles=self.getcycle(rowno))3414 3468 return selector(rows=[rowno]) 3415 3469 … … 3423 3477 hist = dstr+sep 3424 3478 hist += funcname+sep#cdate+sep 3425 if parameters.has_key('self'): del parameters['self'] 3479 if parameters.has_key('self'): 3480 del parameters['self'] 3426 3481 for k, v in parameters.iteritems(): 3427 3482 if type(v) is dict: … … 3480 3535 3481 3536 def _check_ifs(self): 3482 #nchans = [self.nchan(i) for i in range(self.nif(-1))] 3537 # return len(set([self.nchan(i) for i in self.getifnos()])) == 1 3483 3538 nchans = [self.nchan(i) for i in self.getifnos()] 3484 3539 nchans = filter(lambda t: t > 0, nchans) … … 3486 3541 3487 3542 @asaplog_post_dec 3488 #def _fill(self, names, unit, average, getpt, antenna):3489 3543 def _fill(self, names, unit, average, opts={}): 3490 3544 first = True … … 3508 3562 rx = rcParams['scantable.reference'] 3509 3563 r.setreferenceexpr(rx) 3510 #r = filler(tbl)3511 #rx = rcParams['scantable.reference']3512 #r.setreferenceexpr(rx)3513 3564 msg = "Importing %s..." % (name) 3514 3565 asaplog.push(msg, False) 3515 #opts = {'ms': {'antenna' : antenna, 'getpt': getpt} } 3516 r.open(name, opts)# antenna, -1, -1, getpt) 3566 r.open(name, opts) 3517 3567 r.fill() 3518 3568 if average:
Note:
See TracChangeset
for help on using the changeset viewer.