Changeset 1757 for branches/alma/python/scantable.py
- Timestamp:
- 06/09/10 19:03:06 (14 years ago)
- Location:
- branches/alma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma
-
Property
svn:ignore
set to
.sconf_temp
.sconsign.dblite
-
Property
svn:mergeinfo
set to
/branches/asap-3.x merged eligible
-
Property
svn:ignore
set to
-
branches/alma/python/scantable.py
r1701 r1757 1 import os 2 try: 3 from functools import wraps as wraps_dec 4 except ImportError: 5 from asap.compatibility import wraps as wraps_dec 6 1 7 from asap._asap import Scantable 2 8 from asap import rcParams 3 from asap import print_log 9 from asap import print_log, print_log_dec 4 10 from asap import asaplog 5 11 from asap import selector 6 12 from asap import linecatalog 13 from asap.coordinate import coordinate 7 14 from asap import _n_bools, mask_not, mask_and, mask_or 15 16 17 def preserve_selection(func): 18 @wraps_dec(func) 19 def wrap(obj, *args, **kw): 20 basesel = obj.get_selection() 21 val = func(obj, *args, **kw) 22 obj.set_selection(basesel) 23 return val 24 return wrap 25 26 27 def is_scantable(filename): 28 return (os.path.isdir(filename) 29 and not os.path.exists(filename+'/table.f1') 30 and os.path.exists(filename+'/table.info')) 31 8 32 9 33 class scantable(Scantable): … … 12 36 """ 13 37 14 def __init__(self, filename, average=None, unit=None, getpt=None, antenna=None): 38 #@print_log_dec 39 def __init__(self, filename, average=None, unit=None, getpt=None, antenna=None, parallactify=None): 15 40 """ 16 41 Create a scantable from a saved one or make a reference … … 36 61 antenna: Antenna selection. integer (id) or string (name 37 62 or id). 63 parallactify: Indcicate that the data had been parallatified. 64 Default is taken form rc file. 38 65 """ 39 66 if average is None: … … 57 84 return 58 85 antenna = tmpstr.rstrip(',') 86 parallactify = parallactify or rcParams['scantable.parallactify'] 59 87 varlist = vars() 60 88 from asap._asap import stmath … … 63 91 Scantable.__init__(self, filename) 64 92 else: 65 if isinstance(filename, str):# or \ 66 # (isinstance(filename, list) or isinstance(filename, tuple)) \ 67 # and isinstance(filename[-1], str): 68 import os.path 93 if isinstance(filename, str): 69 94 filename = os.path.expandvars(filename) 70 95 filename = os.path.expanduser(filename) … … 73 98 if rcParams['verbose']: 74 99 asaplog.push(s) 75 #print asaplog.pop().strip()76 100 print_log('ERROR') 77 101 return 78 102 raise IOError(s) 79 if os.path.isdir(filename) \ 80 and not os.path.exists(filename+'/table.f1'): 81 # crude check if asap table 82 if os.path.exists(filename+'/table.info'): 83 ondisk = rcParams['scantable.storage'] == 'disk' 84 Scantable.__init__(self, filename, ondisk) 85 if unit is not None: 86 self.set_fluxunit(unit) 87 # do not reset to the default freqframe 88 #self.set_freqframe(rcParams['scantable.freqframe']) 103 if is_scantable(filename): 104 ondisk = rcParams['scantable.storage'] == 'disk' 105 Scantable.__init__(self, filename, ondisk) 106 if unit is not None: 107 self.set_fluxunit(unit) 108 # do not reset to the default freqframe 109 #self.set_freqframe(rcParams['scantable.freqframe']) 110 elif os.path.isdir(filename) \ 111 and not os.path.exists(filename+'/table.f1'): 112 msg = "The given file '%s'is not a valid " \ 113 "asap table." % (filename) 114 if rcParams['verbose']: 115 #print msg 116 asaplog.push( msg ) 117 print_log( 'ERROR' ) 118 return 89 119 else: 90 msg = "The given file '%s'is not a valid " \ 91 "asap table." % (filename) 92 if rcParams['verbose']: 93 #print msg 94 asaplog.push( msg ) 95 print_log( 'ERROR' ) 96 return 97 else: 98 raise IOError(msg) 120 raise IOError(msg) 99 121 else: 100 122 self._fill([filename], unit, average, getpt, antenna) … … 102 124 and isinstance(filename[-1], str): 103 125 self._fill(filename, unit, average, getpt, antenna) 126 self.parallactify(parallactify) 104 127 self._add_history("scantable", varlist) 105 128 print_log() 106 129 130 #@print_log_dec 107 131 def save(self, name=None, format=None, overwrite=False): 108 132 """ … … 119 143 'MS2' (saves as an aips++ 120 144 MeasurementSet V2) 121 'FITS' (save as image FITS - not 145 'FITS' (save as image FITS - not 122 146 readable by class) 123 147 'CLASS' (save as FITS readable by CLASS) … … 130 154 """ 131 155 from os import path 132 if format is None: format =rcParams['scantable.save']156 format = format or rcParams['scantable.save'] 133 157 suffix = '.'+format.lower() 134 158 if name is None or name == "": … … 203 227 else: raise 204 228 try: 205 bsel = self.get_selection() 206 sel = selector() 207 sel.set_scans(allscans) 208 self.set_selection(bsel+sel) 209 scopy = self._copy() 210 self.set_selection(bsel) 211 return scantable(scopy) 229 sel = selector(scans=allscans) 230 return self._select_copy(sel) 212 231 except RuntimeError: 213 232 if rcParams['verbose']: … … 219 238 raise 220 239 240 def _select_copy(self, selection): 241 orig = self.get_selection() 242 self.set_selection(orig+selection) 243 cp = self.copy() 244 self.set_selection(orig) 245 return cp 221 246 222 247 def get_scan(self, scanid=None): … … 253 278 if type(scanid) is str: 254 279 sel.set_name(scanid) 255 self.set_selection(bsel+sel) 256 scopy = self._copy() 257 self.set_selection(bsel) 258 return scantable(scopy) 280 return self._select_copy(sel) 259 281 elif type(scanid) is int: 260 282 sel.set_scans([scanid]) 261 self.set_selection(bsel+sel) 262 scopy = self._copy() 263 self.set_selection(bsel) 264 return scantable(scopy) 283 return self._select_copy(sel) 265 284 elif type(scanid) is list: 266 285 sel.set_scans(scanid) 267 self.set_selection(sel) 268 scopy = self._copy() 269 self.set_selection(bsel) 270 return scantable(scopy) 286 return self._select_copy(sel) 271 287 else: 272 288 msg = "Illegal scanid type, use 'int' or 'list' if ints." … … 294 310 filename: the name of a file to write the putput to 295 311 Default - no file output 296 verbose: print extra info such as the frequency table297 The default (False) is taken from .asaprc298 312 """ 299 313 info = Scantable._summary(self, True) 300 #if verbose is None: verbose = rcParams['scantable.verbosesummary']301 314 if filename is not None: 302 315 if filename is "": … … 328 341 """Return the spectrum for the current row in the scantable as a list. 329 342 Parameters: 330 rowno: the row number to retrieve the spectrum from 343 rowno: the row number to retrieve the spectrum from 331 344 """ 332 345 return self._getspectrum(rowno) … … 335 348 """Return the mask for the current row in the scantable as a list. 336 349 Parameters: 337 rowno: the row number to retrieve the mask from 350 rowno: the row number to retrieve the mask from 338 351 """ 339 352 return self._getmask(rowno) … … 343 356 Parameters: 344 357 spec: the spectrum 345 rowno: the row number to set the spectrum for 358 rowno: the row number to set the spectrum for 346 359 """ 347 360 assert(len(spec) == self.nchan()) 348 361 return self._setspectrum(spec, rowno) 362 363 def get_coordinate(self, rowno): 364 """Return the (spectral) coordinate for a a given 'rowno'. 365 NOTE: 366 * This coordinate is only valid until a scantable method modifies 367 the frequency axis. 368 * This coordinate does contain the original frequency set-up 369 NOT the new frame. The conversions however are done using the user 370 specified frame (e.g. LSRK/TOPO). To get the 'real' coordinate, 371 use scantable.freq_align first. Without it there is no closure, 372 i.e. 373 c = myscan.get_coordinate(0) 374 c.to_frequency(c.get_reference_pixel()) != c.get_reference_value() 375 376 Parameters: 377 rowno: the row number for the spectral coordinate 378 379 """ 380 return coordinate(Scantable.get_coordinate(self, rowno)) 349 381 350 382 def get_selection(self): … … 360 392 return selector(self._getselection()) 361 393 362 def set_selection(self, selection= selector()):394 def set_selection(self, selection=None, **kw): 363 395 """ 364 396 Select a subset of the data. All following operations on this scantable 365 397 are only applied to thi selection. 366 398 Parameters: 367 selection: a selector object (default unset the selection) 399 selection: a selector object (default unset the selection), 400 401 or 402 403 any combination of 404 "pols", "ifs", "beams", "scans", "cycles", "name", "query" 405 368 406 Examples: 369 407 sel = selector() # create a selection object … … 372 410 scan.summary() # will only print summary of scanno 0 an 3 373 411 scan.set_selection() # unset the selection 374 """ 412 # or the equivalent 413 scan.set_selection(scans=[0,3]) 414 scan.summary() # will only print summary of scanno 0 an 3 415 scan.set_selection() # unset the selection 416 """ 417 if selection is None: 418 # reset 419 if len(kw) == 0: 420 selection = selector() 421 else: 422 # try keywords 423 for k in kw: 424 if k not in selector.fields: 425 raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields)) 426 selection = selector(**kw) 375 427 self._setselection(selection) 376 428 … … 425 477 scan.stats(stat='mean', mask=m) 426 478 """ 427 if mask == None: 428 mask = [] 429 axes = ['Beam', 'IF', 'Pol', 'Time'] 479 mask = mask or [] 430 480 if not self._check_ifs(): 431 481 raise ValueError("Cannot apply mask as the IFs have different " … … 441 491 if not rtnabc: statvals = self._math._stats(self, mask, stat) 442 492 443 out = '' 444 axes = [] 493 #def cb(i): 494 # return statvals[i] 495 496 #return self._row_callback(cb, stat) 497 498 label=stat 499 #callback=cb 500 out = "" 501 #outvec = [] 502 sep = '-'*50 445 503 for i in range(self.nrow()): 446 axis = []447 axis.append(self.getscan(i))448 axis.append(self.getbeam(i))449 axis.append(self.getif(i))450 axis.append(self.getpol(i))451 axis.append(self.getcycle(i))452 axes.append(axis)453 tm = self._gettime(i)454 src = self._getsourcename(i)455 504 refstr = '' 456 505 statunit= '' … … 459 508 if rtnabc: 460 509 statvals.append(qx['value']) 461 #refstr = '(value: %3.3f' % (qy['value'])+' ['+qy['unit']+'])'462 510 refstr = ('(value: %'+form) % (qy['value'])+' ['+qy['unit']+'])' 463 511 statunit= '['+qx['unit']+']' 464 512 else: 465 #refstr = '(@ %3.3f' % (qx['value'])+' ['+qx['unit']+'])'466 513 refstr = ('(@ %'+form) % (qx['value'])+' ['+qx['unit']+'])' 467 #statunit= ' ['+qy['unit']+']' 468 out += 'Scan[%d] (%s) ' % (axis[0], src) 514 515 tm = self._gettime(i) 516 src = self._getsourcename(i) 517 out += 'Scan[%d] (%s) ' % (self.getscan(i), src) 469 518 out += 'Time[%s]:\n' % (tm) 470 if self.nbeam(-1) > 1: out += ' Beam[%d] ' % (axis[1]) 471 if self.nif(-1) > 1: out += ' IF[%d] ' % (axis[2]) 472 if self.npol(-1) > 1: out += ' Pol[%d] ' % (axis[3]) 473 #out += '= %3.3f ' % (statvals[i]) +refstr+'\n' 519 if self.nbeam(-1) > 1: 520 out += ' Beam[%d] ' % (self.getbeam(i)) 521 if self.nif(-1) > 1: out += ' IF[%d] ' % (self.getif(i)) 522 if self.npol(-1) > 1: out += ' Pol[%d] ' % (self.getpol(i)) 523 #outvec.append(callback(i)) 524 #out += ('= %'+form) % (outvec[i]) +' '+refstr+'\n' 474 525 out += ('= %'+form) % (statvals[i]) +' '+refstr+'\n' 475 out += "--------------------------------------------------\n"526 out += sep+"\n" 476 527 477 528 if rcParams['verbose']: … … 484 535 tmpfile='/tmp/tmp_'+usr+'_casapy_asap_scantable_stats' 485 536 f=open(tmpfile,'w') 486 print >> f, "--------------------------------------------------"487 print >> f, " ", stat, statunit488 print >> f, "--------------------------------------------------"537 print >> f, sep 538 print >> f, ' %s %s' % (label, statunit) 539 print >> f, sep 489 540 print >> f, out 490 541 f.close() … … 492 543 x=f.readlines() 493 544 f.close() 494 for xx in x: 495 asaplog.push( xx, False ) 545 blanc='' 546 asaplog.push(blanc.join(x), False) 547 #for xx in x: 548 # asaplog.push( xx, False ) 496 549 print_log() 497 #else:498 #retval = { 'axesnames': ['scanno', 'beamno', 'ifno', 'polno', 'cycleno'],499 # 'axes' : axes,500 # 'data': statvals}501 550 return statvals 502 551 … … 541 590 return list(Scantable.get_column_names(self)) 542 591 543 def get_tsys(self ):592 def get_tsys(self, row=-1): 544 593 """ 545 594 Return the System temperatures. … … 547 596 a list of Tsys values for the current selection 548 597 """ 549 598 if row > -1: 599 return self._get_column(self._gettsys, row) 550 600 return self._row_callback(self._gettsys, "Tsys") 551 601 602 603 def get_weather(self, row=-1): 604 values = self._get_column(self._get_weather, row) 605 if row > -1: 606 return {'temperature': values[0], 607 'pressure': values[1], 'humidity' : values[2], 608 'windspeed' : values[3], 'windaz' : values[4] 609 } 610 else: 611 out = [] 612 for r in values: 613 614 out.append({'temperature': r[0], 615 'pressure': r[1], 'humidity' : r[2], 616 'windspeed' : r[3], 'windaz' : r[4] 617 }) 618 return out 619 552 620 def _row_callback(self, callback, label): 553 axes = []554 axesnames = ['scanno', 'beamno', 'ifno', 'polno', 'cycleno']555 621 out = "" 556 622 outvec = [] 623 sep = '-'*50 557 624 for i in range(self.nrow()): 558 axis = []559 axis.append(self.getscan(i))560 axis.append(self.getbeam(i))561 axis.append(self.getif(i))562 axis.append(self.getpol(i))563 axis.append(self.getcycle(i))564 axes.append(axis)565 625 tm = self._gettime(i) 566 626 src = self._getsourcename(i) 567 out += 'Scan[%d] (%s) ' % ( axis[0], src)627 out += 'Scan[%d] (%s) ' % (self.getscan(i), src) 568 628 out += 'Time[%s]:\n' % (tm) 569 if self.nbeam(-1) > 1: out += ' Beam[%d] ' % (axis[1]) 570 if self.nif(-1) > 1: out += ' IF[%d] ' % (axis[2]) 571 if self.npol(-1) > 1: out += ' Pol[%d] ' % (axis[3]) 629 if self.nbeam(-1) > 1: 630 out += ' Beam[%d] ' % (self.getbeam(i)) 631 if self.nif(-1) > 1: out += ' IF[%d] ' % (self.getif(i)) 632 if self.npol(-1) > 1: out += ' Pol[%d] ' % (self.getpol(i)) 572 633 outvec.append(callback(i)) 573 634 out += '= %3.3f\n' % (outvec[i]) 574 out += "--------------------------------------------------\n"635 out += sep+'\n' 575 636 if rcParams['verbose']: 576 asaplog.push( "--------------------------------------------------")637 asaplog.push(sep) 577 638 asaplog.push(" %s" % (label)) 578 asaplog.push( "--------------------------------------------------")639 asaplog.push(sep) 579 640 asaplog.push(out) 580 641 print_log() 581 # disabled because the vector seems more useful582 #retval = {'axesnames': axesnames, 'axes': axes, 'data': outvec}583 642 return outvec 584 643 … … 624 683 none 625 684 """ 626 return self._get_column(self._getinttime, row) 627 685 return self._get_column(self._getinttime, row) 686 628 687 629 688 def get_sourcename(self, row=-1): … … 674 733 """ 675 734 Get a list of Positions on the sky (direction) for the observations. 676 Return a floatfor each integration in the scantable.735 Return a string for each integration in the scantable. 677 736 Parameters: 678 737 row: row no of integration. Default -1 return all rows … … 693 752 return self._get_column(self._getdirectionvec, row) 694 753 754 #@print_log_dec 695 755 def set_unit(self, unit='channel'): 696 756 """ … … 708 768 self._add_history("set_unit", varlist) 709 769 770 #@print_log_dec 710 771 def set_instrument(self, instr): 711 772 """ … … 719 780 print_log() 720 781 782 #@print_log_dec 721 783 def set_feedtype(self, feedtype): 722 784 """ … … 729 791 print_log() 730 792 793 #@print_log_dec 731 794 def set_doppler(self, doppler='RADIO'): 732 795 """ … … 742 805 print_log() 743 806 807 #@print_log_dec 744 808 def set_freqframe(self, frame=None): 745 809 """ … … 747 811 Parameters: 748 812 frame: an optional frame type, default 'LSRK'. Valid frames are: 749 ' REST', 'TOPO', 'LSRD', 'LSRK', 'BARY',813 'TOPO', 'LSRD', 'LSRK', 'BARY', 750 814 'GEO', 'GALACTO', 'LGROUP', 'CMB' 751 815 Examples: 752 816 scan.set_freqframe('BARY') 753 817 """ 754 if frame is None: frame = rcParams['scantable.freqframe'] 755 varlist = vars() 756 valid = ['REST', 'TOPO', 'LSRD', 'LSRK', 'BARY', \ 818 frame = frame or rcParams['scantable.freqframe'] 819 varlist = vars() 820 # "REST" is not implemented in casacore 821 #valid = ['REST', 'TOPO', 'LSRD', 'LSRK', 'BARY', \ 822 # 'GEO', 'GALACTO', 'LGROUP', 'CMB'] 823 valid = ['TOPO', 'LSRD', 'LSRK', 'BARY', \ 757 824 'GEO', 'GALACTO', 'LGROUP', 'CMB'] 758 825 … … 829 896 """ 830 897 varlist = vars() 831 if mask is None: 832 mask = [] 898 mask = mask or [] 833 899 try: 834 900 self._flag(mask, unflag) … … 883 949 else: raise 884 950 self._add_history("clip", varlist) 885 886 def lag_flag(self, frequency, width=0.0, unit="GHz", insitu=None): 951 952 #@print_log_dec 953 def lag_flag(self, start, end, unit="MHz", insitu=None): 954 #def lag_flag(self, frequency, width=0.0, unit="GHz", insitu=None): 887 955 """ 888 956 Flag the data in 'lag' space by providing a frequency to remove. 889 Flagged data in the scantable gets set to 0.0 before the fft.957 Flagged data in the scantable gets interpolated over the region. 890 958 No taper is applied. 891 959 Parameters: 892 frequency: the frequency (really a period within the bandwidth)893 894 width: the width of the frequency to remove, to remove a895 range of frequencies around the centre.896 unit: the frequency unit (default "GHz")960 start: the start frequency (really a period within the 961 bandwidth) or period to remove 962 end: the end frequency or period to remove 963 unit: the frequency unit (default "MHz") or "" for 964 explicit lag channels 897 965 Notes: 898 It is recommended to flag edges of the band or strong 966 It is recommended to flag edges of the band or strong 899 967 signals beforehand. 900 968 """ … … 902 970 self._math._setinsitu(insitu) 903 971 varlist = vars() 904 base = { "GHz": 1000000000., "MHz": 1000000., "kHz": 1000., "Hz": 1. 905 if not base.has_key(unit):972 base = { "GHz": 1000000000., "MHz": 1000000., "kHz": 1000., "Hz": 1.} 973 if not (unit == "" or base.has_key(unit)): 906 974 raise ValueError("%s is not a valid unit." % unit) 907 975 try: 908 s = scantable(self._math._lag_flag(self, frequency*base[unit], 909 width*base[unit])) 976 if unit == "": 977 s = scantable(self._math._lag_flag(self, start, end, "lags")) 978 else: 979 s = scantable(self._math._lag_flag(self, start*base[unit], 980 end*base[unit], "frequency")) 910 981 except RuntimeError, msg: 911 982 if rcParams['verbose']: … … 923 994 return s 924 995 925 996 #@print_log_dec 926 997 def create_mask(self, *args, **kwargs): 927 998 """ … … 952 1023 c) 953 1024 mask only channel 400 954 msk = scan.create_mask([400, 400]) 955 """ 956 row = 0 957 if kwargs.has_key("row"): 958 row = kwargs.get("row") 1025 msk = scan.create_mask([400]) 1026 """ 1027 row = kwargs.get("row", 0) 959 1028 data = self._getabcissa(row) 960 1029 u = self._getcoordinfo()[0] … … 973 1042 and args or args[0] 974 1043 for window in ws: 975 if (len(window) != 2 or window[0] > window[1] ): 976 raise TypeError("A window needs to be defined as [min, max]") 1044 if len(window) == 1: 1045 window = [window[0], window[0]] 1046 if len(window) == 0 or len(window) > 2: 1047 raise ValueError("A window needs to be defined as [start(, end)]") 1048 if window[0] > window[1]: 1049 tmp = window[0] 1050 window[0] = window[1] 1051 window[1] = tmp 977 1052 for i in range(n): 978 1053 if data[i] >= window[0] and data[i] <= window[1]: … … 1127 1202 source and IF basis, use scantable.set_selection() before using 1128 1203 this function. 1129 # provide your scantable is call scan1204 # provide your scantable is called scan 1130 1205 selection = selector() 1131 1206 selection.set_name("ORION*") … … 1188 1263 1189 1264 def shift_refpix(self, delta): 1190 1191 Shift the reference pixel of the Spectra Coordinate by an 1192 1193 1194 1265 """ 1266 Shift the reference pixel of the Spectra Coordinate by an 1267 integer amount. 1268 Parameters: 1269 delta: the amount to shift by 1195 1270 Note: 1196 1197 """ 1198 Scantable.shift(self, delta)1271 Be careful using this with broadband data. 1272 """ 1273 Scantable.shift_refpix(self, delta) 1199 1274 1200 1275 def history(self, filename=None): … … 1249 1324 # Maths business 1250 1325 # 1251 1326 #@print_log_dec 1252 1327 def average_time(self, mask=None, scanav=False, weight='tint', align=False): 1253 1328 """ … … 1275 1350 """ 1276 1351 varlist = vars() 1277 if weight is None: weight = 'TINT' 1278 if mask is None: mask = () 1279 if scanav: scanav = "SCAN" 1280 else: scanav = "NONE" 1352 weight = weight or 'TINT' 1353 mask = mask or () 1354 scanav = (scanav and 'SCAN') or 'NONE' 1281 1355 scan = (self, ) 1282 1356 try: … … 1302 1376 return s 1303 1377 1378 #@print_log_dec 1304 1379 def convert_flux(self, jyperk=None, eta=None, d=None, insitu=None): 1305 1380 """ … … 1321 1396 self._math._setinsitu(insitu) 1322 1397 varlist = vars() 1323 if jyperk is None: jyperk =-1.01324 if d is None: d =-1.01325 if eta is None: eta =-1.01398 jyperk = jyperk or -1.0 1399 d = d or -1.0 1400 eta = eta or -1.0 1326 1401 s = scantable(self._math._convertflux(self, d, eta, jyperk)) 1327 1402 s._add_history("convert_flux", varlist) … … 1330 1405 else: return s 1331 1406 1407 #@print_log_dec 1332 1408 def gain_el(self, poly=None, filename="", method="linear", insitu=None): 1333 1409 """ … … 1373 1449 self._math._setinsitu(insitu) 1374 1450 varlist = vars() 1375 if poly is None: 1376 poly = () 1451 poly = poly or () 1377 1452 from os.path import expandvars 1378 1453 filename = expandvars(filename) … … 1380 1455 s._add_history("gain_el", varlist) 1381 1456 print_log() 1382 if insitu: self._assign(s) 1383 else: return s 1384 1457 if insitu: 1458 self._assign(s) 1459 else: 1460 return s 1461 1462 #@print_log_dec 1385 1463 def freq_align(self, reftime=None, method='cubic', insitu=None): 1386 1464 """ … … 1401 1479 self._math._setinsitu(insitu) 1402 1480 varlist = vars() 1403 if reftime is None: reftime =""1481 reftime = reftime or "" 1404 1482 s = scantable(self._math._freq_align(self, reftime, method)) 1405 1483 s._add_history("freq_align", varlist) … … 1408 1486 else: return s 1409 1487 1410 def opacity(self, tau, insitu=None): 1488 #@print_log_dec 1489 def opacity(self, tau=None, insitu=None): 1411 1490 """ 1412 1491 Apply an opacity correction. The data 1413 1492 and Tsys are multiplied by the correction factor. 1414 1493 Parameters: 1415 tau: Opacity from which the correction factor is1494 tau: (list of) opacity from which the correction factor is 1416 1495 exp(tau*ZD) 1417 where ZD is the zenith-distance 1496 where ZD is the zenith-distance. 1497 If a list is provided, it has to be of length nIF, 1498 nIF*nPol or 1 and in order of IF/POL, e.g. 1499 [opif0pol0, opif0pol1, opif1pol0 ...] 1500 if tau is `None` the opacities are determined from a 1501 model. 1418 1502 insitu: if False a new scantable is returned. 1419 1503 Otherwise, the scaling is done in-situ … … 1423 1507 self._math._setinsitu(insitu) 1424 1508 varlist = vars() 1509 if not hasattr(tau, "__len__"): 1510 tau = [tau] 1425 1511 s = scantable(self._math._opacity(self, tau)) 1426 1512 s._add_history("opacity", varlist) … … 1429 1515 else: return s 1430 1516 1517 #@print_log_dec 1431 1518 def bin(self, width=5, insitu=None): 1432 1519 """ … … 1444 1531 s._add_history("bin", varlist) 1445 1532 print_log() 1446 if insitu: self._assign(s) 1447 else: return s 1448 1449 1533 if insitu: 1534 self._assign(s) 1535 else: 1536 return s 1537 1538 #@print_log_dec 1450 1539 def resample(self, width=5, method='cubic', insitu=None): 1451 1540 """ … … 1470 1559 else: return s 1471 1560 1472 1561 #@print_log_dec 1473 1562 def average_pol(self, mask=None, weight='none'): 1474 1563 """ … … 1482 1571 """ 1483 1572 varlist = vars() 1484 if mask is None: 1485 mask = () 1573 mask = mask or () 1486 1574 s = scantable(self._math._averagepol(self, mask, weight.upper())) 1487 1575 s._add_history("average_pol", varlist) … … 1489 1577 return s 1490 1578 1579 #@print_log_dec 1491 1580 def average_beam(self, mask=None, weight='none'): 1492 1581 """ … … 1500 1589 """ 1501 1590 varlist = vars() 1502 if mask is None: 1503 mask = () 1591 mask = mask or () 1504 1592 s = scantable(self._math._averagebeams(self, mask, weight.upper())) 1505 1593 s._add_history("average_beam", varlist) … … 1507 1595 return s 1508 1596 1597 def parallactify(self, pflag): 1598 """ 1599 Set a flag to inidcate whether this data should be treated as having 1600 been 'parallactified' (total phase == 0.0) 1601 Parameters: 1602 pflag: Bool inidcating whether to turn this on (True) or 1603 off (False) 1604 """ 1605 varlist = vars() 1606 self._parallactify(pflag) 1607 self._add_history("parallactify", varlist) 1608 1609 #@print_log_dec 1509 1610 def convert_pol(self, poltype=None): 1510 1611 """ 1511 1612 Convert the data to a different polarisation type. 1613 Note that you will need cross-polarisation terms for most conversions. 1512 1614 Parameters: 1513 1615 poltype: The new polarisation type. Valid types are: 1514 "linear", " stokes" and "circular"1616 "linear", "circular", "stokes" and "linpol" 1515 1617 """ 1516 1618 varlist = vars() … … 1530 1632 return s 1531 1633 1532 # def smooth(self, kernel="hanning", width=5.0, insitu=None):1533 def smooth(self, kernel="hanning", width=5.0, plot=False, insitu=None):1634 #@print_log_dec 1635 def smooth(self, kernel="hanning", width=5.0, order=2, plot=False, insitu=None): 1534 1636 """ 1535 1637 Smooth the spectrum by the specified kernel (conserving flux). 1536 1638 Parameters: 1537 1639 kernel: The type of smoothing kernel. Select from 1538 'hanning' (default), 'gaussian', 'boxcar' and1539 'rmedian'1640 'hanning' (default), 'gaussian', 'boxcar', 'rmedian' 1641 or 'poly' 1540 1642 width: The width of the kernel in pixels. For hanning this is 1541 1643 ignored otherwise it defauls to 5 pixels. 1542 1644 For 'gaussian' it is the Full Width Half 1543 1645 Maximum. For 'boxcar' it is the full width. 1544 For 'rmedian' it is the half width. 1646 For 'rmedian' and 'poly' it is the half width. 1647 order: Optional parameter for 'poly' kernel (default is 2), to 1648 specify the order of the polnomial. Ignored by all other 1649 kernels. 1545 1650 plot: plot the original and the smoothed spectra. 1546 1651 In this each indivual fit has to be approved, by … … 1558 1663 if plot: orgscan = self.copy() 1559 1664 1560 s = scantable(self._math._smooth(self, kernel.lower(), width ))1665 s = scantable(self._math._smooth(self, kernel.lower(), width, order)) 1561 1666 s._add_history("smooth", varlist) 1562 1667 … … 1601 1706 else: return s 1602 1707 1603 1604 def poly_baseline(self, mask=None, order=0, plot=False, uselin=False, insitu=None): 1708 #@print_log_dec 1709 def poly_baseline(self, mask=None, order=0, plot=False, uselin=False, 1710 insitu=None): 1605 1711 """ 1606 1712 Return a scan which has been baselined (all rows) by a polynomial. … … 1833 1939 return workscan 1834 1940 1941 #@print_log_dec 1835 1942 def rotate_linpolphase(self, angle): 1836 1943 """ … … 1849 1956 return 1850 1957 1851 1958 #@print_log_dec 1852 1959 def rotate_xyphase(self, angle): 1853 1960 """ … … 1866 1973 return 1867 1974 1975 #@print_log_dec 1868 1976 def swap_linears(self): 1869 1977 """ 1870 Swap the linear polarisations XX and YY, or better the first two 1978 Swap the linear polarisations XX and YY, or better the first two 1871 1979 polarisations as this also works for ciculars. 1872 1980 """ … … 1877 1985 return 1878 1986 1987 #@print_log_dec 1879 1988 def invert_phase(self): 1880 1989 """ … … 1887 1996 return 1888 1997 1998 #@print_log_dec 1889 1999 def add(self, offset, insitu=None): 1890 2000 """ … … 1907 2017 return s 1908 2018 2019 #@print_log_dec 1909 2020 def scale(self, factor, tsys=True, insitu=None): 1910 2021 """ … … 1972 2083 self._setsourcetype(stype) 1973 2084 self.set_selection(basesel) 1974 s._add_history("set_sourcetype", varlist) 1975 2085 self._add_history("set_sourcetype", varlist) 2086 2087 #@print_log_dec 1976 2088 def auto_quotient(self, preserve=True, mode='paired', verify=False): 1977 2089 """ … … 1984 2096 preserve: Output = Toff * (on/off) - Toff 1985 2097 remove: Output = Toff * (on/off) - Ton 1986 mode: the on/off detection mode 2098 mode: the on/off detection mode 1987 2099 'paired' (default) 1988 2100 identifies 'off' scans by the … … 2017 2129 return s 2018 2130 2131 #@print_log_dec 2019 2132 def mx_quotient(self, mask = None, weight='median', preserve=True): 2020 2133 """ … … 2028 2141 remove: Output = Toff * (on/off) - Ton 2029 2142 """ 2030 if mask is None: mask =()2143 mask = mask or () 2031 2144 varlist = vars() 2032 2145 on = scantable(self._math._mx_extract(self, 'on')) … … 2039 2152 return q 2040 2153 2154 #@print_log_dec 2041 2155 def freq_switch(self, insitu=None): 2042 2156 """ … … 2058 2172 else: return s 2059 2173 2174 #@print_log_dec 2060 2175 def recalc_azel(self): 2061 2176 """ … … 2071 2186 return 2072 2187 2188 #@print_log_dec 2073 2189 def __add__(self, other): 2074 2190 """ … … 2077 2193 return self._operation( other, "ADD" ) 2078 2194 2195 #@print_log_dec 2079 2196 def __sub__(self, other): 2080 2197 """ … … 2083 2200 return self._operation( other, 'SUB' ) 2084 2201 2202 #@print_log_dec 2085 2203 def __mul__(self, other): 2086 2204 """ … … 2089 2207 return self._operation( other, 'MUL' ) 2090 2208 2209 #@print_log_dec 2091 2210 def __div__(self, other): 2092 2211 """ … … 2120 2239 basesel = self.get_selection() 2121 2240 for i in range(self.nrow()): 2122 sel = selector()+basesel 2123 sel.set_scans(self.getscan(i)) 2124 sel.set_beams(self.getbeam(i)) 2125 sel.set_ifs(self.getif(i)) 2126 sel.set_polarisations(self.getpol(i)) 2127 self.set_selection(sel) 2241 sel = self.get_row_selector(i) 2242 self.set_selection(basesel+sel) 2128 2243 nans = numpy.isnan(self._getspectrum(0)) 2129 2244 if numpy.any(nans): … … 2131 2246 self.flag(bnans) 2132 2247 self.set_selection(basesel) 2133 2248 2249 def get_row_selector(self, rowno): 2250 return selector(beams=self.getbeam(rowno), 2251 ifs=self.getif(rowno), 2252 pols=self.getpol(rowno), 2253 scans=self.getscan(rowno), 2254 cycles=self.getcycle(rowno)) 2134 2255 2135 2256 def _add_history(self, funcname, parameters):
Note: See TracChangeset
for help on using the changeset viewer.