- Timestamp:
- 07/02/09 12:17:20 (15 years ago)
- Location:
- trunk/python
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/__init__.py
r1588 r1589 4 4 """ 5 5 import os,sys,shutil, platform 6 import functools 6 7 7 8 # Set up AIPSPATH and first time use of asap i.e. ~/.asap/* … … 351 352 asaplog.disable() 352 353 354 355 def print_log_dec(f): 356 @functools.wraps(f) 357 def wrap_it(*args, **kw): 358 val = f(*args, **kw) 359 print_log() 360 return val 361 return wrap_it 362 353 363 def print_log(): 354 log = asaplog.pop() 364 log = asaplog.pop().strip() 355 365 if len(log) and rcParams['verbose']: print log 356 366 return … … 395 405 def is_ipython(): 396 406 return '__IP' in dir(sys.modules["__main__"]) 397 407 398 408 if is_ipython(): 399 409 def version(): print "ASAP %s(%s)"% (__version__, __date__) -
trunk/python/asapfitter.py
r1536 r1589 1 1 import _asap 2 2 from asap import rcParams 3 from asap import print_log 3 from asap import print_log_dec 4 4 from asap import _n_bools 5 5 from asap import mask_and … … 76 76 Set the function to be fit. 77 77 Parameters: 78 poly: use a polynomial of the order given with nonlinear least squares fit 78 poly: use a polynomial of the order given with nonlinear least squares fit 79 79 lpoly: use polynomial of the order given with linear least squares fit 80 80 gauss: fit the number of gaussian specified … … 90 90 n = kwargs.get('poly') 91 91 self.components = [n] 92 self.uselinear = False 92 self.uselinear = False 93 93 elif kwargs.has_key('lpoly'): 94 94 self.fitfunc = 'poly' … … 101 101 self.fitfuncs = [ 'gauss' for i in range(n) ] 102 102 self.components = [ 3 for i in range(n) ] 103 self.uselinear = False 103 self.uselinear = False 104 104 else: 105 105 msg = "Invalid function type." … … 114 114 return 115 115 116 @print_log_dec 116 117 def fit(self, row=0, estimate=False): 117 118 """ … … 150 151 self.data.getbeam(i), 151 152 self.data.getif(i), 152 self.data.getpol(i), 153 self.data.getpol(i), 153 154 self.data.getcycle(i)) 154 155 asaplog.push(out,False) … … 175 176 self._fittedrow = row 176 177 self.fitted = True 177 print_log()178 178 return 179 179 … … 204 204 self.data._addfit(fit,self._fittedrow) 205 205 206 #def set_parameters(self, params, fixed=None, component=None):206 @print_log_dec 207 207 def set_parameters(self,*args,**kwargs): 208 208 """ … … 247 247 if fixed is not None: 248 248 self.fitter.setfixedparameters(fixed) 249 print_log()250 249 return 251 250 … … 461 460 return self.fitter.getfit() 462 461 462 @print_log_dec 463 463 def commit(self): 464 464 """ … … 482 482 scan = self.data.copy() 483 483 scan._setspectrum(self.fitter.getresidual()) 484 print_log()485 484 return scan 486 485 486 @print_log_dec 487 487 def plot(self, residual=False, components=None, plotparms=False, filename=None): 488 488 """ … … 520 520 array(self.data._getmask(self._fittedrow), 521 521 copy=False)) 522 522 523 523 ylab = self.data._get_ordinate_label() 524 524 … … 570 570 if (not rcParams['plotter.gui']): 571 571 self._p.save(filename) 572 print_log() 573 572 573 @print_log_dec 574 574 def auto_fit(self, insitu=None, plot=False): 575 575 """ … … 598 598 scan.getbeam(r), 599 599 scan.getif(r), 600 scan.getpol(r), 600 scan.getpol(r), 601 601 scan.getcycle(r)) 602 602 asaplog.push(out, False) … … 616 616 self._p.unmap() 617 617 self._p = None 618 print_log()619 618 return scan 620 -
trunk/python/asapmath.py
r1391 r1589 1 1 from asap.scantable import scantable 2 2 from asap import rcParams 3 from asap import print_log 3 from asap import print_log_dec 4 4 from asap import selector 5 5 6 @print_log_dec 6 7 def average_time(*args, **kwargs): 7 8 """ … … 27 28 # without using a mask 28 29 scanav = average_time(scana,scanb) 29 30 30 # or equivalent 31 # scanav = average_time([scana, scanb]) 31 32 # return the (time) averaged scan, i.e. the average of 32 33 # all correlator cycles … … 88 89 s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav)) 89 90 s._add_history("average_time",varlist) 90 print_log()91 91 return s 92 92 … … 111 111 s = scantable(stm._quotient(source, reference, preserve)) 112 112 s._add_history("quotient",varlist) 113 print_log()114 113 return s 115 114 115 @print_log_dec 116 116 def dototalpower(calon, caloff, tcalval=0.0): 117 117 """ … … 129 129 s = scantable(stm._dototalpower(calon, caloff, tcalval)) 130 130 s._add_history("dototalpower",varlist) 131 print_log()132 131 return s 133 132 133 @print_log_dec 134 134 def dosigref(sig, ref, smooth, tsysval=0.0, tauval=0.0): 135 135 """ … … 149 149 s = scantable(stm._dosigref(sig, ref, smooth, tsysval, tauval)) 150 150 s._add_history("dosigref",varlist) 151 print_log()152 151 return s 153 152 153 @print_log_dec 154 154 def calps(scantab, scannos, smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0): 155 155 """ … … 237 237 ress = dosigref(sig, ref, smooth, tsysval, tauval) 238 238 ress._add_history("calps", varlist) 239 print_log()240 239 return ress 241 240 241 @print_log_dec 242 242 def calnod(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0): 243 243 """ … … 308 308 resspec = scantable(stm._donod(scantab, pairScans, smooth, tsysval,tauval,tcalval)) 309 309 resspec._add_history("calnod",varlist) 310 print_log()311 310 return resspec 312 311 312 @print_log_dec 313 313 def calfs(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0): 314 314 """ … … 349 349 resspec = scantable(stm._dofs(s, scannos, smooth, tsysval,tauval,tcalval)) 350 350 resspec._add_history("calfs",varlist) 351 print_log()352 351 return resspec 353 352 … … 367 366 print "simple_math is deprecated use +=/* instead." 368 367 368 @print_log_dec 369 369 def merge(*args): 370 370 """ … … 375 375 Example: 376 376 myscans = [scan1, scan2] 377 378 379 377 allscans = merge(myscans) 378 # or equivalent 379 sameallscans = merge(scan1, scan2) 380 380 """ 381 381 varlist = vars() … … 400 400 s = scantable(stm._merge(lst)) 401 401 s._add_history("merge", varlist) 402 print_log()403 402 return s 404 -
trunk/python/scantable.py
r1588 r1589 1 1 from asap._asap import Scantable 2 2 from asap import rcParams 3 from asap import print_log 3 from asap import print_log, print_log_dec 4 4 from asap import asaplog 5 5 from asap import selector … … 11 11 The ASAP container for scans 12 12 """ 13 13 @print_log_dec 14 14 def __init__(self, filename, average=None, unit=None, parallactify=None): 15 15 """ … … 53 53 if rcParams['verbose']: 54 54 asaplog.push(s) 55 print asaplog.pop().strip()55 #print asaplog.pop().strip() 56 56 return 57 57 raise IOError(s) … … 80 80 self.parallactify(parallactify) 81 81 self._add_history("scantable", varlist) 82 print_log() 83 82 83 @print_log_dec 84 84 def save(self, name=None, format=None, overwrite=False): 85 85 """ … … 129 129 writer = stw(format2) 130 130 writer.write(self, name) 131 print_log()132 131 return 133 132 … … 587 586 self._add_history("set_unit", varlist) 588 587 588 @print_log_dec 589 589 def set_instrument(self, instr): 590 590 """ … … 596 596 self._setInstrument(instr) 597 597 self._add_history("set_instument", vars()) 598 print_log() 599 598 599 @print_log_dec 600 600 def set_feedtype(self, feedtype): 601 601 """ … … 606 606 self._setfeedtype(feedtype) 607 607 self._add_history("set_feedtype", vars()) 608 print_log() 609 608 609 @print_log_dec 610 610 def set_doppler(self, doppler='RADIO'): 611 611 """ … … 619 619 self._setcoordinfo(inf) 620 620 self._add_history("set_doppler", vars()) 621 print_log() 622 621 622 @print_log_dec 623 623 def set_freqframe(self, frame=None): 624 624 """ … … 647 647 else: 648 648 raise TypeError(msg) 649 print_log()650 649 651 650 def set_dirframe(self, frame=""): … … 691 690 abc = self._getabcissa(rowno) 692 691 lbl = self._getabcissalabel(rowno) 693 print_log()694 692 return abc, lbl 695 693 … … 713 711 self._add_history("flag", varlist) 714 712 713 @print_log_dec 715 714 def lag_flag(self, start, end, unit="MHz", insitu=None): 716 715 """ … … 746 745 else: raise 747 746 s._add_history("lag_flag", varlist) 748 print_log()749 747 if insitu: 750 748 self._assign(s) … … 752 750 return s 753 751 754 752 @print_log_dec 755 753 def create_mask(self, *args, **kwargs): 756 754 """ … … 814 812 if kwargs.get('invert'): 815 813 msk = mask_not(msk) 816 print_log()817 814 return msk 818 815 … … 915 912 916 913 def shift_refpix(self, delta): 917 918 919 920 921 914 """ 915 Shift the reference pixel of the Spectra Coordinate by an 916 integer amount. 917 Parameters: 918 delta: the amount to shift by 922 919 Note: 923 924 """ 925 920 Be careful using this with broadband data. 921 """ 922 Scantable.shift(self, delta) 926 923 927 924 def history(self, filename=None): … … 974 971 # Maths business 975 972 # 976 973 @print_log_dec 977 974 def average_time(self, mask=None, scanav=False, weight='tint', align=False): 978 975 """ … … 1021 1018 else: raise 1022 1019 s._add_history("average_time", varlist) 1023 print_log()1024 1020 return s 1025 1021 1022 @print_log_dec 1026 1023 def convert_flux(self, jyperk=None, eta=None, d=None, insitu=None): 1027 1024 """ … … 1048 1045 s = scantable(self._math._convertflux(self, d, eta, jyperk)) 1049 1046 s._add_history("convert_flux", varlist) 1050 print_log()1051 1047 if insitu: self._assign(s) 1052 1048 else: return s 1053 1049 1050 @print_log_dec 1054 1051 def gain_el(self, poly=None, filename="", method="linear", insitu=None): 1055 1052 """ … … 1101 1098 s = scantable(self._math._gainel(self, poly, filename, method)) 1102 1099 s._add_history("gain_el", varlist) 1103 print_log()1104 1100 if insitu: self._assign(s) 1105 1101 else: return s 1106 1102 1103 @print_log_dec 1107 1104 def freq_align(self, reftime=None, method='cubic', insitu=None): 1108 1105 """ … … 1126 1123 s = scantable(self._math._freq_align(self, reftime, method)) 1127 1124 s._add_history("freq_align", varlist) 1128 print_log()1129 1125 if insitu: self._assign(s) 1130 1126 else: return s 1131 1127 1128 @print_log_dec 1132 1129 def opacity(self, tau, insitu=None): 1133 1130 """ … … 1147 1144 s = scantable(self._math._opacity(self, tau)) 1148 1145 s._add_history("opacity", varlist) 1149 print_log()1150 1146 if insitu: self._assign(s) 1151 1147 else: return s 1152 1148 1149 @print_log_dec 1153 1150 def bin(self, width=5, insitu=None): 1154 1151 """ … … 1165 1162 s = scantable(self._math._bin(self, width)) 1166 1163 s._add_history("bin", varlist) 1167 print_log() 1168 if insitu: self._assign(s) 1169 else: return s 1170 1171 1164 if insitu: 1165 self._assign(s) 1166 else: 1167 return s 1168 1169 @print_log_dec 1172 1170 def resample(self, width=5, method='cubic', insitu=None): 1173 1171 """ … … 1188 1186 s = scantable(self._math._resample(self, method, width)) 1189 1187 s._add_history("resample", varlist) 1190 print_log()1191 1188 if insitu: self._assign(s) 1192 1189 else: return s 1193 1190 1194 1191 @print_log_dec 1195 1192 def average_pol(self, mask=None, weight='none'): 1196 1193 """ … … 1208 1205 s = scantable(self._math._averagepol(self, mask, weight.upper())) 1209 1206 s._add_history("average_pol", varlist) 1210 print_log()1211 1207 return s 1212 1208 1209 @print_log_dec 1213 1210 def average_beam(self, mask=None, weight='none'): 1214 1211 """ … … 1226 1223 s = scantable(self._math._averagebeams(self, mask, weight.upper())) 1227 1224 s._add_history("average_beam", varlist) 1228 print_log()1229 1225 return s 1230 1226 … … 1234 1230 self._add_history("parallactify", varlist) 1235 1231 1232 @print_log_dec 1236 1233 def convert_pol(self, poltype=None): 1237 1234 """ … … 1252 1249 raise 1253 1250 s._add_history("convert_pol", varlist) 1254 print_log()1255 1251 return s 1256 1252 1253 @print_log_dec 1257 1254 def smooth(self, kernel="hanning", width=5.0, order=2, insitu=None): 1258 1255 """ … … 1281 1278 s = scantable(self._math._smooth(self, kernel.lower(), width, order)) 1282 1279 s._add_history("smooth", varlist) 1283 print_log()1284 1280 if insitu: self._assign(s) 1285 1281 else: return s 1286 1282 1287 1283 @print_log_dec 1288 1284 def poly_baseline(self, mask=None, order=0, plot=False, uselin=False, insitu=None): 1289 1285 """ … … 1319 1315 s = f.auto_fit(insitu, plot=plot) 1320 1316 s._add_history("poly_baseline", varlist) 1321 print_log()1322 1317 if insitu: self._assign(s) 1323 1318 else: return s … … 1329 1324 else: 1330 1325 raise RuntimeError(msg) 1331 1332 1326 1333 1327 def auto_poly_baseline(self, mask=[], edge=(0, 0), order=0, … … 1448 1442 return workscan 1449 1443 1444 @print_log_dec 1450 1445 def rotate_linpolphase(self, angle): 1451 1446 """ … … 1461 1456 self._math._rotate_linpolphase(self, angle) 1462 1457 self._add_history("rotate_linpolphase", varlist) 1463 print_log()1464 1458 return 1465 1459 1466 1460 @print_log_dec 1467 1461 def rotate_xyphase(self, angle): 1468 1462 """ … … 1478 1472 self._math._rotate_xyphase(self, angle) 1479 1473 self._add_history("rotate_xyphase", varlist) 1480 print_log()1481 1474 return 1482 1475 1476 @print_log_dec 1483 1477 def swap_linears(self): 1484 1478 """ … … 1489 1483 self._math._swap_linears(self) 1490 1484 self._add_history("swap_linears", varlist) 1491 print_log()1492 1485 return 1493 1486 1487 @print_log_dec 1494 1488 def invert_phase(self): 1495 1489 """ … … 1499 1493 self._math._invert_phase(self) 1500 1494 self._add_history("invert_phase", varlist) 1501 print_log()1502 1495 return 1503 1496 1497 @print_log_dec 1504 1498 def add(self, offset, insitu=None): 1505 1499 """ … … 1516 1510 s = scantable(self._math._unaryop(self, offset, "ADD", False)) 1517 1511 s._add_history("add", varlist) 1518 print_log()1519 1512 if insitu: 1520 1513 self._assign(s) … … 1522 1515 return s 1523 1516 1517 @print_log_dec 1524 1518 def scale(self, factor, tsys=True, insitu=None): 1525 1519 """ … … 1538 1532 s = scantable(self._math._unaryop(self, factor, "MUL", tsys)) 1539 1533 s._add_history("scale", varlist) 1540 print_log()1541 1534 if insitu: 1542 1535 self._assign(s) … … 1580 1573 self._add_history("set_sourcetype", varlist) 1581 1574 1575 @print_log_dec 1582 1576 def auto_quotient(self, preserve=True, mode='paired'): 1583 1577 """ … … 1620 1614 s = scantable(self._math._auto_quotient(self, mode, preserve)) 1621 1615 s._add_history("auto_quotient", varlist) 1622 print_log()1623 1616 return s 1624 1617 1618 @print_log_dec 1625 1619 def mx_quotient(self, mask = None, weight='median', preserve=True): 1626 1620 """ … … 1642 1636 q = quotient(on, off, preserve) 1643 1637 q._add_history("mx_quotient", varlist) 1644 print_log()1645 1638 return q 1646 1639 1640 @print_log_dec 1647 1641 def freq_switch(self, insitu=None): 1648 1642 """ … … 1660 1654 s = scantable(self._math._freqswitch(self)) 1661 1655 s._add_history("freq_switch", varlist) 1662 print_log()1663 1656 if insitu: self._assign(s) 1664 1657 else: return s 1665 1658 1659 @print_log_dec 1666 1660 def recalc_azel(self): 1667 1661 """ … … 1674 1668 self._recalcazel() 1675 1669 self._add_history("recalc_azel", varlist) 1676 print_log()1677 1670 return 1678 1671 1672 @print_log_dec 1679 1673 def __add__(self, other): 1680 1674 varlist = vars() … … 1687 1681 raise TypeError("Other input is not a scantable or float value") 1688 1682 s._add_history("operator +", varlist) 1689 print_log()1690 1683 return s 1691 1684 1685 @print_log_dec 1692 1686 def __sub__(self, other): 1693 1687 """ … … 1703 1697 raise TypeError("Other input is not a scantable or float value") 1704 1698 s._add_history("operator -", varlist) 1705 print_log()1706 1699 return s 1707 1700 1701 @print_log_dec 1708 1702 def __mul__(self, other): 1709 1703 """ … … 1719 1713 raise TypeError("Other input is not a scantable or float value") 1720 1714 s._add_history("operator *", varlist) 1721 print_log()1722 1715 return s 1723 1716 1724 1717 1718 @print_log_dec 1725 1719 def __div__(self, other): 1726 1720 """ … … 1730 1724 s = None 1731 1725 if isinstance(other, scantable): 1732 1726 s = scantable(self._math._binaryop(self, other, "DIV")) 1733 1727 elif isinstance(other, float): 1734 1728 if other == 0.0: … … 1738 1732 raise TypeError("Other input is not a scantable or float value") 1739 1733 s._add_history("operator /", varlist) 1740 print_log()1741 1734 return s 1742 1735 … … 1764 1757 basesel = self.get_selection() 1765 1758 for i in range(self.nrow()): 1766 sel = selector()+basesel 1767 sel.set_scans(self.getscan(i)) 1768 sel.set_beams(self.getbeam(i)) 1769 sel.set_ifs(self.getif(i)) 1770 sel.set_polarisations(self.getpol(i)) 1771 self.set_selection(sel) 1759 sel = self.get_row_selector(i) 1760 self.set_selection(basesel+sel) 1772 1761 nans = numpy.isnan(self._getspectrum(0)) 1773 1762 if numpy.any(nans):
Note:
See TracChangeset
for help on using the changeset viewer.