casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2008, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 #from casac import * 00009 import casac 00010 import string 00011 import time 00012 import inspect 00013 import gc 00014 import numpy 00015 from odict import odict 00016 from taskmanager import tm 00017 from task_sdplot import sdplot 00018 class sdplot_cli_: 00019 __name__ = "sdplot" 00020 __async__ = {} 00021 rkey = None 00022 i_am_a_casapy_task = None 00023 # The existence of the i_am_a_casapy_task attribute allows help() 00024 # (and other) to treat casapy tasks as a special case. 00025 00026 def __init__(self) : 00027 self.__bases__ = (sdplot_cli_,) 00028 self.__doc__ = self.__call__.__doc__ 00029 00030 self.parameters={'infile':None, 'antenna':None, 'fluxunit':None, 'telescopeparm':None, 'specunit':None, 'restfreq':None, 'frame':None, 'doppler':None, 'scanlist':None, 'field':None, 'iflist':None, 'pollist':None, 'beamlist':None, 'scanaverage':None, 'timeaverage':None, 'tweight':None, 'polaverage':None, 'pweight':None, 'kernel':None, 'kwidth':None, 'plottype':None, 'stack':None, 'panel':None, 'flrange':None, 'sprange':None, 'linecat':None, 'linedop':None, 'subplot':None, 'colormap':None, 'linestyles':None, 'linewidth':None, 'histogram':None, 'center':None, 'cell':None, 'header':None, 'headsize':None, 'plotstyle':None, 'margin':None, 'legendloc':None, 'outfile':None, 'overwrite':None, 'async':None} 00031 00032 00033 def result(self, key=None): 00034 #### here we will scan the task-ids in __async__ 00035 #### and add any that have completed... 00036 if key is not None and self.__async__.has_key(key) and self.__async__[key] is not None: 00037 ret = tm.retrieve(self.__async__[key]) 00038 if ret['state'] == "done" : 00039 self.__async__[key] = None 00040 elif ret['state'] == 'crashed' : 00041 self.__async__[key] = None 00042 return ret 00043 return None 00044 00045 00046 def __call__(self, infile=None, antenna=None, fluxunit=None, telescopeparm=None, specunit=None, restfreq=None, frame=None, doppler=None, scanlist=None, field=None, iflist=None, pollist=None, beamlist=None, scanaverage=None, timeaverage=None, tweight=None, polaverage=None, pweight=None, kernel=None, kwidth=None, plottype=None, stack=None, panel=None, flrange=None, sprange=None, linecat=None, linedop=None, subplot=None, colormap=None, linestyles=None, linewidth=None, histogram=None, center=None, cell=None, header=None, headsize=None, plotstyle=None, margin=None, legendloc=None, outfile=None, overwrite=None, async=None): 00047 00048 """ASAP SD plotting task 00049 Keyword arguments: 00050 infile -- name of input SD dataset 00051 antenna -- antenna name or id (only effective for MS input). 00052 fluxunit -- units for line flux 00053 options: 'K','Jy','' 00054 default: '' (keep current fluxunit) 00055 WARNING: For GBT data, see description below. 00056 >>> fluxunit expandable parameter 00057 telescopeparm -- the telescope characteristics 00058 options: (str) name or (list) list of gain info 00059 default: '' (none set) 00060 example: if telescopeparm='', it tries to get the telescope 00061 name from the data. 00062 Full antenna parameters (diameter,ap.eff.) known 00063 to ASAP are 00064 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 'DSS-43', 00065 'CEDUNA','HOBART'. For GBT, it fixes default fluxunit 00066 to 'K' first then convert to a new fluxunit. 00067 telescopeparm=[104.9,0.43] diameter(m), ap.eff. 00068 telescopeparm=[0.743] gain in Jy/K 00069 telescopeparm='FIX' to change default fluxunit 00070 see description below 00071 00072 specunit -- units for spectral axis 00073 options: (str) 'channel','km/s','GHz','MHz','kHz','Hz' 00074 default: '' (=current) 00075 example: this will be the units for masklist 00076 >>> specunit expandable parameter 00077 restfreq -- rest frequency 00078 default: '' (use current setting) 00079 example: 4.6e10 (float value in Hz), 00080 '46GHz' (string with unit), 00081 ['345.8GHz', 347.0e9, 356.7e9] (for each IF) 00082 [{'name':'CO','value':345e9}] (a value with name) 00083 frame -- frequency frame for spectral axis 00084 options: (str) 'LSRK','REST','TOPO','LSRD','BARY', 00085 'GEO','GALACTO','LGROUP','CMB' 00086 default: currently set frame in scantable 00087 WARNING: frame='REST' not yet implemented 00088 doppler -- doppler mode 00089 options: (str) 'RADIO','OPTICAL','Z','BETA','GAMMA' 00090 default: currently set doppler in scantable 00091 scanlist -- list or string of scan numbers to process 00092 default: [] (use all scans) 00093 example: [21,22,23,24], or "21~24" 00094 this selection is in addition to field, iflist, pollist, 00095 and beamlist 00096 field -- selection string for selecting scans by name 00097 default: '' (no name selection) 00098 example: 'FLS3a*' 00099 this selection is in addition to scanlist, iflist, pollist, 00100 and beamlist 00101 iflist -- list or string of IF id numbers to select 00102 default: [] (use all IFs) 00103 example: [15] 00104 this selection is in addition to scanlist, field, pollist, 00105 and beamlist 00106 pollist -- list or string of polarization id numbers to select 00107 default: [] (use all polarizations) 00108 example: [1] 00109 this selection is in addition to scanlist, field, iflist, 00110 and beamlist 00111 beamlist -- list or string of beam id numbers to select 00112 default: [] (use all beams) 00113 example: [1] 00114 this selection is in addition to scanlist, field, iflist, 00115 and pollist 00116 scanaverage -- average integs within scans 00117 options: (bool) True,False 00118 default: False 00119 timeaverage -- average times for multiple scan cycles 00120 options: (bool) True,False 00121 default: False 00122 example: if True, this happens after calibration 00123 >>>timeaverage expandable parameter 00124 tweight -- weighting for time average 00125 options: 'var' (1/var(spec) weighted) 00126 'tsys' (1/Tsys**2 weighted) 00127 'tint' (integration time weighted) 00128 'tintsys' (Tint/Tsys**2) 00129 'median' ( median averaging) 00130 default: 'tintsys' 00131 polaverage -- average polarizations 00132 options: (bool) True,False 00133 default: False 00134 >>>polaverage expandable parameter 00135 pweight -- weighting for polarization average 00136 options: 'var' (1/var(spec) weighted) 00137 'tsys' (1/Tsys**2 weighted) 00138 default: 'tsys' 00139 kernel -- type of spectral smoothing 00140 options: 'hanning','gaussian','boxcar', 'none' 00141 default: 'none' 00142 >>>kernel expandable parameter 00143 kwidth -- width of spectral smoothing kernel 00144 options: (int) in channels 00145 default: 5 00146 example: 5 or 10 seem to be popular for boxcar 00147 ignored for hanning (fixed at 5 chans) 00148 (0 will turn off gaussian or boxcar) 00149 plottype -- type of plot 00150 options: 'spectra','totalpower','pointing','azel','grid' 00151 default: 'spectra' 00152 >>> plottype expandable parameters 00153 stack -- code for stacking on single plot for spectral plotting 00154 options: 'p','b','i','t','s','r' or 00155 'pol', 'beam', 'if', 'time', 'scan', 'row' 00156 default: 'p' 00157 example: maximum of 16 stacked spectra 00158 stack by pol, beam, if, time, scan 00159 Note stack selection is ignored when panel='r'. 00160 panel -- code for splitting into multiple panels for spectral plotting 00161 options: 'p','b','i','t','s','r' or 00162 'pol', 'beam', 'if', 'time', 'scan', 'row' 00163 default: 'i' 00164 example: maximum of 16 panels 00165 panel by pol, beam, if, time, scan 00166 Note panel selection is ignored when stack='r'. 00167 flrange -- range for flux axis of plot for spectral plotting 00168 options: (list) [min,max] 00169 default: [] (full range) 00170 example: flrange=[-0.1,2.0] if 'K' 00171 assumes current fluxunit 00172 sprange -- range for spectral axis of plot 00173 options: (list) [min,max] 00174 default: [] (full range) 00175 example: sprange=[42.1,42.5] if 'GHz' 00176 assumes current specunit 00177 linecat -- control for line catalog plotting for spectral plotting 00178 options: (str) 'all','none' or by molecule 00179 default: 'none' (no lines plotted) 00180 example: linecat='SiO' for SiO lines 00181 linecat='*OH' for alcohols 00182 uses sprange to limit catalog 00183 WARNING: specunit must be in frequency (*Hz) 00184 to plot from the line catalog! 00185 and must be 'GHz' or 'MHz' to use 00186 sprange to limit catalog 00187 linedop -- doppler offset for line catalog plotting (spectral plotting) 00188 options: (float) doppler velocity (km/s) 00189 default: 0.0 00190 example: linedop=-30.0 00191 center -- the central direction of gridding 00192 default: '' (map center) 00193 example: 'J2000 19h30m00 -40d00m00' 00194 Note currently only supports 'J2000' as direction frame 00195 cell -- x and y cell size of gridding 00196 default: [] (map extent devided by # of subplots in x and y) 00197 example: cell=['1.0arcmin','1.0arcmin'] 00198 cell='1.0arcmin' (equivalent to the example above) 00199 Note default number of subplots is 1 x 1 in plottype='grid'. 00200 subplot -- number of subplots (row and column) on a page 00201 NOTICE plotter will slow down when a large number is specified 00202 default: -1 (auto. for plottype='spectra', 1x1 for plottype='grid') 00203 example: 23 (2 rows by 3 columns) 00204 colormap -- the colours to be used for plot lines. 00205 default: None 00206 example: colormap="green red black cyan magenta" (html standard) 00207 colormap="g r k c m" (abbreviation) 00208 colormap="#008000 #00FFFF #FF0090" (RGB tuple) 00209 The plotter will cycle through these colours 00210 when lines are overlaid (stacking mode). 00211 linestyles -- the linestyles to be used for plot lines. 00212 default: None 00213 example: linestyles="line dashed dotted dashdot dashdotdot dashdashdot". 00214 The plotter will cycle through these linestyles 00215 when lines are overlaid (stacking mode). 00216 WARNING: Linestyles can be specified only one color has been set. 00217 linewidth -- width of plotted lines. 00218 default: 1 00219 example: linewidth=1 (integer) 00220 linewidth=0.75 (double) 00221 histogram -- plot histogram 00222 options: (bool) True, False 00223 default: False 00224 header -- print header information on the plot 00225 options: (bool) True, False 00226 default: True 00227 The header information is printed only on the logger when 00228 plottype = 'azel' and 'pointing'. 00229 >>> header expandable parameter 00230 headsize -- header font size 00231 options: (int) 00232 default: 9 00233 plotstyle -- customise plot settings 00234 options: (bool) True, False 00235 default: False 00236 >>> plotstyle expandable parameter 00237 margin -- a list of subplot margins in figure coordinate (0-1), 00238 i.e., fraction of the figure width or height. 00239 The order of elements should be: 00240 [left, bottom, right, top, horizontal space btw panels, 00241 vertical space btw panels] 00242 example: margin = [0.125, 0.1, 0.9, 0.9, 0.2, 0.2] 00243 legendloc -- legend location on the axes (0-10) 00244 options: (integer) 0 -10 00245 see help of "sd.plotter.set_legend" for 00246 the detail of location. Note that 0 ('best') 00247 is very slow. 00248 default: 1 ('upper right') 00249 outfile -- file name for hardcopy output 00250 options: (str) filename.eps,.ps,.png 00251 default: '' (no hardcopy) 00252 example: 'specplot.eps','specplot.png' 00253 Note this autodetects the format from the suffix (.eps,.ps,.png). 00254 overwrite -- overwrite the output file if already exists 00255 options: (bool) True,False 00256 default: False 00257 00258 00259 DESCRIPTION: 00260 00261 Task sdplot displays single-dish spectra, total power, 00262 or pointing direction of input data. 00263 It assumes that the spectra have been calibrated. 00264 It does allow selection of scans, IFs, polarizations, and 00265 some time and channel averaging/smoothing options also, 00266 but does not write out this data. 00267 00268 This task adds an additional toolbar to Matplotlib plotter. 00269 See the cookbook for details of its capability. 00270 00271 *** Data selection *** 00272 This task allows data selection via field name, scan, IF, 00273 polarization and beam IDs. Selection of field allows pattern 00274 matching using asterisk, e.g., 'FLS3a*'. Selection of scans, 00275 IFs, polarizations, and beams, is possible either by a list 00276 of IDs or by a CASA type selection syntax using a string of 00277 comma separated numbers with operaters, i.e., '~', '>', '>=', 00278 '<', and '<='. 00279 For example, the following two selections are equivalent: 00280 scanlist = [0, 1, 2, 7, 8, 9, 15] 00281 scanlist = "<3,7~9,15" 00282 00283 *** control of plot lines in 'spectra' and 'grid' plottype *** 00284 Note that colormap and linestyles cannot be controlled at a time. 00285 The 'linestyles' is ignored if both of them are specified. 00286 Some plot options, like changing titles, legends, fonts, 00287 and the like are not supported in this task. You should use 00288 sd.plotter from the ASAP toolkit directly for this. 00289 00290 *** available plottypes *** 00291 * plottype = 'spectra' plots single dish spectra. Multiple scans, 00292 IFs, polarizations, and beams can be handles through stacking 00293 and panelling. 00294 This task uses the JPL line catalog as supplied by ASAP. 00295 If you wish to use a different catalog, or have it plot 00296 the line IDs from top or bottom (rather than alternating), 00297 then you will need to explore the sd toolkit also. 00298 * plottype = 'grid' plots spectra based on their pointing direction. 00299 The spectra are gridded by direction before plotting. 00300 Multiple IFs and polarizations are not handled in this mode. Only 00301 the first IF and polarizaion is gridded and plotted if data 00302 includes multiple IDs after selections are applied. Hence, over 00303 plotting is not available 00304 00305 Currently most of the parameters are ignored in the following modes. 00306 00307 * plottype='totalpower' is used to plot the total power data. 00308 and only plot option is amplitude versus data row number. 00309 * plottype='azel' plots azimuth and elevation tracks of the source. 00310 * plottype='pointing' plots antenna poinitings. 00311 00312 ASAP recognizes the data of the "AT" telescopes, but currently 00313 does not know about the GBT or any other telescope. This task 00314 does know about GBT. Telescope name is obtained from the data. 00315 If you wish to change the fluxunit (see below), and telescopeparm='', 00316 for the AT telescopes it will use internal telescope parameters for 00317 flux conversion. For GBT, it will use an approximate aperture 00318 efficiency conversion. If you give telescopeparm a list, 00319 then if the list has a single float it is assumed to 00320 be the gain in Jy/K, if two or more elements they are assumed 00321 to be telescope diameter (m) and aperture efficiency 00322 respectively. 00323 00324 WARNING: be careful plotting otf data with lots of fields! 00325 00326 WARNING for the GBT raw SDFITS format data as input: 00327 SDtasks are able to handle GBT raw SDFITS format data since the 00328 data filler is available. However, the functionality is not well 00329 tested yet, so that there may be unknown bugs. 00330 00331 00332 """ 00333 if not hasattr(self, "__globals__") or self.__globals__ == None : 00334 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00335 #casac = self.__globals__['casac'] 00336 casalog = self.__globals__['casalog'] 00337 #casalog = casac.casac.logsink() 00338 self.__globals__['__last_task'] = 'sdplot' 00339 self.__globals__['taskname'] = 'sdplot' 00340 ### 00341 self.__globals__['update_params'](func=self.__globals__['taskname'],printtext=False,ipython_globals=self.__globals__) 00342 ### 00343 ### 00344 #Handle globals or user over-ride of arguments 00345 # 00346 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00347 useLocalDefaults = False 00348 00349 for item in function_signature_defaults.iteritems(): 00350 key,val = item 00351 keyVal = eval(key) 00352 if (keyVal == None): 00353 #user hasn't set it - use global/default 00354 pass 00355 else: 00356 #user has set it - use over-ride 00357 if (key != 'self') : 00358 useLocalDefaults = True 00359 00360 myparams = {} 00361 if useLocalDefaults : 00362 for item in function_signature_defaults.iteritems(): 00363 key,val = item 00364 keyVal = eval(key) 00365 exec('myparams[key] = keyVal') 00366 self.parameters[key] = keyVal 00367 if (keyVal == None): 00368 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00369 keyVal = eval(key) 00370 if(type(keyVal) == dict) : 00371 if len(keyVal) > 0 : 00372 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00373 else : 00374 exec('myparams[key] = ' + key + ' = {}') 00375 00376 else : 00377 async = self.parameters['async'] 00378 myparams['infile'] = infile = self.parameters['infile'] 00379 myparams['antenna'] = antenna = self.parameters['antenna'] 00380 myparams['fluxunit'] = fluxunit = self.parameters['fluxunit'] 00381 myparams['telescopeparm'] = telescopeparm = self.parameters['telescopeparm'] 00382 myparams['specunit'] = specunit = self.parameters['specunit'] 00383 myparams['restfreq'] = restfreq = self.parameters['restfreq'] 00384 myparams['frame'] = frame = self.parameters['frame'] 00385 myparams['doppler'] = doppler = self.parameters['doppler'] 00386 myparams['scanlist'] = scanlist = self.parameters['scanlist'] 00387 myparams['field'] = field = self.parameters['field'] 00388 myparams['iflist'] = iflist = self.parameters['iflist'] 00389 myparams['pollist'] = pollist = self.parameters['pollist'] 00390 myparams['beamlist'] = beamlist = self.parameters['beamlist'] 00391 myparams['scanaverage'] = scanaverage = self.parameters['scanaverage'] 00392 myparams['timeaverage'] = timeaverage = self.parameters['timeaverage'] 00393 myparams['tweight'] = tweight = self.parameters['tweight'] 00394 myparams['polaverage'] = polaverage = self.parameters['polaverage'] 00395 myparams['pweight'] = pweight = self.parameters['pweight'] 00396 myparams['kernel'] = kernel = self.parameters['kernel'] 00397 myparams['kwidth'] = kwidth = self.parameters['kwidth'] 00398 myparams['plottype'] = plottype = self.parameters['plottype'] 00399 myparams['stack'] = stack = self.parameters['stack'] 00400 myparams['panel'] = panel = self.parameters['panel'] 00401 myparams['flrange'] = flrange = self.parameters['flrange'] 00402 myparams['sprange'] = sprange = self.parameters['sprange'] 00403 myparams['linecat'] = linecat = self.parameters['linecat'] 00404 myparams['linedop'] = linedop = self.parameters['linedop'] 00405 myparams['subplot'] = subplot = self.parameters['subplot'] 00406 myparams['colormap'] = colormap = self.parameters['colormap'] 00407 myparams['linestyles'] = linestyles = self.parameters['linestyles'] 00408 myparams['linewidth'] = linewidth = self.parameters['linewidth'] 00409 myparams['histogram'] = histogram = self.parameters['histogram'] 00410 myparams['center'] = center = self.parameters['center'] 00411 myparams['cell'] = cell = self.parameters['cell'] 00412 myparams['header'] = header = self.parameters['header'] 00413 myparams['headsize'] = headsize = self.parameters['headsize'] 00414 myparams['plotstyle'] = plotstyle = self.parameters['plotstyle'] 00415 myparams['margin'] = margin = self.parameters['margin'] 00416 myparams['legendloc'] = legendloc = self.parameters['legendloc'] 00417 myparams['outfile'] = outfile = self.parameters['outfile'] 00418 myparams['overwrite'] = overwrite = self.parameters['overwrite'] 00419 00420 if type(flrange)==float: flrange=[flrange] 00421 if type(cell)==float: cell=[cell] 00422 if type(margin)==float: margin=[margin] 00423 00424 result = None 00425 00426 # 00427 # The following is work around to avoid a bug with current python translation 00428 # 00429 mytmp = {} 00430 00431 mytmp['infile'] = infile 00432 mytmp['antenna'] = antenna 00433 mytmp['fluxunit'] = fluxunit 00434 mytmp['telescopeparm'] = telescopeparm 00435 mytmp['specunit'] = specunit 00436 mytmp['restfreq'] = restfreq 00437 mytmp['frame'] = frame 00438 mytmp['doppler'] = doppler 00439 mytmp['scanlist'] = scanlist 00440 mytmp['field'] = field 00441 mytmp['iflist'] = iflist 00442 mytmp['pollist'] = pollist 00443 mytmp['beamlist'] = beamlist 00444 mytmp['scanaverage'] = scanaverage 00445 mytmp['timeaverage'] = timeaverage 00446 mytmp['tweight'] = tweight 00447 mytmp['polaverage'] = polaverage 00448 mytmp['pweight'] = pweight 00449 mytmp['kernel'] = kernel 00450 mytmp['kwidth'] = kwidth 00451 mytmp['plottype'] = plottype 00452 mytmp['stack'] = stack 00453 mytmp['panel'] = panel 00454 mytmp['flrange'] = flrange 00455 mytmp['sprange'] = sprange 00456 mytmp['linecat'] = linecat 00457 mytmp['linedop'] = linedop 00458 mytmp['subplot'] = subplot 00459 mytmp['colormap'] = colormap 00460 mytmp['linestyles'] = linestyles 00461 mytmp['linewidth'] = linewidth 00462 mytmp['histogram'] = histogram 00463 mytmp['center'] = center 00464 mytmp['cell'] = cell 00465 mytmp['header'] = header 00466 mytmp['headsize'] = headsize 00467 mytmp['plotstyle'] = plotstyle 00468 mytmp['margin'] = margin 00469 mytmp['legendloc'] = legendloc 00470 mytmp['outfile'] = outfile 00471 mytmp['overwrite'] = overwrite 00472 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00473 trec = casac.casac.utils().torecord(pathname+'sdplot.xml') 00474 00475 casalog.origin('sdplot') 00476 try : 00477 #if not trec.has_key('sdplot') or not casac.casac.utils().verify(mytmp, trec['sdplot']) : 00478 #return False 00479 00480 casac.casac.utils().verify(mytmp, trec['sdplot'], True) 00481 scriptstr=[''] 00482 saveinputs = self.__globals__['saveinputs'] 00483 saveinputs('sdplot', 'sdplot.last', myparams, self.__globals__,scriptstr=scriptstr) 00484 if async : 00485 count = 0 00486 keybase = time.strftime("%y%m%d.%H%M%S") 00487 key = keybase + "_" + str(count) 00488 while self.__async__.has_key(key) : 00489 count += 1 00490 key = keybase + "_" + str(count) 00491 result = tm.execute('sdplot', infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, beamlist, scanaverage, timeaverage, tweight, polaverage, pweight, kernel, kwidth, plottype, stack, panel, flrange, sprange, linecat, linedop, subplot, colormap, linestyles, linewidth, histogram, center, cell, header, headsize, plotstyle, margin, legendloc, outfile, overwrite) 00492 print "Use: " 00493 print " tm.retrieve(return_value) # to retrieve the status" 00494 print 00495 self.rkey = key 00496 self.__async__[key] = result 00497 else : 00498 tname = 'sdplot' 00499 spaces = ' '*(18-len(tname)) 00500 casalog.post('\n##########################################'+ 00501 '\n##### Begin Task: ' + tname + spaces + ' #####') 00502 casalog.post(scriptstr[1][1:]+'\n', 'INFO') 00503 result = sdplot(infile, antenna, fluxunit, telescopeparm, specunit, restfreq, frame, doppler, scanlist, field, iflist, pollist, beamlist, scanaverage, timeaverage, tweight, polaverage, pweight, kernel, kwidth, plottype, stack, panel, flrange, sprange, linecat, linedop, subplot, colormap, linestyles, linewidth, histogram, center, cell, header, headsize, plotstyle, margin, legendloc, outfile, overwrite) 00504 casalog.post('##### End Task: ' + tname + ' ' + spaces + ' #####'+ 00505 '\n##########################################') 00506 00507 except Exception, instance: 00508 if(self.__globals__.has_key('__rethrow_casa_exceptions') and self.__globals__['__rethrow_casa_exceptions']) : 00509 raise 00510 else : 00511 #print '**** Error **** ',instance 00512 tname = 'sdplot' 00513 casalog.post('An error occurred running task '+tname+'.', 'ERROR') 00514 pass 00515 00516 gc.collect() 00517 return result 00518 # 00519 # 00520 # 00521 def paramgui(self, useGlobals=True, ipython_globals=None): 00522 """ 00523 Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00524 """ 00525 import paramgui 00526 if not hasattr(self, "__globals__") or self.__globals__ == None : 00527 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00528 00529 if useGlobals: 00530 if ipython_globals == None: 00531 myf=self.__globals__ 00532 else: 00533 myf=ipython_globals 00534 00535 paramgui.setGlobals(myf) 00536 else: 00537 paramgui.setGlobals({}) 00538 00539 paramgui.runTask('sdplot', myf['_ip']) 00540 paramgui.setGlobals({}) 00541 00542 # 00543 # 00544 # 00545 def defaults(self, param=None, ipython_globals=None, paramvalue=None, subparam=None): 00546 if not hasattr(self, "__globals__") or self.__globals__ == None : 00547 self.__globals__=sys._getframe(len(inspect.stack())-1).f_globals 00548 if ipython_globals == None: 00549 myf=self.__globals__ 00550 else: 00551 myf=ipython_globals 00552 00553 a = odict() 00554 a['infile'] = '' 00555 a['antenna'] = 0 00556 a['fluxunit'] = '' 00557 a['specunit'] = '' 00558 a['frame'] = '' 00559 a['doppler'] = '' 00560 a['scanlist'] = [] 00561 a['field'] = '' 00562 a['iflist'] = [] 00563 a['pollist'] = [] 00564 a['beamlist'] = [] 00565 a['scanaverage'] = False 00566 a['timeaverage'] = False 00567 a['polaverage'] = False 00568 a['kernel'] = 'none' 00569 a['plottype'] = 'spectra' 00570 a['header'] = True 00571 a['plotstyle'] = False 00572 a['outfile'] = '' 00573 a['overwrite'] = False 00574 00575 a['async']=False 00576 a['fluxunit'] = { 00577 0:{'value':''}, 00578 1:odict([{'value':'K'}, {'telescopeparm':""}]), 00579 2:odict([{'value':'k'}, {'telescopeparm':""}]), 00580 3:odict([{'value':'Jy'}, {'telescopeparm':""}]), 00581 4:odict([{'value':'jy'}, {'telescopeparm':""}])} 00582 a['specunit'] = { 00583 0:{'value':''}, 00584 1:{'value':'channel'}, 00585 2:odict([{'value':'km/s'}, {'restfreq':''}]), 00586 3:{'value':'GHz'}, 00587 4:{'value':'MHz'}, 00588 5:{'value':'kHz'}, 00589 6:{'value':'Hz'}} 00590 a['kernel'] = { 00591 0:{'value':'none'}, 00592 1:{'value':'hanning'}, 00593 2:odict([{'value':'gaussian'}, {'kwidth':5}]), 00594 3:odict([{'value':'boxcar'}, {'kwidth':5}])} 00595 a['plottype'] = { 00596 0:odict([{'value':'spectra'}, {'stack':'p'}, {'panel':'i'}, {'flrange':[]}, {'sprange':[]}, {'linecat':'none'}, {'linedop':0.0}, {'subplot':-1}, {'colormap':'none'}, {'linestyles':'none'}, {'linewidth':1}, {'histogram':False}]), 00597 1:odict([{'value':'grid'}, {'center':''}, {'cell':[]}, {'subplot':-1}, {'flrange':[]}, {'sprange':[]}, {'colormap':'none'}, {'linestyles':'none'}, {'linewidth':1}]), 00598 2:{'value':'totalpower'}, 00599 3:{'value':'pointing'}, 00600 4:{'value':'azel'}} 00601 a['timeaverage'] = { 00602 0:{'value':False}, 00603 1:odict([{'value':True}, {'tweight':'tintsys'}])} 00604 a['polaverage'] = { 00605 0:{'value':False}, 00606 1:odict([{'value':True}, {'pweight':'tsys'}])} 00607 a['header'] = { 00608 0:odict([{'value':True}, {'headsize':9}]), 00609 1:{'value':False}} 00610 a['plotstyle'] = { 00611 0:{'value':False}, 00612 1:odict([{'value':True}, {'margin':[]}, {'legendloc':1}])} 00613 00614 ### This function sets the default values but also will return the list of 00615 ### parameters or the default value of a given parameter 00616 if(param == None): 00617 myf['__set_default_parameters'](a) 00618 elif(param == 'paramkeys'): 00619 return a.keys() 00620 else: 00621 if(paramvalue==None and subparam==None): 00622 if(a.has_key(param)): 00623 return a[param] 00624 else: 00625 return self.itsdefault(param) 00626 else: 00627 retval=a[param] 00628 if(type(a[param])==dict): 00629 for k in range(len(a[param])): 00630 valornotval='value' 00631 if(a[param][k].has_key('notvalue')): 00632 valornotval='notvalue' 00633 if((a[param][k][valornotval])==paramvalue): 00634 retval=a[param][k].copy() 00635 retval.pop(valornotval) 00636 if(subparam != None): 00637 if(retval.has_key(subparam)): 00638 retval=retval[subparam] 00639 else: 00640 retval=self.itsdefault(subparam) 00641 else: 00642 retval=self.itsdefault(subparam) 00643 return retval 00644 00645 00646 # 00647 # 00648 def check_params(self, param=None, value=None, ipython_globals=None): 00649 if ipython_globals == None: 00650 myf=self.__globals__ 00651 else: 00652 myf=ipython_globals 00653 # print 'param:', param, 'value:', value 00654 try : 00655 if str(type(value)) != "<type 'instance'>" : 00656 value0 = value 00657 value = myf['cu'].expandparam(param, value) 00658 matchtype = False 00659 if(type(value) == numpy.ndarray): 00660 if(type(value) == type(value0)): 00661 myf[param] = value.tolist() 00662 else: 00663 #print 'value:', value, 'value0:', value0 00664 #print 'type(value):', type(value), 'type(value0):', type(value0) 00665 myf[param] = value0 00666 if type(value0) != list : 00667 matchtype = True 00668 else : 00669 myf[param] = value 00670 value = myf['cu'].verifyparam({param:value}) 00671 if matchtype: 00672 value = False 00673 except Exception, instance: 00674 #ignore the exception and just return it unchecked 00675 myf[param] = value 00676 return value 00677 # 00678 # 00679 def description(self, key='sdplot', subkey=None): 00680 desc={'sdplot': 'ASAP SD plotting task ', 00681 'infile': 'name of input SD dataset', 00682 'antenna': 'antenna name or id (only effective for MS input)', 00683 'fluxunit': 'units for line flux (K,Jy) (''=current)', 00684 'telescopeparm': 'param of telescope for flux conversion', 00685 'specunit': 'units for spectral axis (channel,km/s,GHz)', 00686 'restfreq': 'rest frequency (default unit: Hz)', 00687 'frame': 'frequency reference frame, e.g. LSRK (''=current)', 00688 'doppler': 'doppler convention, e.g. RADIO (''=current)', 00689 'scanlist': 'list or string of scans to use (e.g. [1,2,3,4] or "1~4")', 00690 'field': 'string for selection by source name', 00691 'iflist': 'list or string of IF ids to select (e.g. [0,1] or "0~1")', 00692 'pollist': 'list or string of polarization ids to select (e.g. [0,1])', 00693 'beamlist': 'list or string of beam ids to select (e.g. [0,1])', 00694 'scanaverage': 'average integs within scans (True,False)', 00695 'timeaverage': 'average scans over time (True,False)', 00696 'tweight': 'weighting for time averaging', 00697 'polaverage': 'average over polarizations (True,False)', 00698 'pweight': '', 00699 'kernel': 'type of spectral smoothing', 00700 'kwidth': 'width of spectral kernel in channels', 00701 'plottype': 'type of plot (spectra, totalpower, azel, pointing, grid)', 00702 'stack': 'code for stacking on single plot for spectral plotting', 00703 'panel': 'code for splitting into multiple panels for spectral plotting', 00704 'flrange': 'range for flux axis of plot for spectral plotting', 00705 'sprange': 'range for spectral axis of plot', 00706 'linecat': 'control for line catalog plotting for spectral plotting', 00707 'linedop': 'doppler offset for line catalog plotting (spectral plotting)', 00708 'subplot': 'number of subplots (row and column)', 00709 'colormap': 'the colours to be used for plot lines', 00710 'linestyles': 'the linestyles to be used for plot lines', 00711 'linewidth': 'width of plotted lines', 00712 'histogram': 'plot histogram', 00713 'center': 'the central direction of gridding. (default: map center)', 00714 'cell': 'x and y cell size, e.g., ["1arcmin","1arcmin"]. (default map extent/subplot number)', 00715 'header': 'print header information on the plot', 00716 'headsize': 'header fontsize', 00717 'plotstyle': 'customise plot settings', 00718 'margin': 'subplot margins in figure coordinate', 00719 'legendloc': 'legend location', 00720 'outfile': 'file name for hardcopy output', 00721 'overwrite': 'overwrite the output file if already exists', 00722 00723 'async': 'If true the taskname must be started using sdplot(...)' 00724 } 00725 00726 # 00727 # Set subfields defaults if needed 00728 # 00729 00730 if(desc.has_key(key)) : 00731 return desc[key] 00732 00733 def itsdefault(self, paramname) : 00734 a = {} 00735 a['infile'] = '' 00736 a['antenna'] = 0 00737 a['fluxunit'] = '' 00738 a['telescopeparm'] = '' 00739 a['specunit'] = '' 00740 a['restfreq'] = '' 00741 a['frame'] = '' 00742 a['doppler'] = '' 00743 a['scanlist'] = [] 00744 a['field'] = '' 00745 a['iflist'] = [] 00746 a['pollist'] = [] 00747 a['beamlist'] = [] 00748 a['scanaverage'] = False 00749 a['timeaverage'] = False 00750 a['tweight'] = 'tintsys' 00751 a['polaverage'] = False 00752 a['pweight'] = 'tsys' 00753 a['kernel'] = 'none' 00754 a['kwidth'] = 5 00755 a['plottype'] = 'spectra' 00756 a['stack'] = 'p' 00757 a['panel'] = 'i' 00758 a['flrange'] = [] 00759 a['sprange'] = [] 00760 a['linecat'] = 'none' 00761 a['linedop'] = 0.0 00762 a['subplot'] = -1 00763 a['colormap'] = 'none' 00764 a['linestyles'] = 'none' 00765 a['linewidth'] = 1 00766 a['histogram'] = False 00767 a['center'] = '' 00768 a['cell'] = [] 00769 a['header'] = True 00770 a['headsize'] = 9 00771 a['plotstyle'] = False 00772 a['margin'] = [] 00773 a['legendloc'] = 1 00774 a['outfile'] = '' 00775 a['overwrite'] = False 00776 00777 #a = sys._getframe(len(inspect.stack())-1).f_globals 00778 00779 if self.parameters['fluxunit'] == 'K': 00780 a['telescopeparm'] = "" 00781 00782 if self.parameters['fluxunit'] == 'k': 00783 a['telescopeparm'] = "" 00784 00785 if self.parameters['fluxunit'] == 'Jy': 00786 a['telescopeparm'] = "" 00787 00788 if self.parameters['fluxunit'] == 'jy': 00789 a['telescopeparm'] = "" 00790 00791 if self.parameters['specunit'] == 'km/s': 00792 a['restfreq'] = '' 00793 00794 if self.parameters['kernel'] == 'gaussian': 00795 a['kwidth'] = 5 00796 00797 if self.parameters['kernel'] == 'boxcar': 00798 a['kwidth'] = 5 00799 00800 if self.parameters['plottype'] == 'spectra': 00801 a['stack'] = 'p' 00802 a['panel'] = 'i' 00803 a['flrange'] = [] 00804 a['sprange'] = [] 00805 a['linecat'] = 'none' 00806 a['linedop'] = 0.0 00807 a['subplot'] = -1 00808 a['colormap'] = 'none' 00809 a['linestyles'] = 'none' 00810 a['linewidth'] = 1 00811 a['histogram'] = False 00812 00813 if self.parameters['plottype'] == 'grid': 00814 a['center'] = '' 00815 a['cell'] = [] 00816 a['subplot'] = -1 00817 a['flrange'] = [] 00818 a['sprange'] = [] 00819 a['colormap'] = 'none' 00820 a['linestyles'] = 'none' 00821 a['linewidth'] = 1 00822 00823 if self.parameters['timeaverage'] == True: 00824 a['tweight'] = 'tintsys' 00825 00826 if self.parameters['polaverage'] == True: 00827 a['pweight'] = 'tsys' 00828 00829 if self.parameters['header'] == True: 00830 a['headsize'] = 9 00831 00832 if self.parameters['plotstyle'] == True: 00833 a['margin'] = [] 00834 a['legendloc'] = 1 00835 00836 if a.has_key(paramname) : 00837 return a[paramname] 00838 sdplot_cli = sdplot_cli_()