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 string 00010 import time 00011 import inspect 00012 import gc 00013 import numpy 00014 from odict import odict 00015 from task_blcal import blcal 00016 from task_blcal import casalog 00017 00018 class blcal_pg_: 00019 __name__ = "blcal" 00020 00021 def __init__(self) : 00022 self.__bases__ = (blcal_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, vis=None, caltable=None, field=None, spw=None, intent=None, selectdata=None, timerange=None, uvrange=None, antenna=None, scan=None, observation=None, msselect=None, solint=None, combine=None, freqdep=None, calmode=None, solnorm=None, gaintable=None, gainfield=None, interp=None, spwmap=None, gaincurve=None, opacity=None, parang=None, async=None): 00027 00028 """Calculate a baseline-based calibration solution (gain or bandpass) 00029 00030 This task determines a baseline by baseline gain (time) or bandpass (freq) 00031 for all baseline pairs in the data set. For the usual antenna-based calibration 00032 of interferometric data, this task gaincal is recommended, even with only one 00033 to three baselines. For arrays with closure errors, use blcal 00034 00035 Keyword arguments: 00036 vis -- Name of input visibility file 00037 default: none; example: vis='ngc5921.ms' 00038 caltable -- Name of output Gain calibration table 00039 default: none; example: caltable='ngc5921.gcal' 00040 00041 --- Data Selection (see help par.selectdata for more detailed information) 00042 00043 field -- Select field using field id(s) or field name(s). 00044 [run listobs to obtain the list id's or names] 00045 default: ''=all fields 00046 If field string is a non-negative integer, it is assumed a field index 00047 otherwise, it is assumed a field name 00048 field='0~2'; field ids 0,1,2 00049 field='0,4,5~7'; field ids 0,4,5,6,7 00050 field='3C286,3C295'; field named 3C286 adn 3C295 00051 field = '3,4C*'; field id 3, all names starting with 4C 00052 spw -- Select spectral window/channels 00053 default: ''=all spectral windows and channels 00054 spw='0~2,4'; spectral windows 0,1,2,4 (all channels) 00055 spw='<2'; spectral windows less than 2 (i.e. 0,1) 00056 spw='0:5~61'; spw 0, channels 5 to 61 00057 spw='0,10,3:3~45'; spw 0,10 all channels, spw 3, channels 3 to 45. 00058 spw='0~2:2~6'; spw 0,1,2 with channels 2 through 6 in each. 00059 spw='0:0~10;15~60'; spectral window 0 with channels 0-10,15-60 00060 spw='0:0~10,1:20~30,2:1;2;3'; spw 0, channels 0-10, 00061 spw 1, channels 20-30, and spw 2, channels, 1,2 and 3 00062 intent -- Select observing intent 00063 default: '' (no selection by intent) 00064 intent='*BANDPASS*' (selects data labelled with 00065 BANDPASS intent) 00066 selectdata -- Other data selection parameters 00067 default: True 00068 timerange -- Select data based on time range: 00069 default = '' (all); examples, 00070 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss' 00071 Note: if YYYY/MM/DD is missing dat defaults to first day in data set 00072 timerange='09:14:0~09:54:0' picks 40 min on first day 00073 timerange= '25:00:00~27:30:00' picks 1 hr to 3 hr 30min on next day 00074 timerange='09:44:00' data within one integration of time 00075 timerange='>10:24:00' data after this time 00076 uvrange -- Select data within uvrange (default units kilo-lambda) 00077 default: '' (all); example: 00078 uvrange='0~1000kl'; uvrange from 0-1000 kilo-lamgda 00079 uvrange='>4kl';uvranges greater than 4 kilo lambda 00080 uvrange='0~1000km'; uvrange in kilometers 00081 antenna -- Select data based on antenna/baseline 00082 default: '' (all) 00083 If antenna string is a non-negative integer, it is assumed an antenna index 00084 otherwise, it is assumed as an antenna name 00085 antenna='5&6'; baseline between antenna index 5 and index 6. 00086 antenna='VA05&VA06'; baseline between VLA antenna 5 and 6. 00087 antenna='5&6;7&8'; baseline 5-6 and 7-8 00088 antenna='5'; all baselines with antenna 5 00089 antenna='5,6,10'; all baselines with antennas 5 and 6 00090 scan -- Scan number range - New, under developement 00091 observation -- Observation ID(s). 00092 default: '' = all 00093 example: '0~2,4' 00094 msselect -- Optional complex data selection (ignore for now) 00095 00096 solint -- Solution interval (units optional) 00097 default: 'inf' (~infinite, up to boundaries controlled by combine); 00098 Options: 'inf' (~infinite), 'int' (per integration), any float 00099 or integer value with or without units 00100 examples: solint='1min'; solint='60s', solint=60 --> 1 minute 00101 solint='0s'; solint=0; solint='int' --> per integration 00102 solint-'-1s'; solint='inf' --> ~infinite, up to boundaries 00103 enforced by combine 00104 combine -- Data axes to combine for solving 00105 default: 'scan' --> solutions will break at field and spw boundaries, 00106 but may extend over multiple scans (per field and spw) up 00107 to solint. 00108 Options: '','scan','spw',field', or any comma-separated combination 00109 example: combine='scan,spw' --> extend solutions over scan boundaries 00110 (up to the solint), and combine spws for solving 00111 freqdep -- Solve for frequency dependent solutions 00112 default: False (gain; True=bandpass); example: freqdep=True 00113 calmode -- Type of solution 00114 default: 'ap' (amp and phase); example: calmode='p' 00115 Options: 'p','a','ap' 00116 solnorm -- Normalize solutions. For freqdep=F, this is a global (per-spw) 00117 normalization of amplitudes (only). For freqdep=T, each baseline 00118 solution spectrum is separately normalized by its (complex) mean. 00119 default: False (no normalization) 00120 00121 gaintable -- Gain calibration table(s) to apply 00122 default: '' (none); 00123 examples: gaintable='ngc5921.gcal' 00124 gaintable=['ngc5921.ampcal','ngc5921.phcal'] 00125 gainfield -- Select a subset of calibrators from gaintable(s) 00126 default:'' ==> all sources in table; 00127 'nearest' ==> nearest (on sky) available field in table 00128 otherwise, same syntax as field 00129 example: gainfield='0~3' 00130 gainfield=['0~3','4~6'] 00131 interp -- Interpolation type (in time[,freq]) to use for each gaintable. 00132 When frequency interpolation is relevant (B, Df, Xf), 00133 separate time-dependent and freq-dependent interp 00134 types with a comma (freq _after_ the comma). 00135 Specifications for frequency are ignored when the 00136 calibration table has no channel-dependence. 00137 Time-dependent interp options ending in 'PD' enable a 00138 "phase delay" correction per spw for non-channel-dependent 00139 calibration types. 00140 default: '' --> 'linear,linear' for all gaintable(s) 00141 example: interp='nearest' (in time, freq-dep will be 00142 linear, if relevant) 00143 interp='linear,cubic' (linear in time, cubic 00144 in freq) 00145 interp=',spline' (spline in freq; linear in 00146 time by default) 00147 interp=['nearest,spline','linear'] (for multiple gaintables) 00148 Options: Time: 'nearest', 'linear' 00149 Freq: 'nearest', 'linear', 'cubic', 'spline' 00150 spwmap -- Spectral windows combinations to form for gaintable(s) 00151 default: [] (apply solutions from each spw to that spw only) 00152 Example: spwmap=[0,0,1,1] means apply the caltable solutions 00153 from spw = 0 to the spw 0,1 and spw 1 to spw 2,3. 00154 spwmap=[[0,0,1,1],[0,1,0,1]] 00155 gaincurve -- Apply internal VLA antenna gain curve correction (True/False) 00156 default: False; 00157 Use gaincurve=True ONLY for VLA data 00158 opacity -- Opacity correction to apply (nepers), per spw 00159 default: [] (no opacity correction for any spw) 00160 examples: 00161 A global value for all spws: 00162 opacity=0.051 00163 Different values for spws 0,1,2: 00164 opacity=[0.051, 0.055, 0.057] 00165 (if more than 3 spws, spw 3 and higher will 00166 be assigned the last specified value, or 0.057) 00167 Typical VLA values are: 5 GHz - 0.013, 8 GHz - 0.013 00168 15 GHz - 0.016, 23 GHz - 0.051, 43 GHz - 0.07 00169 parang -- If True, apply the parallactic angle correction (required 00170 for polarization calibration) 00171 default: False 00172 00173 00174 """ 00175 a=inspect.stack() 00176 stacklevel=0 00177 for k in range(len(a)): 00178 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00179 stacklevel=k 00180 break 00181 myf=sys._getframe(stacklevel).f_globals 00182 myf['__last_task'] = 'blcal' 00183 myf['taskname'] = 'blcal' 00184 ### 00185 myf['update_params'](func=myf['taskname'],printtext=False) 00186 ### 00187 ### 00188 #Handle globals or user over-ride of arguments 00189 # 00190 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00191 useLocalDefaults = False 00192 00193 for item in function_signature_defaults.iteritems(): 00194 key,val = item 00195 keyVal = eval(key) 00196 if (keyVal == None): 00197 #user hasn't set it - use global/default 00198 pass 00199 else: 00200 #user has set it - use over-ride 00201 if (key != 'self') : 00202 useLocalDefaults = True 00203 #myf[key]=keyVal 00204 00205 myparams = {} 00206 if useLocalDefaults : 00207 for item in function_signature_defaults.iteritems(): 00208 key,val = item 00209 keyVal = eval(key) 00210 exec('myparams[key] = keyVal') 00211 if (keyVal == None): 00212 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00213 keyVal = eval(key) 00214 if(type(keyVal) == dict) : 00215 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00216 00217 else : 00218 uselessvariable = None 00219 myparams['vis'] = vis = myf['vis'] 00220 myparams['caltable'] = caltable = myf['caltable'] 00221 myparams['field'] = field = myf['field'] 00222 myparams['spw'] = spw = myf['spw'] 00223 myparams['intent'] = intent = myf['intent'] 00224 myparams['selectdata'] = selectdata = myf['selectdata'] 00225 myparams['timerange'] = timerange = myf['timerange'] 00226 myparams['uvrange'] = uvrange = myf['uvrange'] 00227 myparams['antenna'] = antenna = myf['antenna'] 00228 myparams['scan'] = scan = myf['scan'] 00229 myparams['observation'] = observation = myf['observation'] 00230 myparams['msselect'] = msselect = myf['msselect'] 00231 myparams['solint'] = solint = myf['solint'] 00232 myparams['combine'] = combine = myf['combine'] 00233 myparams['freqdep'] = freqdep = myf['freqdep'] 00234 myparams['calmode'] = calmode = myf['calmode'] 00235 myparams['solnorm'] = solnorm = myf['solnorm'] 00236 myparams['gaintable'] = gaintable = myf['gaintable'] 00237 myparams['gainfield'] = gainfield = myf['gainfield'] 00238 myparams['interp'] = interp = myf['interp'] 00239 myparams['spwmap'] = spwmap = myf['spwmap'] 00240 myparams['gaincurve'] = gaincurve = myf['gaincurve'] 00241 myparams['opacity'] = opacity = myf['opacity'] 00242 myparams['parang'] = parang = myf['parang'] 00243 00244 if type(gaintable)==str: gaintable=[gaintable] 00245 if type(gainfield)==str: gainfield=[gainfield] 00246 if type(interp)==str: interp=[interp] 00247 if type(spwmap)==int: spwmap=[spwmap] 00248 if type(opacity)==float: opacity=[opacity] 00249 00250 result = None 00251 00252 # 00253 # The following is work around to avoid a bug with current python translation 00254 # 00255 mytmp = {} 00256 00257 mytmp['vis'] = vis 00258 mytmp['caltable'] = caltable 00259 mytmp['field'] = field 00260 mytmp['spw'] = spw 00261 mytmp['intent'] = intent 00262 mytmp['selectdata'] = selectdata 00263 mytmp['timerange'] = timerange 00264 mytmp['uvrange'] = uvrange 00265 mytmp['antenna'] = antenna 00266 mytmp['scan'] = scan 00267 mytmp['observation'] = observation 00268 mytmp['msselect'] = msselect 00269 mytmp['solint'] = solint 00270 mytmp['combine'] = combine 00271 mytmp['freqdep'] = freqdep 00272 mytmp['calmode'] = calmode 00273 mytmp['solnorm'] = solnorm 00274 mytmp['gaintable'] = gaintable 00275 mytmp['gainfield'] = gainfield 00276 mytmp['interp'] = interp 00277 mytmp['spwmap'] = spwmap 00278 mytmp['gaincurve'] = gaincurve 00279 mytmp['opacity'] = opacity 00280 mytmp['parang'] = parang 00281 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00282 trec = casac.utils().torecord(pathname+'blcal.xml') 00283 00284 casalog.origin('blcal') 00285 if not trec.has_key('blcal') or not casac.utils().verify(mytmp, trec['blcal']) : 00286 return False 00287 00288 00289 try : 00290 casalog.post('') 00291 casalog.post('##########################################') 00292 casalog.post('##### Begin Task: blcal #####') 00293 casalog.post('') 00294 result = blcal(vis, caltable, field, spw, intent, selectdata, timerange, uvrange, antenna, scan, observation, msselect, solint, combine, freqdep, calmode, solnorm, gaintable, gainfield, interp, spwmap, gaincurve, opacity, parang) 00295 casalog.post('') 00296 casalog.post('##### End Task: blcal #####') 00297 casalog.post('##########################################') 00298 00299 00300 # saveinputs for individule engine has no use 00301 # saveinputs should alos be removed from casa_in_py.py 00302 # 00303 # 00304 # saveinputs = myf['saveinputs'] 00305 # saveinputs('blcal', 'blcal.last', myparams) 00306 # 00307 # 00308 except Exception, instance: 00309 #print '**** Error **** ',instance 00310 pass 00311 00312 gc.collect() 00313 return result 00314 # 00315 # 00316 ## 00317 # def paramgui(self, useGlobals=True): 00318 # """ 00319 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00320 # """ 00321 # import paramgui 00322 # 00323 # a=inspect.stack() 00324 # stacklevel=0 00325 # for k in range(len(a)): 00326 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00327 # stacklevel=k 00328 # break 00329 # myf = sys._getframe(stacklevel).f_globals 00330 # 00331 # if useGlobals: 00332 # paramgui.setGlobals(myf) 00333 # else: 00334 # paramgui.setGlobals({}) 00335 # 00336 # paramgui.runTask('blcal', myf['_ip']) 00337 # paramgui.setGlobals({}) 00338 # 00339 # 00340 # 00341 # 00342 def defaults(self, param=None): 00343 a=inspect.stack() 00344 stacklevel=0 00345 for k in range(len(a)): 00346 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00347 stacklevel=k 00348 break 00349 myf=sys._getframe(stacklevel).f_globals 00350 a = odict() 00351 a['vis'] = '' 00352 a['caltable'] = '' 00353 a['field'] = '' 00354 a['spw'] = '' 00355 a['intent'] = '' 00356 a['selectdata'] = True 00357 a['solint'] = 'inf' 00358 a['combine'] = 'scan' 00359 a['freqdep'] = False 00360 a['calmode'] = 'ap' 00361 a['solnorm'] = False 00362 a['gaintable'] = [''] 00363 a['gainfield'] = [''] 00364 a['interp'] = [''] 00365 a['spwmap'] = [] 00366 a['gaincurve'] = False 00367 a['opacity'] = [] 00368 a['parang'] = False 00369 00370 a['async']=False 00371 a['selectdata'] = { 00372 0:odict([{'value':True}, {'timerange':''}, {'uvrange':''}, {'antenna':''}, {'scan':''}, {'observation':''}, {'msselect':''}]), 00373 1:{'value':False}} 00374 00375 ### This function sets the default values but also will return the list of 00376 ### parameters or the default value of a given parameter 00377 if(param == None): 00378 myf['__set_default_parameters'](a) 00379 elif(param == 'paramkeys'): 00380 return a.keys() 00381 else: 00382 if(a.has_key(param)): 00383 #if(type(a[param]) == dict) : 00384 # return a[param][len(a[param])-1]['value'] 00385 #else : 00386 return a[param] 00387 00388 00389 # 00390 # 00391 def check_params(self, param=None, value=None): 00392 a=inspect.stack() 00393 stacklevel=0 00394 for k in range(len(a)): 00395 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00396 stacklevel=k 00397 break 00398 myf=sys._getframe(stacklevel).f_globals 00399 00400 # print 'param:', param, 'value:', value 00401 try : 00402 if str(type(value)) != "<type 'instance'>" : 00403 value0 = value 00404 value = myf['cu'].expandparam(param, value) 00405 matchtype = False 00406 if(type(value) == numpy.ndarray): 00407 if(type(value) == type(value0)): 00408 myf[param] = value.tolist() 00409 else: 00410 #print 'value:', value, 'value0:', value0 00411 #print 'type(value):', type(value), 'type(value0):', type(value0) 00412 myf[param] = value0 00413 if type(value0) != list : 00414 matchtype = True 00415 else : 00416 myf[param] = value 00417 value = myf['cu'].verifyparam({param:value}) 00418 if matchtype: 00419 value = False 00420 except Exception, instance: 00421 #ignore the exception and just return it unchecked 00422 myf[param] = value 00423 return value 00424 00425 # 00426 # 00427 def description(self, key='blcal', subkey=None): 00428 desc={'blcal': 'Calculate a baseline-based calibration solution (gain or bandpass)', 00429 'vis': 'Name of input visibility file', 00430 'caltable': 'Name of output gain calibration table', 00431 'field': 'Select field using field id(s) or field name(s)', 00432 'spw': 'Select spectral window/channels', 00433 'intent': 'Select observing intent', 00434 'selectdata': 'Other data selection parameters', 00435 'timerange': 'Select data based on time range', 00436 'uvrange': 'Select data within uvrange (default units meters)', 00437 'antenna': 'Select data based on antenna/baseline', 00438 'scan': 'Scan number range', 00439 'observation': 'Select by observation ID(s)', 00440 'msselect': 'Optional complex data selection (ignore for now)', 00441 'solint': 'Solution interval', 00442 'combine': 'Data axes which to combine for solve (scan, spw, and/or field)', 00443 'freqdep': 'Solve for frequency dependent solutions', 00444 'calmode': 'Type of solution" (\'ap\', \'p\', \'a\')', 00445 'solnorm': 'Normalize average solution amplitudes to 1.0', 00446 'gaintable': 'Gain calibration table(s) to apply on the fly', 00447 'gainfield': 'Select a subset of calibrators from gaintable(s)', 00448 'interp': 'Interpolation mode (in time) to use for each gaintable', 00449 'spwmap': 'Spectral windows combinations to form for gaintables(s)', 00450 'gaincurve': 'Apply internal VLA antenna gain curve correction', 00451 'opacity': 'Opacity correction to apply (nepers), per spw', 00452 'parang': 'Apply parallactic angle correction', 00453 00454 'async': 'If true the taskname must be started using blcal(...)' 00455 } 00456 00457 # 00458 # Set subfields defaults if needed 00459 # 00460 00461 if(desc.has_key(key)) : 00462 return desc[key] 00463 00464 def itsdefault(self, paramname) : 00465 a = {} 00466 a['vis'] = '' 00467 a['caltable'] = '' 00468 a['field'] = '' 00469 a['spw'] = '' 00470 a['intent'] = '' 00471 a['selectdata'] = True 00472 a['timerange'] = '' 00473 a['uvrange'] = '' 00474 a['antenna'] = '' 00475 a['scan'] = '' 00476 a['observation'] = '' 00477 a['msselect'] = '' 00478 a['solint'] = 'inf' 00479 a['combine'] = 'scan' 00480 a['freqdep'] = False 00481 a['calmode'] = 'ap' 00482 a['solnorm'] = False 00483 a['gaintable'] = [''] 00484 a['gainfield'] = [''] 00485 a['interp'] = [''] 00486 a['spwmap'] = [] 00487 a['gaincurve'] = False 00488 a['opacity'] = [] 00489 a['parang'] = False 00490 00491 if a.has_key(paramname) : 00492 return a[paramname] 00493 blcal_pg = blcal_pg_()