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