Changeset 976 for trunk/python
- Timestamp:
- 04/03/06 16:39:42 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r946 r976 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, asaplog 4 4 from asap import selector 5 5 from numarray import ones,zeros … … 30 30 in existing scantables 31 31 """ 32 if average is None or type(average) is not bool:32 if average is None: 33 33 average = rcParams['scantable.autoaverage'] 34 35 34 varlist = vars() 36 35 from asap._asap import stmath 37 36 self._math = stmath() 38 from asap import asaplog39 37 if isinstance(filename, Scantable): 40 38 Scantable.__init__(self, filename) 41 if unit is not None: 42 self.set_fluxunit(unit) 43 else: 44 import os.path 45 if not os.path.exists(filename): 46 s = "File '%s' not found." % (filename) 47 if rcParams['verbose']: 48 asaplog.push(s) 49 print asaplog.pop().strip() 50 return 51 raise IOError(s) 52 filename = os.path.expandvars(filename) 53 if os.path.isdir(filename): 54 # crude check if asap table 55 if os.path.exists(filename+'/table.info'): 56 Scantable.__init__(self, filename, "memory") 57 if unit is not None: 58 self.set_fluxunit(unit) 39 else: 40 if isinstance(filename,str): 41 import os.path 42 filename = os.path.expandvars(filename) 43 filename = os.path.expanduser(filename) 44 if not os.path.exists(filename): 45 s = "File '%s' not found." % (filename) 46 if rcParams['verbose']: 47 asaplog.push(s) 48 print asaplog.pop().strip() 49 return 50 raise IOError(s) 51 if os.path.isdir(filename): 52 # crude check if asap table 53 if os.path.exists(filename+'/table.info'): 54 Scantable.__init__(self, filename, "memory") 55 if unit is not None: 56 self.set_fluxunit(unit) 57 self.set_freqframe(rcParams['scantable.freqframe']) 58 else: 59 msg = "The given file '%s'is not a valid asap table." % (filename) 60 if rcParams['verbose']: 61 print msg 62 return 63 else: 64 raise IOError(msg) 59 65 else: 60 msg = "The given file '%s'is not a valid asap table." % (filename) 61 if rcParams['verbose']: 62 print msg 63 return 64 else: 65 raise IOError(msg) 66 else: 67 from asap._asap import stfiller 68 ifSel = -1 69 beamSel = -1 70 r = stfiller() 71 r._open(filename,ifSel,beamSel) 72 asaplog.push('Importing data...') 73 print_log() 74 r._read() 75 tbl = r._getdata() 76 if unit is not None: 77 tbl.set_fluxunit(unit) 78 if average: 79 asaplog.push('Auto averaging integrations...') 80 print_log() 81 tbl2 = self._math._average((tbl,),(),'NONE','SCAN', False) 82 Scantable.__init__(self,tbl2) 83 del tbl2 84 else: 85 Scantable.__init__(self,tbl) 86 del r,tbl 87 self._add_history("scantable", varlist) 66 self._fill([filename],unit, average) 67 elif (isinstance(filename,list) or isinstance(filename,tuple)) \ 68 and isinstance(filename[-1], str): 69 self._fill(filename, unit, average) 88 70 print_log() 89 71 … … 209 191 return Scantable._summary(self,True) 210 192 211 def summary(self, filename=None , verbose=None):193 def summary(self, filename=None): 212 194 """ 213 195 Print a summary of the contents of this scantable. … … 218 200 The default (False) is taken from .asaprc 219 201 """ 220 info = Scantable._summary(self, verbose)221 if verbose is None: verbose = rcParams['scantable.verbosesummary']202 info = Scantable._summary(self, True) 203 #if verbose is None: verbose = rcParams['scantable.verbosesummary'] 222 204 if filename is not None: 223 205 if filename is "": … … 772 754 """ 773 755 varlist = vars() 774 if weight is None: weight = ' tint'756 if weight is None: weight = 'TINT' 775 757 if mask is None: mask = () 776 758 if scanav: … … 1046 1028 both sides of the spectrum. Default is to keep 1047 1029 all channels. Nested tuples represent individual 1048 1049 1030 edge selection for different IFs (a number of spectral 1031 channels can be different) 1050 1032 order: the order of the polynomial (default is 0) 1051 1033 threshold: the threshold used by line finder. It is better to … … 1065 1047 from asap import _is_sequence_or_number as _is_valid 1066 1048 1067 1068 1069 1070 1071 1049 # check whether edge is set up for each IF individually 1050 individualEdge = False; 1051 if len(edge)>1: 1052 if isinstance(edge[0],list) or isinstance(edge[0],tuple): 1053 individualEdge = True; 1072 1054 1073 1055 if not _is_valid(edge, int) and not individualEdge: … … 1076 1058 to make individual selection for different IFs." 1077 1059 1078 1079 1080 1081 1082 1060 curedge = (0,0) 1061 if individualEdge: 1062 for edge_par in edge: 1063 if not _is_valid(edge,int): 1064 raise ValueError, "Each element of the 'edge' tuple has \ 1083 1065 to be a pair of integers or an integer." 1084 1066 else: 1085 1067 curedge = edge; 1086 1068 1087 1069 # setup fitter … … 1107 1089 asaplog.push(msg, False) 1108 1090 1109 1110 1111 1112 1113 1114 1115 1091 # figure out edge parameter 1092 if individualEdge: 1093 if len(edge)>=workscan.getif(r): 1094 raise RuntimeError, "Number of edge elements appear to be less than the number of IFs" 1095 curedge = edge[workscan.getif(r)] 1096 1097 # setup line finder 1116 1098 fl.find_lines(r,mask,curedge) 1117 1099 f.set_scan(workscan, fl.get_mask()) … … 1360 1342 if row > self.nrow(): 1361 1343 return 1362 from asap import asapfit1344 from asap.asapfit import asapfit 1363 1345 fit = asapfit(self._getfit(row)) 1364 1346 if rcParams['verbose']: … … 1435 1417 nchans = filter(lambda t: t > 0, nchans) 1436 1418 return (sum(nchans)/len(nchans) == nchans[0]) 1419 1420 def _fill(self, names, unit, average): 1421 import os 1422 varlist = vars() 1423 from asap._asap import stfiller 1424 first = True 1425 fullnames = [] 1426 for name in names: 1427 name = os.path.expandvars(name) 1428 name = os.path.expanduser(name) 1429 if not os.path.exists(name): 1430 msg = "File '%s' does not exists" % (name) 1431 if rcParams['verbose']: 1432 asaplog.push(msg) 1433 print asaplog.pop().strip() 1434 return 1435 raise IOError(msg) 1436 fullnames.append(name) 1437 if average: 1438 asaplog.push('Auto averaging integrations') 1439 for name in fullnames: 1440 r = stfiller() 1441 msg = "Importing %s..." % (name) 1442 asaplog.push(msg,False) 1443 print_log() 1444 r._open(name,-1,-1) 1445 r._read() 1446 tbl = r._getdata() 1447 if average: 1448 tbl = self._math._average((tbl,),(),'NONE','SCAN', False) 1449 #tbl = tbl2 1450 if not first: 1451 tbl = self._math._merge([self, tbl]) 1452 #tbl = tbl2 1453 Scantable.__init__(self, tbl) 1454 r._close() 1455 del r,tbl 1456 first = False 1457 if unit is not None: 1458 self.set_fluxunit(unit) 1459 self.set_freqframe(rcParams['scantable.freqframe']) 1460 #self._add_history("scantable", varlist) 1461
Note:
See TracChangeset
for help on using the changeset viewer.