| [100] | 1 | """ | 
|---|
|  | 2 | This is the ATNF Single Dish Analysis package. | 
|---|
|  | 3 |  | 
|---|
|  | 4 | """ | 
|---|
| [1080] | 5 | import os,sys,shutil, platform | 
|---|
| [1691] | 6 | try: | 
|---|
|  | 7 | from functools import wraps as wraps_dec | 
|---|
|  | 8 | except ImportError: | 
|---|
|  | 9 | from asap.compatibility import wraps as wraps_dec | 
|---|
| [226] | 10 |  | 
|---|
| [1080] | 11 | # Set up AIPSPATH and first time use of asap i.e. ~/.asap/* | 
|---|
|  | 12 | plf = None | 
|---|
|  | 13 | if sys.platform == "linux2": | 
|---|
|  | 14 | if platform.architecture()[0] == '64bit': | 
|---|
|  | 15 | plf = 'linux_64b' | 
|---|
|  | 16 | else: | 
|---|
|  | 17 | plf = 'linux_gnu' | 
|---|
|  | 18 | elif sys.platform == 'darwin': | 
|---|
|  | 19 | plf = 'darwin' | 
|---|
|  | 20 | else: | 
|---|
|  | 21 | # Shouldn't happen - default to linux | 
|---|
|  | 22 | plf = 'linux' | 
|---|
|  | 23 | asapdata = __path__[-1] | 
|---|
| [1171] | 24 | # Allow user defined data location | 
|---|
|  | 25 | if os.environ.has_key("ASAPDATA"): | 
|---|
|  | 26 | if os.path.exists(os.environ["ASAPDATA"]): | 
|---|
|  | 27 | asapdata = os.environ["ASAPDATA"] | 
|---|
| [1371] | 28 | # use AIPSPATH if defined and "data" dir present | 
|---|
|  | 29 | if not os.environ.has_key("AIPSPATH") or \ | 
|---|
|  | 30 | not os.path.exists(os.environ["AIPSPATH"].split()[0]+"/data"): | 
|---|
| [1316] | 31 | os.environ["AIPSPATH"] = "%s %s somwhere" % ( asapdata, plf) | 
|---|
| [1171] | 32 | # set up user space | 
|---|
| [1080] | 33 | userdir = os.environ["HOME"]+"/.asap" | 
|---|
|  | 34 | if not os.path.exists(userdir): | 
|---|
|  | 35 | print 'First time ASAP use. Setting up ~/.asap' | 
|---|
|  | 36 | os.mkdir(userdir) | 
|---|
|  | 37 | shutil.copyfile(asapdata+"/data/ipythonrc-asap", userdir+"/ipythonrc-asap") | 
|---|
| [1588] | 38 | shutil.copyfile(asapdata+"/data/ipy_user_conf.py", | 
|---|
| [1434] | 39 | userdir+"/ipy_user_conf.py") | 
|---|
| [1080] | 40 | f = file(userdir+"/asapuserfuncs.py", "w") | 
|---|
|  | 41 | f.close() | 
|---|
|  | 42 | f = file(userdir+"/ipythonrc", "w") | 
|---|
|  | 43 | f.close() | 
|---|
| [1472] | 44 | else: | 
|---|
|  | 45 | # upgrade to support later ipython versions | 
|---|
|  | 46 | if not os.path.exists(userdir+"/ipy_user_conf.py"): | 
|---|
| [1588] | 47 | shutil.copyfile(asapdata+"/data/ipy_user_conf.py", | 
|---|
| [1472] | 48 | userdir+"/ipy_user_conf.py") | 
|---|
|  | 49 |  | 
|---|
| [1171] | 50 | # remove from namespace | 
|---|
| [1080] | 51 | del asapdata, userdir, shutil, platform | 
|---|
|  | 52 |  | 
|---|
| [513] | 53 | def _validate_bool(b): | 
|---|
| [226] | 54 | 'Convert b to a boolean or raise' | 
|---|
|  | 55 | bl = b.lower() | 
|---|
|  | 56 | if bl in ('f', 'no', 'false', '0', 0): return False | 
|---|
|  | 57 | elif bl in ('t', 'yes', 'true', '1', 1): return True | 
|---|
|  | 58 | else: | 
|---|
|  | 59 | raise ValueError('Could not convert "%s" to boolean' % b) | 
|---|
|  | 60 |  | 
|---|
| [513] | 61 | def _validate_int(s): | 
|---|
| [226] | 62 | 'convert s to int or raise' | 
|---|
|  | 63 | try: return int(s) | 
|---|
|  | 64 | except ValueError: | 
|---|
|  | 65 | raise ValueError('Could not convert "%s" to int' % s) | 
|---|
|  | 66 |  | 
|---|
| [513] | 67 | def _asap_fname(): | 
|---|
| [226] | 68 | """ | 
|---|
|  | 69 | Return the path to the rc file | 
|---|
|  | 70 |  | 
|---|
|  | 71 | Search order: | 
|---|
|  | 72 |  | 
|---|
|  | 73 | * current working dir | 
|---|
|  | 74 | * environ var ASAPRC | 
|---|
| [274] | 75 | * HOME/.asaprc | 
|---|
| [706] | 76 |  | 
|---|
| [226] | 77 | """ | 
|---|
|  | 78 | fname = os.path.join( os.getcwd(), '.asaprc') | 
|---|
|  | 79 | if os.path.exists(fname): return fname | 
|---|
|  | 80 |  | 
|---|
|  | 81 | if os.environ.has_key('ASAPRC'): | 
|---|
|  | 82 | path =  os.environ['ASAPRC'] | 
|---|
|  | 83 | if os.path.exists(path): | 
|---|
|  | 84 | fname = os.path.join(path, '.asaprc') | 
|---|
|  | 85 | if os.path.exists(fname): | 
|---|
|  | 86 | return fname | 
|---|
|  | 87 |  | 
|---|
|  | 88 | if os.environ.has_key('HOME'): | 
|---|
|  | 89 | home =  os.environ['HOME'] | 
|---|
|  | 90 | fname = os.path.join(home, '.asaprc') | 
|---|
|  | 91 | if os.path.exists(fname): | 
|---|
|  | 92 | return fname | 
|---|
|  | 93 | return None | 
|---|
|  | 94 |  | 
|---|
| [706] | 95 |  | 
|---|
| [226] | 96 | defaultParams = { | 
|---|
|  | 97 | # general | 
|---|
| [513] | 98 | 'verbose'             : [True, _validate_bool], | 
|---|
|  | 99 | 'useplotter'          : [True, _validate_bool], | 
|---|
| [542] | 100 | 'insitu'              : [True, _validate_bool], | 
|---|
| [706] | 101 |  | 
|---|
| [226] | 102 | # plotting | 
|---|
| [706] | 103 | 'plotter.gui'         : [True, _validate_bool], | 
|---|
| [226] | 104 | 'plotter.stacking'    : ['p', str], | 
|---|
|  | 105 | 'plotter.panelling'   : ['s', str], | 
|---|
| [700] | 106 | 'plotter.colours'     : ['', str], | 
|---|
|  | 107 | 'plotter.linestyles'  : ['', str], | 
|---|
| [710] | 108 | 'plotter.decimate'    : [False, _validate_bool], | 
|---|
|  | 109 | 'plotter.ganged'      : [True, _validate_bool], | 
|---|
| [1022] | 110 | 'plotter.histogram'  : [False, _validate_bool], | 
|---|
| [1097] | 111 | 'plotter.papertype'  : ['A4', str], | 
|---|
| [1560] | 112 | 'plotter.axesformatting' : ['mpl', str], | 
|---|
| [710] | 113 |  | 
|---|
| [226] | 114 | # scantable | 
|---|
|  | 115 | 'scantable.save'      : ['ASAP', str], | 
|---|
| [513] | 116 | 'scantable.autoaverage'      : [True, _validate_bool], | 
|---|
| [226] | 117 | 'scantable.freqframe' : ['LSRK', str],  #default frequency frame | 
|---|
| [1076] | 118 | 'scantable.verbosesummary'   : [False, _validate_bool], | 
|---|
| [1422] | 119 | 'scantable.storage'   : ['memory', str], | 
|---|
| [1504] | 120 | 'scantable.history'   : [True, _validate_bool], | 
|---|
| [1586] | 121 | 'scantable.reference'      : ['.*(e|w|_R)$', str], | 
|---|
|  | 122 | 'scantable.parallactify'   : [False, _validate_bool] | 
|---|
| [226] | 123 | # fitter | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
| [255] | 126 | def list_rcparameters(): | 
|---|
| [706] | 127 |  | 
|---|
| [255] | 128 | print """ | 
|---|
| [737] | 129 | # general | 
|---|
|  | 130 | # print verbose output | 
|---|
|  | 131 | verbose                    : True | 
|---|
| [255] | 132 |  | 
|---|
| [737] | 133 | # preload a default plotter | 
|---|
|  | 134 | useplotter                 : True | 
|---|
| [255] | 135 |  | 
|---|
| [737] | 136 | # apply operations on the input scantable or return new one | 
|---|
|  | 137 | insitu                     : True | 
|---|
| [706] | 138 |  | 
|---|
| [737] | 139 | # plotting | 
|---|
| [710] | 140 |  | 
|---|
| [737] | 141 | # do we want a GUI or plot to a file | 
|---|
|  | 142 | plotter.gui                : True | 
|---|
| [710] | 143 |  | 
|---|
| [737] | 144 | # default mode for colour stacking | 
|---|
|  | 145 | plotter.stacking           : Pol | 
|---|
| [255] | 146 |  | 
|---|
| [737] | 147 | # default mode for panelling | 
|---|
|  | 148 | plotter.panelling          : scan | 
|---|
| [255] | 149 |  | 
|---|
| [1560] | 150 | # push panels together, to share axis labels | 
|---|
| [737] | 151 | plotter.ganged             : True | 
|---|
| [710] | 152 |  | 
|---|
| [1513] | 153 | # decimate the number of points plotted by a factor of | 
|---|
| [737] | 154 | # nchan/1024 | 
|---|
|  | 155 | plotter.decimate           : False | 
|---|
| [733] | 156 |  | 
|---|
| [737] | 157 | # default colours/linestyles | 
|---|
|  | 158 | plotter.colours            : | 
|---|
|  | 159 | plotter.linestyles         : | 
|---|
| [700] | 160 |  | 
|---|
| [1022] | 161 | # enable/disable histogram plotting | 
|---|
|  | 162 | plotter.histogram          : False | 
|---|
|  | 163 |  | 
|---|
| [1097] | 164 | # ps paper type | 
|---|
|  | 165 | plotter.papertype          : A4 | 
|---|
|  | 166 |  | 
|---|
| [1513] | 167 | # The formatting style of the xaxis | 
|---|
| [1560] | 168 | plotter.axesformatting    : 'mpl' (default) or 'asap' (for old versions of matplotlib) | 
|---|
| [1513] | 169 |  | 
|---|
| [737] | 170 | # scantable | 
|---|
| [1076] | 171 |  | 
|---|
| [1259] | 172 | # default storage of scantable ('memory'/'disk') | 
|---|
| [1076] | 173 | scantable.storage          : memory | 
|---|
| [1422] | 174 |  | 
|---|
|  | 175 | # write history of each call to scantable | 
|---|
|  | 176 | scantable.history          : True | 
|---|
|  | 177 |  | 
|---|
| [737] | 178 | # default ouput format when saving | 
|---|
|  | 179 | scantable.save             : ASAP | 
|---|
| [1422] | 180 |  | 
|---|
| [737] | 181 | # auto averaging on read | 
|---|
|  | 182 | scantable.autoaverage      : True | 
|---|
| [255] | 183 |  | 
|---|
| [737] | 184 | # default frequency frame to set when function | 
|---|
| [1097] | 185 | # scantable.set_freqframe is called | 
|---|
| [737] | 186 | scantable.freqframe        : LSRK | 
|---|
| [255] | 187 |  | 
|---|
| [737] | 188 | # Control the level of information printed by summary | 
|---|
|  | 189 | scantable.verbosesummary   : False | 
|---|
| [706] | 190 |  | 
|---|
| [1504] | 191 | # Control the identification of reference (off) scans | 
|---|
|  | 192 | # This is has to be a regular expression | 
|---|
| [1595] | 193 | scantable.reference        : .*(e|w|_R)$ | 
|---|
| [1560] | 194 |  | 
|---|
| [1595] | 195 | # Indicate whether the data was parallactified (total phase offest == 0.0) | 
|---|
|  | 196 | scantable.parallactify     : False | 
|---|
|  | 197 |  | 
|---|
| [737] | 198 | # Fitter | 
|---|
|  | 199 | """ | 
|---|
| [706] | 200 |  | 
|---|
| [226] | 201 | def rc_params(): | 
|---|
|  | 202 | 'Return the default params updated from the values in the rc file' | 
|---|
| [706] | 203 |  | 
|---|
| [513] | 204 | fname = _asap_fname() | 
|---|
| [706] | 205 |  | 
|---|
| [226] | 206 | if fname is None or not os.path.exists(fname): | 
|---|
|  | 207 | message = 'could not find rc file; returning defaults' | 
|---|
|  | 208 | ret =  dict([ (key, tup[0]) for key, tup in defaultParams.items()]) | 
|---|
|  | 209 | #print message | 
|---|
|  | 210 | return ret | 
|---|
| [706] | 211 |  | 
|---|
| [226] | 212 | cnt = 0 | 
|---|
|  | 213 | for line in file(fname): | 
|---|
|  | 214 | cnt +=1 | 
|---|
|  | 215 | line = line.strip() | 
|---|
|  | 216 | if not len(line): continue | 
|---|
|  | 217 | if line.startswith('#'): continue | 
|---|
|  | 218 | tup = line.split(':',1) | 
|---|
|  | 219 | if len(tup) !=2: | 
|---|
|  | 220 | print ('Illegal line #%d\n\t%s\n\tin file "%s"' % (cnt, line, fname)) | 
|---|
|  | 221 | continue | 
|---|
| [706] | 222 |  | 
|---|
| [226] | 223 | key, val = tup | 
|---|
|  | 224 | key = key.strip() | 
|---|
|  | 225 | if not defaultParams.has_key(key): | 
|---|
|  | 226 | print ('Bad key "%s" on line %d in %s' % (key, cnt, fname)) | 
|---|
|  | 227 | continue | 
|---|
| [706] | 228 |  | 
|---|
| [226] | 229 | default, converter =  defaultParams[key] | 
|---|
|  | 230 |  | 
|---|
|  | 231 | ind = val.find('#') | 
|---|
|  | 232 | if ind>=0: val = val[:ind]   # ignore trailing comments | 
|---|
|  | 233 | val = val.strip() | 
|---|
|  | 234 | try: cval = converter(val)   # try to convert to proper type or raise | 
|---|
| [1080] | 235 | except ValueError, msg: | 
|---|
| [226] | 236 | print ('Bad val "%s" on line #%d\n\t"%s"\n\tin file "%s"\n\t%s' % (val, cnt, line, fname, msg)) | 
|---|
|  | 237 | continue | 
|---|
|  | 238 | else: | 
|---|
|  | 239 | # Alles Klar, update dict | 
|---|
|  | 240 | defaultParams[key][0] = cval | 
|---|
|  | 241 |  | 
|---|
|  | 242 | # strip the conveter funcs and return | 
|---|
|  | 243 | ret =  dict([ (key, tup[0]) for key, tup in defaultParams.items()]) | 
|---|
| [466] | 244 | print ('loaded rc file %s'%fname) | 
|---|
| [226] | 245 |  | 
|---|
|  | 246 | return ret | 
|---|
|  | 247 |  | 
|---|
|  | 248 |  | 
|---|
|  | 249 | # this is the instance used by the asap classes | 
|---|
| [706] | 250 | rcParams = rc_params() | 
|---|
| [226] | 251 |  | 
|---|
|  | 252 | rcParamsDefault = dict(rcParams.items()) # a copy | 
|---|
|  | 253 |  | 
|---|
|  | 254 | def rc(group, **kwargs): | 
|---|
|  | 255 | """ | 
|---|
|  | 256 | Set the current rc params.  Group is the grouping for the rc, eg | 
|---|
| [379] | 257 | for scantable.save the group is 'scantable', for plotter.stacking, the | 
|---|
|  | 258 | group is 'plotter', and so on.  kwargs is a list of attribute | 
|---|
| [226] | 259 | name/value pairs, eg | 
|---|
|  | 260 |  | 
|---|
| [379] | 261 | rc('scantable', save='SDFITS') | 
|---|
| [226] | 262 |  | 
|---|
|  | 263 | sets the current rc params and is equivalent to | 
|---|
| [706] | 264 |  | 
|---|
| [379] | 265 | rcParams['scantable.save'] = 'SDFITS' | 
|---|
| [226] | 266 |  | 
|---|
|  | 267 | Use rcdefaults to restore the default rc params after changes. | 
|---|
|  | 268 | """ | 
|---|
|  | 269 |  | 
|---|
| [379] | 270 | aliases = {} | 
|---|
| [706] | 271 |  | 
|---|
| [226] | 272 | for k,v in kwargs.items(): | 
|---|
|  | 273 | name = aliases.get(k) or k | 
|---|
| [1422] | 274 | if len(group): | 
|---|
|  | 275 | key = '%s.%s' % (group, name) | 
|---|
|  | 276 | else: | 
|---|
|  | 277 | key = name | 
|---|
| [226] | 278 | if not rcParams.has_key(key): | 
|---|
|  | 279 | raise KeyError('Unrecognized key "%s" for group "%s" and name "%s"' % (key, group, name)) | 
|---|
| [706] | 280 |  | 
|---|
| [226] | 281 | rcParams[key] = v | 
|---|
|  | 282 |  | 
|---|
|  | 283 |  | 
|---|
|  | 284 | def rcdefaults(): | 
|---|
|  | 285 | """ | 
|---|
|  | 286 | Restore the default rc params - the ones that were created at | 
|---|
|  | 287 | asap load time | 
|---|
|  | 288 | """ | 
|---|
|  | 289 | rcParams.update(rcParamsDefault) | 
|---|
|  | 290 |  | 
|---|
| [1295] | 291 | def _n_bools(n, val): | 
|---|
| [1588] | 292 | return [ val for i in xrange(n) ] | 
|---|
| [513] | 293 |  | 
|---|
|  | 294 | def _is_sequence_or_number(param, ptype=int): | 
|---|
|  | 295 | if isinstance(param,tuple) or isinstance(param,list): | 
|---|
| [928] | 296 | if len(param) == 0: return True # empty list | 
|---|
| [513] | 297 | out = True | 
|---|
|  | 298 | for p in param: | 
|---|
|  | 299 | out &= isinstance(p,ptype) | 
|---|
|  | 300 | return out | 
|---|
|  | 301 | elif isinstance(param, ptype): | 
|---|
|  | 302 | return True | 
|---|
|  | 303 | return False | 
|---|
|  | 304 |  | 
|---|
| [928] | 305 | def _to_list(param, ptype=int): | 
|---|
|  | 306 | if isinstance(param, ptype): | 
|---|
|  | 307 | if ptype is str: return param.split() | 
|---|
|  | 308 | else: return [param] | 
|---|
|  | 309 | if _is_sequence_or_number(param, ptype): | 
|---|
|  | 310 | return param | 
|---|
|  | 311 | return None | 
|---|
| [715] | 312 |  | 
|---|
| [944] | 313 | def unique(x): | 
|---|
| [992] | 314 | """ | 
|---|
|  | 315 | Return the unique values in a list | 
|---|
|  | 316 | Parameters: | 
|---|
|  | 317 | x:      the list to reduce | 
|---|
|  | 318 | Examples: | 
|---|
|  | 319 | x = [1,2,3,3,4] | 
|---|
|  | 320 | print unique(x) | 
|---|
|  | 321 | [1,2,3,4] | 
|---|
|  | 322 | """ | 
|---|
| [944] | 323 | return dict([ (val, 1) for val in x]).keys() | 
|---|
|  | 324 |  | 
|---|
| [992] | 325 | def list_files(path=".",suffix="rpf"): | 
|---|
|  | 326 | """ | 
|---|
|  | 327 | Return a list files readable by asap, such as rpf, sdfits, mbf, asap | 
|---|
|  | 328 | Parameters: | 
|---|
|  | 329 | path:     The directory to list (default '.') | 
|---|
|  | 330 | suffix:   The file extension (default rpf) | 
|---|
|  | 331 | Example: | 
|---|
|  | 332 | files = list_files("data/","sdfits") | 
|---|
|  | 333 | print files | 
|---|
|  | 334 | ['data/2001-09-01_0332_P363.sdfits', | 
|---|
|  | 335 | 'data/2003-04-04_131152_t0002.sdfits', | 
|---|
|  | 336 | 'data/Sgr_86p262_best_SPC.sdfits'] | 
|---|
|  | 337 | """ | 
|---|
|  | 338 | if not os.path.isdir(path): | 
|---|
|  | 339 | return None | 
|---|
| [1295] | 340 | valid = "rpf rpf.1 rpf.2 sdf sdfits mbf asap".split() | 
|---|
| [992] | 341 | if not suffix in valid: | 
|---|
|  | 342 | return None | 
|---|
|  | 343 | files = [os.path.expanduser(os.path.expandvars(path+"/"+f)) for f in os.listdir(path)] | 
|---|
|  | 344 | return filter(lambda x: x.endswith(suffix),files) | 
|---|
|  | 345 |  | 
|---|
| [715] | 346 | # workaround for ipython, which redirects this if banner=0 in ipythonrc | 
|---|
|  | 347 | sys.stdout = sys.__stdout__ | 
|---|
|  | 348 | sys.stderr = sys.__stderr__ | 
|---|
|  | 349 |  | 
|---|
|  | 350 | # Logging | 
|---|
|  | 351 | from asap._asap import Log as _asaplog | 
|---|
|  | 352 | global asaplog | 
|---|
| [710] | 353 | asaplog=_asaplog() | 
|---|
| [715] | 354 | if rcParams['verbose']: | 
|---|
|  | 355 | asaplog.enable() | 
|---|
|  | 356 | else: | 
|---|
|  | 357 | asaplog.disable() | 
|---|
|  | 358 |  | 
|---|
| [1589] | 359 |  | 
|---|
|  | 360 | def print_log_dec(f): | 
|---|
| [1691] | 361 | @wraps_dec(f) | 
|---|
| [1589] | 362 | def wrap_it(*args, **kw): | 
|---|
|  | 363 | val = f(*args, **kw) | 
|---|
|  | 364 | print_log() | 
|---|
|  | 365 | return val | 
|---|
|  | 366 | return wrap_it | 
|---|
|  | 367 |  | 
|---|
| [715] | 368 | def print_log(): | 
|---|
| [1589] | 369 | log = asaplog.pop().strip() | 
|---|
| [715] | 370 | if len(log) and rcParams['verbose']: print log | 
|---|
|  | 371 | return | 
|---|
|  | 372 |  | 
|---|
| [1295] | 373 | def mask_and(a, b): | 
|---|
|  | 374 | assert(len(a)==len(b)) | 
|---|
|  | 375 | return [ a[i] & b[i] for i in xrange(len(a)) ] | 
|---|
| [1134] | 376 |  | 
|---|
| [1295] | 377 | def mask_or(a, b): | 
|---|
|  | 378 | assert(len(a)==len(b)) | 
|---|
|  | 379 | return [ a[i] | b[i] for i in xrange(len(a)) ] | 
|---|
|  | 380 |  | 
|---|
|  | 381 | def mask_not(a): | 
|---|
|  | 382 | return [ not i for i in a ] | 
|---|
|  | 383 |  | 
|---|
| [1117] | 384 | from asapfitter import fitter | 
|---|
| [895] | 385 | from asapreader import reader | 
|---|
| [944] | 386 | from selector import selector | 
|---|
| [710] | 387 |  | 
|---|
| [100] | 388 | from asapmath import * | 
|---|
| [1080] | 389 | from scantable import scantable | 
|---|
| [1097] | 390 | from asaplinefind import linefinder | 
|---|
| [1645] | 391 | from simplelinefinder import simplelinefinder | 
|---|
| [1134] | 392 | from linecatalog import linecatalog | 
|---|
| [1689] | 393 | from opacity import skydip | 
|---|
| [1725] | 394 | from opacity import model as opacity_model | 
|---|
| [285] | 395 |  | 
|---|
| [928] | 396 | if rcParams['useplotter']: | 
|---|
| [1295] | 397 | try: | 
|---|
| [1423] | 398 | from asapplotter import asapplotter | 
|---|
|  | 399 | gui = os.environ.has_key('DISPLAY') and rcParams['plotter.gui'] | 
|---|
|  | 400 | if gui: | 
|---|
| [1422] | 401 | import matplotlib | 
|---|
|  | 402 | matplotlib.use("TkAgg") | 
|---|
| [1691] | 403 | from matplotlib import pylab | 
|---|
| [1422] | 404 | xyplotter = pylab | 
|---|
| [1423] | 405 | plotter = asapplotter(gui) | 
|---|
|  | 406 | del gui | 
|---|
| [1295] | 407 | except ImportError: | 
|---|
| [1423] | 408 | print "Matplotlib not installed. No plotting available" | 
|---|
| [285] | 409 |  | 
|---|
| [574] | 410 | __date__ = '$Date: 2010-05-06 00:50:51 +0000 (Thu, 06 May 2010) $'.split()[1] | 
|---|
| [1745] | 411 | __version__  = '3.0.0' | 
|---|
| [100] | 412 |  | 
|---|
| [1193] | 413 | def is_ipython(): | 
|---|
| [1725] | 414 | return 'IPython' in sys.modules.keys() | 
|---|
| [1589] | 415 |  | 
|---|
| [1193] | 416 | if is_ipython(): | 
|---|
| [1014] | 417 | def version(): print  "ASAP %s(%s)"% (__version__, __date__) | 
|---|
| [1588] | 418 |  | 
|---|
|  | 419 | def list_scans(t = scantable): | 
|---|
| [1560] | 420 | import inspect | 
|---|
|  | 421 | print "The user created scantables are: ", | 
|---|
|  | 422 | globs=inspect.currentframe().f_back.f_locals.copy() | 
|---|
|  | 423 | out = [ k for k,v in globs.iteritems() \ | 
|---|
|  | 424 | if isinstance(v, scantable) and not k.startswith("_") ] | 
|---|
|  | 425 | print out | 
|---|
|  | 426 | return out | 
|---|
| [100] | 427 |  | 
|---|
| [715] | 428 | def commands(): | 
|---|
|  | 429 | x = """ | 
|---|
| [113] | 430 | [The scan container] | 
|---|
|  | 431 | scantable           - a container for integrations/scans | 
|---|
| [182] | 432 | (can open asap/rpfits/sdfits and ms files) | 
|---|
| [113] | 433 | copy            - returns a copy of a scan | 
|---|
|  | 434 | get_scan        - gets a specific scan out of a scantable | 
|---|
| [984] | 435 | (by name or number) | 
|---|
| [1093] | 436 | drop_scan       - drops a specific scan out of a scantable | 
|---|
|  | 437 | (by number) | 
|---|
| [984] | 438 | set_selection   - set a new subselection of the data | 
|---|
|  | 439 | get_selection   - get the current selection object | 
|---|
| [113] | 440 | summary         - print info about the scantable contents | 
|---|
| [182] | 441 | stats           - get specified statistic of the spectra in | 
|---|
|  | 442 | the scantable | 
|---|
|  | 443 | stddev          - get the standard deviation of the spectra | 
|---|
|  | 444 | in the scantable | 
|---|
| [113] | 445 | get_tsys        - get the TSys | 
|---|
|  | 446 | get_time        - get the timestamps of the integrations | 
|---|
| [1351] | 447 | get_inttime     - get the integration time | 
|---|
| [733] | 448 | get_sourcename  - get the source names of the scans | 
|---|
| [794] | 449 | get_azimuth     - get the azimuth of the scans | 
|---|
|  | 450 | get_elevation   - get the elevation of the scans | 
|---|
|  | 451 | get_parangle    - get the parallactic angle of the scans | 
|---|
| [1697] | 452 | get_coordinate  - get the spectral coordinate for the given row, | 
|---|
|  | 453 | which can be used for coordinate conversions | 
|---|
| [1739] | 454 | get_weather     - get the weather condition parameters | 
|---|
| [876] | 455 | get_unit        - get the current unit | 
|---|
| [513] | 456 | set_unit        - set the abcissa unit to be used from this | 
|---|
|  | 457 | point on | 
|---|
| [255] | 458 | get_abcissa     - get the abcissa values and name for a given | 
|---|
|  | 459 | row (time) | 
|---|
| [1259] | 460 | get_column_names - get the names of the columns in the scantable | 
|---|
|  | 461 | for use with selector.set_query | 
|---|
| [113] | 462 | set_freqframe   - set the frame info for the Spectral Axis | 
|---|
|  | 463 | (e.g. 'LSRK') | 
|---|
| [276] | 464 | set_doppler     - set the doppler to be used from this point on | 
|---|
| [984] | 465 | set_dirframe    - set the frame for the direction on the sky | 
|---|
| [240] | 466 | set_instrument  - set the instrument name | 
|---|
| [1190] | 467 | set_feedtype    - set the feed type | 
|---|
| [255] | 468 | get_fluxunit    - get the brightness flux unit | 
|---|
| [240] | 469 | set_fluxunit    - set the brightness flux unit | 
|---|
| [1508] | 470 | set_sourcetype  - set the type of the source - source or reference | 
|---|
| [188] | 471 | create_mask     - return an mask in the current unit | 
|---|
|  | 472 | for the given region. The specified regions | 
|---|
|  | 473 | are NOT masked | 
|---|
| [255] | 474 | get_restfreqs   - get the current list of rest frequencies | 
|---|
|  | 475 | set_restfreqs   - set a list of rest frequencies | 
|---|
| [1471] | 476 | shift_refpix    - shift the reference pixel of the IFs | 
|---|
|  | 477 | set_spectrum    - overwrite the spectrum for a given row | 
|---|
|  | 478 | get_spectrum    - retrieve the spectrum for a given | 
|---|
|  | 479 | get_mask        - retrieve the mask for a given | 
|---|
| [1012] | 480 | flag            - flag selected channels in the data | 
|---|
| [1192] | 481 | lag_flag        - flag specified frequency in the data | 
|---|
| [1151] | 482 | save            - save the scantable to disk as either 'ASAP', | 
|---|
|  | 483 | 'SDFITS' or 'ASCII' | 
|---|
| [486] | 484 | nbeam,nif,nchan,npol - the number of beams/IFs/Pols/Chans | 
|---|
| [733] | 485 | nscan           - the number of scans in the scantable | 
|---|
| [1422] | 486 | nrow            - the number of spectra in the scantable | 
|---|
| [486] | 487 | history         - print the history of the scantable | 
|---|
| [530] | 488 | get_fit         - get a fit which has been stored witnh the data | 
|---|
| [706] | 489 | average_time    - return the (weighted) time average of a scan | 
|---|
| [513] | 490 | or a list of scans | 
|---|
|  | 491 | average_pol     - average the polarisations together. | 
|---|
| [1144] | 492 | average_beam    - average the beams together. | 
|---|
| [992] | 493 | convert_pol     - convert to a different polarisation type | 
|---|
| [690] | 494 | auto_quotient   - return the on/off quotient with | 
|---|
| [1069] | 495 | automatic detection of the on/off scans (closest | 
|---|
|  | 496 | in time off is selected) | 
|---|
| [1144] | 497 | mx_quotient     - Form a quotient using MX data (off beams) | 
|---|
| [1014] | 498 | scale, *, /     - return a scan scaled by a given factor | 
|---|
| [1560] | 499 | add, +          - return a scan with given value added | 
|---|
|  | 500 | sub, -          - return a scan with given value subtracted | 
|---|
| [513] | 501 | bin             - return a scan with binned channels | 
|---|
|  | 502 | resample        - return a scan with resampled channels | 
|---|
|  | 503 | smooth          - return the spectrally smoothed scan | 
|---|
|  | 504 | poly_baseline   - fit a polynomial baseline to all Beams/IFs/Pols | 
|---|
| [706] | 505 | auto_poly_baseline - automatically fit a polynomial baseline | 
|---|
| [780] | 506 | recalc_azel     - recalculate azimuth and elevation based on | 
|---|
|  | 507 | the pointing | 
|---|
| [513] | 508 | gain_el         - apply gain-elevation correction | 
|---|
|  | 509 | opacity         - apply opacity correction | 
|---|
|  | 510 | convert_flux    - convert to and from Jy and Kelvin brightness | 
|---|
| [255] | 511 | units | 
|---|
| [513] | 512 | freq_align      - align spectra in frequency frame | 
|---|
| [1014] | 513 | invert_phase    - Invert the phase of the cross-correlation | 
|---|
| [1351] | 514 | swap_linears    - Swap XX and YY (or RR LL) | 
|---|
| [513] | 515 | rotate_xyphase  - rotate XY phase of cross correlation | 
|---|
|  | 516 | rotate_linpolphase - rotate the phase of the complex | 
|---|
|  | 517 | polarization O=Q+iU correlation | 
|---|
| [733] | 518 | freq_switch     - perform frequency switching on the data | 
|---|
|  | 519 | stats           - Determine the specified statistic, e.g. 'min' | 
|---|
|  | 520 | 'max', 'rms' etc. | 
|---|
|  | 521 | stddev          - Determine the standard deviation of the current | 
|---|
|  | 522 | beam/if/pol | 
|---|
| [1588] | 523 | get_row_selector - get the selection object for a specified row | 
|---|
|  | 524 | number | 
|---|
| [1014] | 525 | [Selection] | 
|---|
|  | 526 | selector              - a selection object to set a subset of a scantable | 
|---|
|  | 527 | set_scans          - set (a list of) scans by index | 
|---|
|  | 528 | set_cycles         - set (a list of) cycles by index | 
|---|
|  | 529 | set_beams          - set (a list of) beamss by index | 
|---|
|  | 530 | set_ifs            - set (a list of) ifs by index | 
|---|
|  | 531 | set_polarisations  - set (a list of) polarisations by name | 
|---|
|  | 532 | or by index | 
|---|
|  | 533 | set_names          - set a selection by name (wildcards allowed) | 
|---|
|  | 534 | set_tsys           - set a selection by tsys thresholds | 
|---|
| [1259] | 535 | set_query          - set a selection by SQL-like query, e.g. BEAMNO==1 | 
|---|
| [1351] | 536 | ( also  get_ functions for all these ) | 
|---|
| [1014] | 537 | reset              - unset all selections | 
|---|
| [1351] | 538 | +                  - merge two selections | 
|---|
| [733] | 539 |  | 
|---|
| [513] | 540 | [Math] Mainly functions which operate on more than one scantable | 
|---|
| [100] | 541 |  | 
|---|
| [706] | 542 | average_time    - return the (weighted) time average | 
|---|
| [513] | 543 | of a list of scans | 
|---|
|  | 544 | quotient        - return the on/off quotient | 
|---|
|  | 545 | simple_math     - simple mathematical operations on two scantables, | 
|---|
|  | 546 | 'add', 'sub', 'mul', 'div' | 
|---|
| [1069] | 547 | quotient        - build quotient of the given on and off scans | 
|---|
| [1351] | 548 | (matched pairs and 1 off - n on are valid) | 
|---|
| [1117] | 549 | merge           - merge a list of scantables | 
|---|
| [1069] | 550 |  | 
|---|
| [1151] | 551 | [Line Catalog] | 
|---|
|  | 552 | linecatalog              - a linecatalog wrapper, taking an ASCII or | 
|---|
|  | 553 | internal format table | 
|---|
|  | 554 | summary              - print a summary of the current selection | 
|---|
|  | 555 | set_name             - select a subset by name pattern, e.g. '*OH*' | 
|---|
|  | 556 | set_strength_limits  - select a subset by line strength limits | 
|---|
|  | 557 | set_frequency_limits - select a subset by frequency limits | 
|---|
|  | 558 | reset                - unset all selections | 
|---|
|  | 559 | save                 - save the current subset to a table (internal | 
|---|
|  | 560 | format) | 
|---|
|  | 561 | get_row              - get the name and frequency from a specific | 
|---|
|  | 562 | row in the table | 
|---|
| [513] | 563 | [Fitting] | 
|---|
| [113] | 564 | fitter | 
|---|
|  | 565 | auto_fit        - return a scan where the function is | 
|---|
|  | 566 | applied to all Beams/IFs/Pols. | 
|---|
|  | 567 | commit          - return a new scan where the fits have been | 
|---|
|  | 568 | commited. | 
|---|
|  | 569 | fit             - execute the actual fitting process | 
|---|
| [984] | 570 | store_fit       - store the fit parameters in the data (scantable) | 
|---|
| [113] | 571 | get_chi2        - get the Chi^2 | 
|---|
|  | 572 | set_scan        - set the scantable to be fit | 
|---|
|  | 573 | set_function    - set the fitting function | 
|---|
|  | 574 | set_parameters  - set the parameters for the function(s), and | 
|---|
|  | 575 | set if they should be held fixed during fitting | 
|---|
| [513] | 576 | set_gauss_parameters - same as above but specialised for individual | 
|---|
|  | 577 | gaussian components | 
|---|
| [113] | 578 | get_parameters  - get the fitted parameters | 
|---|
| [513] | 579 | plot            - plot the resulting fit and/or components and | 
|---|
|  | 580 | residual | 
|---|
| [210] | 581 | [Plotter] | 
|---|
|  | 582 | asapplotter         - a plotter for asap, default plotter is | 
|---|
|  | 583 | called 'plotter' | 
|---|
| [984] | 584 | plot            - plot a scantable | 
|---|
| [1151] | 585 | plot_lines      - plot a linecatalog overlay | 
|---|
| [1697] | 586 | plotazel        - plot azimuth and elevation versus time | 
|---|
|  | 587 | plotpointing    - plot telescope pointings | 
|---|
| [378] | 588 | save            - save the plot to a file ('png' ,'ps' or 'eps') | 
|---|
| [210] | 589 | set_mode        - set the state of the plotter, i.e. | 
|---|
|  | 590 | what is to be plotted 'colour stacked' | 
|---|
|  | 591 | and what 'panelled' | 
|---|
| [984] | 592 | set_selection   - only plot a selected part of the data | 
|---|
| [733] | 593 | set_range       - set a 'zoom' window [xmin,xmax,ymin,ymax] | 
|---|
| [255] | 594 | set_legend      - specify user labels for the legend indeces | 
|---|
|  | 595 | set_title       - specify user labels for the panel indeces | 
|---|
| [733] | 596 | set_abcissa     - specify a user label for the abcissa | 
|---|
| [255] | 597 | set_ordinate    - specify a user label for the ordinate | 
|---|
| [378] | 598 | set_layout      - specify the multi-panel layout (rows,cols) | 
|---|
| [733] | 599 | set_colors      - specify a set of colours to use | 
|---|
|  | 600 | set_linestyles  - specify a set of linestyles to use if only | 
|---|
|  | 601 | using one color | 
|---|
| [1151] | 602 | set_font        - set general font properties, e.g. 'family' | 
|---|
| [1054] | 603 | set_histogram   - plot in historam style | 
|---|
| [733] | 604 | set_mask        - set a plotting mask for a specific polarization | 
|---|
| [1171] | 605 | text            - draw text annotations either in data or relative | 
|---|
|  | 606 | coordinates | 
|---|
|  | 607 | arrow           - draw arrow annotations either in data or relative | 
|---|
|  | 608 | coordinates | 
|---|
|  | 609 | axhline,axvline - draw horizontal/vertical lines | 
|---|
|  | 610 | axhspan,axvspan - draw horizontal/vertical regions | 
|---|
| [1560] | 611 | annotate        - draw an arrow with label | 
|---|
|  | 612 | create_mask     - create a scnatble mask interactively | 
|---|
| [1175] | 613 |  | 
|---|
|  | 614 | xyplotter           - matplotlib/pylab plotting functions | 
|---|
|  | 615 |  | 
|---|
| [113] | 616 | [General] | 
|---|
|  | 617 | commands            - this command | 
|---|
|  | 618 | print               - print details about a variable | 
|---|
| [1560] | 619 | list_scans          - list all scantables created by the user | 
|---|
| [992] | 620 | list_files          - list all files readable by asap (default rpf) | 
|---|
| [113] | 621 | del                 - delete the given variable from memory | 
|---|
|  | 622 | range               - create a list of values, e.g. | 
|---|
|  | 623 | range(3) = [0,1,2], range(2,5) = [2,3,4] | 
|---|
|  | 624 | help                - print help for one of the listed functions | 
|---|
|  | 625 | execfile            - execute an asap script, e.g. execfile('myscript') | 
|---|
| [255] | 626 | list_rcparameters   - print out a list of possible values to be | 
|---|
| [274] | 627 | put into $HOME/.asaprc | 
|---|
| [1171] | 628 | rc                  - set rc parameters from within asap | 
|---|
| [466] | 629 | mask_and,mask_or, | 
|---|
|  | 630 | mask_not            - boolean operations on masks created with | 
|---|
|  | 631 | scantable.create_mask | 
|---|
| [1697] | 632 | skydip              - gain opacity values from a sky dip observation | 
|---|
| [1725] | 633 | opacity_model       - compute opacities fro given frequencies based on | 
|---|
|  | 634 | atmospheric model | 
|---|
| [706] | 635 |  | 
|---|
| [210] | 636 | Note: | 
|---|
|  | 637 | How to use this with help: | 
|---|
|  | 638 | # function 'summary' | 
|---|
|  | 639 | [xxx] is just a category | 
|---|
|  | 640 | Every 'sub-level' in this list should be replaces by a '.' Period when | 
|---|
| [706] | 641 | using help | 
|---|
| [210] | 642 | Example: | 
|---|
|  | 643 | ASAP> help scantable # to get info on ths scantable | 
|---|
|  | 644 | ASAP> help scantable.summary # to get help on the scantable's | 
|---|
|  | 645 | ASAP> help average_time | 
|---|
|  | 646 |  | 
|---|
| [715] | 647 | """ | 
|---|
| [1151] | 648 | if rcParams['verbose']: | 
|---|
|  | 649 | try: | 
|---|
|  | 650 | from IPython.genutils import page as pager | 
|---|
|  | 651 | except ImportError: | 
|---|
|  | 652 | from pydoc import pager | 
|---|
|  | 653 | pager(x) | 
|---|
|  | 654 | else: | 
|---|
|  | 655 | print x | 
|---|
| [715] | 656 | return | 
|---|
| [113] | 657 |  | 
|---|
| [706] | 658 | def welcome(): | 
|---|
|  | 659 | return """Welcome to ASAP v%s (%s) - the ATNF Spectral Analysis Package | 
|---|
| [100] | 660 |  | 
|---|
| [1035] | 661 | Please report any bugs via: | 
|---|
| [1378] | 662 | http://svn.atnf.csiro.au/trac/asap/simpleticket | 
|---|
| [100] | 663 |  | 
|---|
| [378] | 664 | [IMPORTANT: ASAP is 0-based] | 
|---|
| [706] | 665 | Type commands() to get a list of all available ASAP commands.""" % (__version__, __date__) | 
|---|