casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
l02d_regression.py
Go to the documentation of this file.
00001 ###############################################
00002 #                                             #
00003 # Regression/Benchmarking Script for L02D     #
00004 #             26 JAN               (U Cam)    #
00005 ###############################################
00006 import time
00007 import os
00008 # Data must be pre-filled
00009 # l.ms, l2.ms
00010 
00011 pathname=os.environ.get('CASAPATH').split()[0]
00012 datapath=pathname+'/data/regression/ATST1/L02D/l*.ms'
00013 
00014 startTime=time.time()
00015 startProc=time.clock()
00016 
00017 print '--Copy MS--'
00018 # Fill - really copy over pristine MS
00019 os.system('rm -rf l.* l2.* all.* l1.* *.ms* *.image *.model *.residual')
00020 copystring='cp -r '+datapath+' .'
00021 os.system(copystring)
00022 clearcal(vis='l.ms')
00023 clearcal(vis='l2.ms')
00024 copytime=time.time()
00025 
00026 print '--Flag data--'
00027 default('tflagdata')
00028 #flagdata(vis='l.ms',
00029 #        timerange=['2002/01/27/05:45:47.0', '2002/01/27/07:00:00.0'],
00030 #        fieldid=-1)
00031 tflagdata(vis='l.ms',
00032          timerange='2002/01/27/05:45:47.0~2002/01/27/07:00:00.0')
00033 flagtime=time.time()
00034 
00035 #
00036 # l1 calibration 
00037 #
00038 print '--Calibration phase/bandpass (3mm)--'
00039 #setjy
00040 default('setjy')
00041 setjy(vis='l.ms',field='0',spw='6',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00042 setjy(vis='l.ms',field='0',spw='14',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00043 setjy(vis='l.ms',field='0',spw='18',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00044 setjy(vis='l.ms',field='0',spw='7',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00045 setjy(vis='l.ms',field='0',spw='15',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00046 setjy(vis='l.ms',field='0',spw='19',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00047 setjy(vis='l.ms',field='0',spw='3',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00048 setjy(vis='l.ms',field='0',spw='11',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00049 setjy(vis='l.ms',field='0',spw='26',scalebychan=False,fluxdensity=[6.0,0,0,0])
00050 setjy(vis='l.ms',field='0',spw='30',scalebychan=False,fluxdensity=[6.0,0,0,0])
00051 setjy(vis='l.ms',field='0',spw='27',scalebychan=False,fluxdensity=[6.0,0,0,0])
00052 setjy(vis='l.ms',field='0',spw='31',scalebychan=False,fluxdensity=[6.0,0,0,0])
00053 
00054 # 3mm USB
00055 #preliminary time-dependent phase solutions to improve coherent average for bandpass solution
00056 default('gaincal')
00057 gaincal(vis='l.ms',caltable='l.3mmUSB.gcal0',
00058         field='0',spw='7,15,19:9~118',
00059         gaintype='GSPLINE',calmode='p',splinetime=10000.,
00060         refant='1',phasewrap=260,
00061         gaincurve=False,opacity=0.0,preavg=0)
00062 
00063 print '--bandpass (3mm)--'
00064 #derive bandpass calibration for 3mm (C34S J=2-1) using USB continuum phase solns
00065 default('bandpass')
00066 bandpass(vis='l.ms',caltable='l.3mmC34S.bpoly',
00067          field='0',spw='3',
00068          bandtype='BPOLY',degamp=2,degphase=2,solnorm=False,
00069          maskcenter=2,maskedge=0,refant='1',
00070          gaintable='l.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00071 
00072 # Band pass for CH3OH,3mm continuum USB/LSB
00073 default('bandpass')
00074 bandpass(vis='l.ms',caltable='l.3mmch3oh.bpoly',
00075          field='0',spw='11',
00076          bandtype='BPOLY',degamp=2,degphase=4,solnorm=False,
00077          maskcenter=2,maskedge=0,refant='1',
00078          gaintable='l.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00079 default('bandpass')
00080 bandpass(vis='l.ms',caltable='l.3mmcont.bpoly',
00081          field='0',spw='7,15,19',
00082          bandtype='BPOLY',degamp=10,degphase=25,solnorm=False,
00083          maskcenter=2,maskedge=0,refant='1',
00084          gaintable='l.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00085 default('bandpass')
00086 bandpass(vis='l.ms',caltable='l.3mmcont.bpoly',
00087          field='0',spw='6,14,18',
00088          bandtype='BPOLY',degamp=10,degphase=25,solnorm=False,
00089          maskcenter=2,maskedge=0,refant='1',
00090          gaintable='l.3mmUSB.gcal0',gaincurve=False,opacity=0.0,append=True)
00091 
00092 print '--gaincal phase (3mm)--'
00093 #derive new and better phase solutions for 3mm LSB
00094 default('gaincal')
00095 gaincal(vis='l.ms',caltable='l.3mmcont.gcal',
00096         field='0,1,2',spw='6,14,18,7,15,19',
00097         gaintype='GSPLINE',calmode='p',splinetime=3000.,refant='1',
00098         phasewrap=260,
00099         gaincurve=False,opacity=0.0,gaintable='l.3mmcont.bpoly',preavg=0.)
00100 
00101 #Apply all solutions derived so far, determine calibrator's flux densities by solving for T 
00102 #and use fluxscale
00103 default('gaincal')
00104 gaincal(vis='l.ms',caltable='l.3mmcont.temp',
00105         field='0,1,2',spw='7,15,19,6,14,18',
00106         solint='600s',refant='1',gaintype='T',
00107         opacity=0.0,gaincurve=False,
00108         gaintable=['l.3mmcont.gcal','l.3mmcont.bpoly'])
00109 
00110 #fluxscale
00111 default('fluxscale')
00112 fluxscale(vis='l.ms',caltable='l.3mmcont.temp',fluxtable='l.3mmcont.flux',
00113           reference='3C273*',transfer='MWC349*,2013+370*')
00114 calphase3mmtime=time.time()
00115 #MWC349 1.14
00116 #2013+370 3.25
00117 
00118 #use old values
00119 print '--Set fluxscale (setjy)--'
00120 default('setjy')
00121 setjy(vis='l.ms',field='1',spw='6',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00122 setjy(vis='l.ms',field='1',spw='7',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00123 setjy(vis='l.ms',field='1',spw='14',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00124 setjy(vis='l.ms',field='1',spw='15',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00125 setjy(vis='l.ms',field='1',spw='18',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00126 setjy(vis='l.ms',field='1',spw='19',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00127 setjy(vis='l.ms',field='2',spw='6',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00128 setjy(vis='l.ms',field='2',spw='7',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00129 setjy(vis='l.ms',field='2',spw='14',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00130 setjy(vis='l.ms',field='2',spw='15',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00131 setjy(vis='l.ms',field='2',spw='18',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00132 setjy(vis='l.ms',field='2',spw='19',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00133 setjy3mmtime=time.time()
00134 
00135 ## Amplitude calibration of 3mm continuum:
00136 ##
00137 ##  phase solutions will be pre-applied as well as carried forward 
00138 ##   to the output solution table.
00139 print '--gaincal amp (3mm)--'
00140 default('gaincal')
00141 gaincal(vis='l.ms',caltable='l.3mmcont.amp.gcal',
00142         field='0,1,2',spw='7,15,19,6,14,18',
00143         gaintype='GSPLINE',calmode='a',splinetime=3000.,refant='1',
00144         phasewrap=260,
00145         gaincurve=False,opacity=0.0,preavg=0.,
00146         gaintable=['l.3mmcont.gcal','l.3mmcont.bpoly'])
00147 calamp3mmtime=time.time()
00148 
00149 ## Correct the target source C34S (J=2-1)
00150 ##
00151 ##  note that only the 60 central channels will be calibrated
00152 ##   since the BPOLY solution is only defined for these
00153 default('applycal')
00154 applycal(vis='l.ms',
00155          field='3',spw='3',
00156          gaincurve=False,opacity=0.0,
00157          gaintable=['l.3mmcont.gcal','l.3mmcont.amp.gcal','l.3mmC34S.bpoly']);
00158 # Correct Target other 3mm line data (CH3OH)
00159 applycal(vis='l.ms',
00160          field='3',spw='11',
00161          gaincurve=False,opacity=0.0,
00162          gaintable=['l.3mmcont.gcal','l.3mmcont.amp.gcal','l.3mmch3oh.bpoly'])
00163 # Correct Target source 3mm continuum 
00164 applycal(vis='l.ms',
00165          field='3',spw='7,15,19,6,14,18',
00166          gaincurve=False,opacity=0.0,
00167          gaintable=['l.3mmcont.gcal','l.3mmcont.amp.gcal','l.3mmcont.bpoly'])
00168 correct3mmtime=time.time()
00169 
00170 # 1mm Calibration
00171 
00172 ###########################################################
00173 ## Get first cut phase solutions to improve S/N for BPass determination:
00174 ## 
00175 default('gaincal')
00176 gaincal(vis='l.ms',caltable='l.1mmUSB.gcal0',
00177         field='0',spw='27,31:9~118',
00178         gaintype='GSPLINE',calmode='p',splinetime=7000.,refant='1',
00179         phasewrap=260,preavg=0.,gaincurve=False,opacity=0.0)
00180 
00181 ## Derive bandpass calibration for 1mm 
00182 ##
00183 bandpass(vis='l.ms',caltable='l.1mmcont.bpoly',
00184          field='0',spw='27,31',
00185          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00186          maskcenter=2,maskedge=0,refant='1',
00187          gaintable='l.1mmUSB.gcal0',gaincurve=False,opacity=0.0)
00188 bandpass(vis='l.ms',caltable='l.1mmcont.bpoly',
00189          field='0',spw='26,30',
00190          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00191          maskcenter=2,maskedge=0,refant='1',
00192          gaintable='l.1mmUSB.gcal0',gaincurve=False,opacity=0.0,append=True)
00193 bandpass(vis='l.ms',caltable='l.1mmUSB.bpoly',
00194          field='0',spw='23',
00195          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00196          maskcenter=2,maskedge=0,refant='1',
00197          gaintable='l.1mmUSB.gcal0',gaincurve=False,opacity=0.0)
00198 
00199 ## Determine phase solutions for 1mm LSB & USB 
00200 ##
00201 print '--Phase solutions--'
00202 default('gaincal')
00203 gaincal(vis='l.ms',caltable='l.1mmcont.gcal',
00204         field='0,1,2',spw='26,27,30,31',
00205         gaintype='GSPLINE',calmode='p',splinetime=3000.,refant='1',
00206         phasewrap=260,
00207         gaincurve=False,opacity=0.0,gaintable='l.1mmcont.bpoly',preavg=0.)
00208 
00209 ##  Apply all solutions derived so far, determine
00210 ##  calibrators' flux densities using a solve for T and
00211 ##  fluxscale
00212 print '--Solve for solutions, fluxscale--'
00213 default('gaincal')
00214 gaincal(vis='l.ms',caltable='l.1mmcont.temp',
00215         field='0,1,2',spw='26,27,30,31',
00216         solint='1200s',refant='1',gaintype='T',
00217         opacity=0.0,gaincurve=False,
00218         gaintable=['l.1mmcont.gcal','l.1mmcont.bpoly'])
00219 #
00220 default('fluxscale')
00221 fluxscale(vis='l.ms',caltable='l.1mmcont.temp',fluxtable='l.1mmcont.flux',
00222           reference='3C273*',transfer='MWC349*,2013+370*')
00223 #MWC349   2.7   1.74
00224 #2013+370 3.8   2.44
00225 calphase1mmtime=time.time()
00226 
00227 ## Record flux values from logger window.  Manually insert
00228 ## fluxes with imgr.setjy:
00229 print '--Setjy 1mm --'
00230 setjy(vis='l.ms',field='1',spw='27',scalebychan=False,fluxdensity=[1.7,0.,0.,0.])
00231 setjy(vis='l.ms',field='1',spw='31',scalebychan=False,fluxdensity=[1.7,0.,0.,0.])
00232 setjy(vis='l.ms',field='2',spw='27',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00233 setjy(vis='l.ms',field='2',spw='31',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00234 setjy(vis='l.ms',field='1',spw='27',scalebychan=False,fluxdensity=[1.7,0.,0.,0.])
00235 setjy(vis='l.ms',field='1',spw='31',scalebychan=False,fluxdensity=[1.7,0.,0.,0.])
00236 setjy(vis='l.ms',field='2',spw='27',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00237 setjy(vis='l.ms',field='2',spw='31',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00238 setjy1mmtime=time.time()
00239 
00240 
00241 ## Amplitude calibration of 1mm LSB:
00242 default('gaincal')
00243 gaincal(vis='l.ms',caltable='l.1mmcont.amp.gcal',
00244         field='0,1,2',spw='26,27,30,31',
00245         gaintype='GSPLINE',calmode='a',splinetime=3000.,refant='1',
00246         phasewrap=260,
00247         gaincurve=False,opacity=0.0,
00248         preavg=0.,
00249         gaintable=['l.1mmcont.gcal','l.1mmcont.bpoly'])
00250 calamp1mmtime=time.time()
00251 
00252 ## Correct the target source 1mm LSB & USB continuum data:
00253 ##
00254 ##  Note that edge channels in won't be calibrated because
00255 ##   BPOLY solution is not defined for them
00256 default('applycal')
00257 applycal(vis='l.ms',
00258          field='3',spw='26,27,30,31',
00259          gaincurve=False,opacity=0.0,
00260          gaintable=['l.1mmcont.gcal','l.1mmcont.amp.gcal','l.1mmcont.bpoly'])
00261 default('applycal')
00262 applycal(vis='l.ms',
00263          field='3',spw='23',
00264          gaincurve=False,opacity=0.0,
00265          gaintable=['l.1mmcont.gcal','l.1mmcont.amp.gcal','l.1mmcont.bpoly'],
00266          spwmap=[[-1],[-1],[26]])
00267 correct1mmtime=time.time()
00268 
00269 ## Split out calibrated target source 1 mm continuum data:
00270 default('split')
00271 split(vis='l.ms',outputvis='l.1mm.split.ms',
00272       field='3',spw='26:8~117,27:8~117,30:8~117,31:8~117',
00273       datacolumn='corrected')
00274 default('split')
00275 split(vis='l.ms',outputvis='l.1mmc34s5_4.split.ms',
00276       field='3',spw='23:0~511',
00277       datacolumn='corrected')
00278 splitsrc1mmtime=time.time()
00279 
00280 print '--Image 1mm continuum--'
00281 ## Get a first image the target source in 1 mm continuum emission:
00282 default('clean')
00283 clean(vis='l.1mm.split.ms',imagename='l.1mm',
00284       psfmode='clark',imagermode='',niter=100,gain=0.1,nchan=1,start=0,width=1,
00285       spw='0~3',field='0',stokes='I',interpolation='nearest',
00286       weighting='natural',
00287       cell=[0.2,0.2],imsize=[128,128],mode='mfs')
00288 image1mmtime=time.time()
00289 
00290 print '--Resplit data--'
00291 default('split')
00292 split(vis='l.ms',outputvis='l1.c34s.split.ms',
00293       field='3',spw='3:0~511',datacolumn='corrected')
00294 default('split')
00295 split(vis='l.ms',outputvis='l1.ch3oh.split.ms',
00296       field='3',spw='11:0~511',datacolumn='corrected')
00297 default('split')
00298 split(vis='l.ms',outputvis='l1.3mmcont.split.ms',
00299       field='3',
00300       spw='6:9~108,7:9~108,14:9~108,15:9~108,18:9~108,19:9~108',
00301       width=[100,100,100,100,100,100],
00302       datacolumn='corrected')
00303 default('split')
00304 split(vis='l.ms',outputvis='l1.1mmcont.split.ms',
00305       field='3',
00306       spw='26:9~118,27:9~118,30:9~118,31:9~118',
00307       width=[110,110,110,110],
00308       datacolumn='corrected')
00309 default('split')
00310 split(vis='l.ms',outputvis='l1.1mmc34s5_4.split.ms',
00311       field='3',spw='23:0~511',datacolumn='corrected')
00312 splitsrc1mmtime=time.time()
00313 
00314 
00315 
00316 ###############################################
00317 #                                             #
00318 # Regression/Benchmarking Script for L02D     #
00319 #            29 JAN                (U Cam)    #
00320 ###############################################
00321 
00322 print '--Flag data--'
00323 default('tflagdata')
00324 #flagdata(vis='l2.ms',
00325 #        timerange=['2002/01/29/03:37:50.0', '2002/01/29/04:02:48.0'],
00326 #        fieldid=-1)
00327 tflagdata(vis='l2.ms',
00328          timerange='2002/01/29/03:37:50.0~2002/01/29/04:02:48.0')
00329 flagtime=time.time()
00330 
00331 #
00332 # l2 calibration 
00333 #
00334 print '--Calibration phase/bandpass (3mm)--'
00335 #setjy
00336 default('setjy')
00337 setjy(vis='l2.ms',field='0',spw='6',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00338 setjy(vis='l2.ms',field='0',spw='14',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00339 setjy(vis='l2.ms',field='0',spw='18',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00340 setjy(vis='l2.ms',field='0',spw='7',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00341 setjy(vis='l2.ms',field='0',spw='15',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00342 setjy(vis='l2.ms',field='0',spw='19',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00343 setjy(vis='l2.ms',field='0',spw='3',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00344 setjy(vis='l2.ms',field='0',spw='11',scalebychan=False,fluxdensity=[10.87,0.,0.,0.])
00345 setjy(vis='l2.ms',field='0',spw='26',scalebychan=False,fluxdensity=[6.0,0,0,0])
00346 setjy(vis='l2.ms',field='0',spw='30',scalebychan=False,fluxdensity=[6.0,0,0,0])
00347 setjy(vis='l2.ms',field='0',spw='27',scalebychan=False,fluxdensity=[6.0,0,0,0])
00348 setjy(vis='l2.ms',field='0',spw='31',scalebychan=False,fluxdensity=[6.0,0,0,0])
00349 
00350 # 3mm USB
00351 #preliminary time-dependent phase solutions to improve coherent average for bandpass solution
00352 default('gaincal')
00353 gaincal(vis='l2.ms',caltable='l2.3mmUSB.gcal0',
00354         field='0',spw='7,15,19:9~118',
00355         gaintype='GSPLINE',calmode='p',splinetime=10000.,refant='1',
00356         phasewrap=260,
00357         gaincurve=False,opacity=0.0,preavg=0)
00358 
00359 print '--bandpass (3mm)--'
00360 #derive bandpass calibration for 3mm (C34S J=2-1) using USB continuum phase solns
00361 default('bandpass')
00362 bandpass(vis='l2.ms',caltable='l2.3mmC34S.bpoly',
00363          field='0',spw='3',
00364          bandtype='BPOLY',degamp=2,degphase=2,solnorm=False,
00365          maskcenter=2,maskedge=0,refant='1',
00366          gaintable='l2.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00367 
00368 # Band pass for CH3OH,3mm continuum USB/LSB
00369 default('bandpass')
00370 bandpass(vis='l2.ms',caltable='l2.3mmch3oh.bpoly',
00371          field='0',spw='11',
00372          bandtype='BPOLY',degamp=10,degphase=20,solnorm=False,
00373          maskcenter=2,maskedge=0,refant='1',
00374          gaintable='l2.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00375 default('bandpass')
00376 bandpass(vis='l2.ms',caltable='l2.3mmcont.bpoly',
00377          field='0',spw='7,15,19',
00378          bandtype='BPOLY',degamp=10,degphase=25,solnorm=False,
00379          maskcenter=2,maskedge=0,refant='1',
00380          gaintable='l2.3mmUSB.gcal0',gaincurve=False,opacity=0.0)
00381 default('bandpass')
00382 bandpass(vis='l2.ms',caltable='l2.3mmcont.bpoly',
00383          field='0',spw='6,14,18',
00384          bandtype='BPOLY',degamp=10,degphase=25,solnorm=False,
00385          maskcenter=2,maskedge=0,refant='1',
00386          gaintable='l2.3mmUSB.gcal0',gaincurve=False,opacity=0.0,append=True)
00387 
00388 print '--gaincal phase (3mm)--'
00389 #derive new and better phase solutions for 3mm LSB
00390 default('gaincal')
00391 gaincal(vis='l2.ms',caltable='l2.3mmcont.gcal',
00392         field='0,1,2',spw='6,14,18,7,15,19',
00393         gaintype='GSPLINE',calmode='p',splinetime=10000.,refant='1',
00394         phasewrap=260,
00395         gaincurve=False,opacity=0.0,gaintable='l2.3mmcont.bpoly',preavg=0.)
00396 
00397 #Apply all solutions derived so far, determine calibrator's flux densities by solving for T 
00398 #and use fluxscale
00399 default('gaincal')
00400 gaincal(vis='l2.ms',caltable='l2.3mmcont.temp',
00401         field='0,1,2',spw='7,15,19,6,14,18',
00402         solint='600s',refant='1',gaintype='T',opacity=0.0,
00403         gaincurve=False,
00404         gaintable=['l2.3mmcont.gcal','l2.3mmcont.bpoly'])
00405 
00406 #fluxscale
00407 default('fluxscale')
00408 fluxscale(vis='l2.ms',caltable='l2.3mmcont.temp',fluxtable='l2.3mmcont.flux',
00409           reference='3C273*',transfer='MWC349*,2013+370*')
00410 calphase3mmtime=time.time()
00411 #MWC249 = 0.82 Jy
00412 #2013+370 = 2.60 Jy
00413 
00414 print '--Set fluxscale (setjy)--'
00415 default('setjy')
00416 setjy(vis='l2.ms',field='1',spw='6',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00417 setjy(vis='l2.ms',field='1',spw='7',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00418 setjy(vis='l2.ms',field='1',spw='14',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00419 setjy(vis='l2.ms',field='1',spw='15',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00420 setjy(vis='l2.ms',field='1',spw='18',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00421 setjy(vis='l2.ms',field='1',spw='19',scalebychan=False,fluxdensity=[1.01,0.,0.,0.])
00422 setjy(vis='l2.ms',field='2',spw='6',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00423 setjy(vis='l2.ms',field='2',spw='7',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00424 setjy(vis='l2.ms',field='2',spw='14',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00425 setjy(vis='l2.ms',field='2',spw='15',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00426 setjy(vis='l2.ms',field='2',spw='18',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00427 setjy(vis='l2.ms',field='2',spw='19',scalebychan=False,fluxdensity=[2.79,0.,0.,0.])
00428 setjy3mmtime=time.time()
00429 
00430 ## Amplitude calibration of 3mm continuum:
00431 ##
00432 ##  phase solutions will be pre-applied as well as carried forward 
00433 ##   to the output solution table.
00434 print '--gaincal amp (3mm)--'
00435 default('gaincal')
00436 gaincal(vis='l2.ms',caltable='l2.3mmcont.amp.gcal',
00437         field='0,1,2',spw='7,15,19,6,14,18',
00438         gaintype='GSPLINE',calmode='a',splinetime=10000.,
00439         refant='1',phasewrap=260,
00440         gaincurve=False,opacity=0.0,
00441         preavg=0.,
00442         gaintable=['l2.3mmcont.gcal','l2.3mmcont.bpoly'])
00443 calamp3mmtime=time.time()
00444 
00445 ## Correct the target source C34S (J=2-1)
00446 ##
00447 ##  note that only the 60 central channels will be calibrated
00448 ##   since the BPOLY solution is only defined for these
00449 default('applycal')
00450 applycal(vis='l2.ms',
00451          field='3',spw='3',
00452          gaincurve=False,opacity=0.0,
00453          gaintable=['l2.3mmcont.gcal','l2.3mmcont.amp.gcal','l2.3mmC34S.bpoly'])
00454 # Correct Target other 3mm line data (CH3OH)
00455 default('applycal')
00456 applycal(vis='l2.ms',
00457          field='3',spw='11',
00458          gaincurve=False,opacity=0.0,
00459          gaintable=['l2.3mmcont.gcal','l2.3mmcont.amp.gcal','l2.3mmch3oh.bpoly'])
00460 # Correct Target source 3mm continuum 
00461 default('applycal')
00462 applycal(vis='l2.ms',
00463          field='3',spw='7,15,19,6,14,18',
00464          gaincurve=False,opacity=0.0,
00465          gaintable=['l2.3mmcont.gcal','l2.3mmcont.amp.gcal','l2.3mmcont.bpoly'])
00466 correct3mmtime=time.time()
00467 
00468 # Split calibrated data
00469 print '--split calibrater--'
00470 default('split')
00471 split(vis='l2.ms',outputvis='l2.3mmconta.split.ms',
00472       field='3',
00473       spw='6:10~109,7:10~109,14:10~109,15:10~109,18:10~109,19:10~109',
00474       width=[100,100,100,100,100,100],
00475       datacolumn='corrected')
00476 splitsrctime=time.time()
00477 
00478 #Image target source in 3mm continuum emission
00479 default('clean')
00480 clean(vis='l2.3mmconta.split.ms',imagename='l2.3mmcont',
00481       psfmode='clark',imagermode='',niter=100,gain=0.1,nchan=1,start=0,width=1,
00482       spw='0~5',field='0',stokes='I',
00483       weighting='natural',interpolation='nearest',
00484       cell=[0.4,0.4],imsize=[256,256],mode='mfs')
00485 
00486 
00487 # 1mm Calibration
00488 
00489 ###########################################################
00490 ## Get first cut phase solutions to improve S/N for BPass determination:
00491 ## 
00492 default('gaincal')
00493 gaincal(vis='l2.ms',caltable='l2.1mmUSB.gcal0',
00494         field='0',spw='27,31:9~118',
00495         gaintype='GSPLINE',calmode='p',splinetime=10000.,
00496         refant='1',phasewrap=260,preavg=0.,
00497         gaincurve=False,opacity=0.0)
00498 
00499 ## Derive bandpass calibration for 1mm 
00500 ##
00501 default('bandpass')
00502 bandpass(vis='l2.ms',caltable='l2.1mmcont.bpoly',
00503          field='0',spw='27,31',
00504          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00505          maskcenter=2,maskedge=0,refant='1',
00506          gaintable='l2.1mmUSB.gcal0',gaincurve=False,opacity=0.0)
00507 default('bandpass')
00508 bandpass(vis='l2.ms',caltable='l2.1mmcont.bpoly',
00509          field='0',spw='26,30',
00510          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00511          maskcenter=2,maskedge=0,refant='1',gaintable='l2.1mmUSB.gcal0',gaincurve=False,opacity=0.0,append=True)
00512 default('bandpass')
00513 bandpass(vis='l2.ms',caltable='l2.1mmUSB.bpoly',
00514          field='0',spw='23',
00515          bandtype='BPOLY',degamp=10,degphase=20,visnorm=False,solnorm=False,
00516          maskcenter=2,maskedge=0,refant='1',
00517          gaintable='l2.1mmUSB.gcal0',gaincurve=False,opacity=0.0)
00518 
00519 ## Determine phase solutions for 1mm LSB & USB 
00520 ##
00521 print '--Phase solutions--'
00522 default('gaincal')
00523 gaincal(vis='l2.ms',caltable='l2.1mmcont.gcal',
00524         field='0,1,2',spw='26,27,30,31',
00525         gaintype='GSPLINE',calmode='p',splinetime=10000.,refant='1',
00526         phasewrap=260,
00527         gaincurve=False,opacity=0.0,gaintable='l2.1mmcont.bpoly',preavg=0.)
00528 
00529 ##  Apply all solutions derived so far, determine
00530 ##  calibrators' flux densities using a solve for T and
00531 ##  fluxscale
00532 print '--Solve for solutions, fluxscale--'
00533 default('gaincal')
00534 gaincal(vis='l2.ms',caltable='l2.1mmcont.temp',
00535         field='0,1,2',spw='26,27,30,31',
00536         solint='1200s',refant='1',gaintype='T',
00537         opacity=0.0,gaincurve=False,
00538         gaintable=['l2.1mmcont.gcal','l2.1mmcont.bpoly'])
00539 #
00540 default('fluxscale')
00541 fluxscale(vis='l2.ms',caltable='l2.1mmcont.temp',fluxtable='l2.1mmcont.flux',
00542           reference='3C273*',transfer='MWC349*,2013+370*')
00543 calphase1mmtime=time.time()
00544 # MWC349:   0.8x (AIPS++ 0.75)
00545 # 2013+370: 1.3  (AIPS++: 1.3)
00546 
00547 ## Record flux values from logger window.  Manually insert
00548 ## fluxes with imgr.setjy:
00549 print '--Setjy 1mm --'
00550 setjy(vis='l2.ms',field='1',spw='27',scalebychan=False,fluxdensity=[1.75,0.,0.,0.])
00551 setjy(vis='l2.ms',field='1',spw='31',scalebychan=False,fluxdensity=[1.75,0.,0.,0.])
00552 setjy(vis='l2.ms',field='2',spw='27',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00553 setjy(vis='l2.ms',field='2',spw='31',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00554 setjy(vis='l2.ms',field='1',spw='26',scalebychan=False,fluxdensity=[1.75,0.,0.,0.])
00555 setjy(vis='l2.ms',field='1',spw='30',scalebychan=False,fluxdensity=[1.75,0.,0.,0.])
00556 setjy(vis='l2.ms',field='2',spw='26',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00557 setjy(vis='l2.ms',field='2',spw='30',scalebychan=False,fluxdensity=[1.8,0.,0.,0.])
00558 setjy1mmtime=time.time()
00559 
00560 
00561 ## Amplitude calibration of 1mm LSB:
00562 default('gaincal')
00563 gaincal(vis='l2.ms',caltable='l2.1mmcont.amp.gcal',
00564         field='0,1,2',spw='26,27,30,31',
00565         gaintype='GSPLINE',calmode='a',splinetime=10000.,refant='1',
00566         phasewrap=260,
00567         gaincurve=False,opacity=0.0,
00568         preavg=0.,
00569         gaintable=['l2.1mmcont.gcal','l2.1mmcont.bpoly'])
00570 calamp1mmtime=time.time()
00571 
00572 ## Correct the target source 1mm LSB & USB continuum data:
00573 ##
00574 ##  Note that edge channels in won't be calibrated because
00575 ##   BPOLY solution is not defined for them
00576 default('applycal')
00577 applycal(vis='l2.ms',
00578          field='3',spw='26,27,30,31',
00579          gaincurve=False,opacity=0.0,
00580          gaintable=['l2.1mmcont.gcal','l2.1mmcont.amp.gcal','l2.1mmcont.bpoly'])
00581 default('applycal')
00582 applycal(vis='l2.ms',
00583          field='3',spw='23',
00584          gaincurve=False,opacity=0.0,
00585          gaintable=['l2.1mmcont.gcal','l2.1mmcont.amp.gcal','l2.1mmcont.bpoly'],
00586          spwmap=[[-1],[-1],[26]])
00587 correct1mmtime=time.time()
00588 
00589 ## Split out calibrated target source 1 mm continuum data:
00590 default('split')
00591 split(vis='l2.ms',outputvis='l2.1mma.split.ms',
00592       field='3',spw='26:8~117,27:8~117,30:8~117,31:8~117',
00593       datacolumn='corrected')
00594 default('split')
00595 splitsrc1mmtime=time.time()
00596 
00597 print '--Image 1mm continuum--'
00598 ## Get a first image the target source in 1 mm continuum emission:
00599 default('clean')
00600 clean(vis='l2.1mma.split.ms',imagename='l2.1mm',
00601       psfmode='clark',imagermode='',niter=100,gain=0.1,nchan=1,start=0,width=1,
00602       spw='0~3',field='0',stokes='I',
00603       weighting='natural',interpolation='nearest',
00604       cell=[0.2,0.2],imsize=[128,128],mode='mfs')
00605 image1mmtime=time.time()
00606 
00607 print '--Resplit data--'
00608 default('split')
00609 split(vis='l2.ms',outputvis='l2.c34s.split.ms',
00610       field='3',spw='3:0~511',datacolumn='corrected')
00611 default('split')
00612 split(vis='l2.ms',outputvis='l2.ch3oh.split.ms',
00613       field='3',spw='11:0~511',datacolumn='corrected')
00614 default('split')
00615 split(vis='l2.ms',outputvis='l2.3mmcont.split.ms',
00616       field='3',
00617       spw='6:9~108,7:9~108,14:9~108,15:9~108,18:9~108,19:9~108',
00618       width=[100,100,100,100,100,100],
00619       datacolumn='corrected')
00620 default('split')
00621 split(vis='l2.ms',outputvis='l2.1mmcont.split.ms',
00622       field='3',
00623       spw='26:9~118,27:9~118,30:9~118,31:9~118',
00624       width=[110,110,110,110],
00625       datacolumn='corrected')
00626 default('split')
00627 split(vis='l2.ms',outputvis='l2.1mmc34s5_4.split.ms',
00628       field='3',spw='23:0~511',datacolumn='corrected')
00629 splitsrc1mmtime=time.time()
00630 
00631 ### COMBINE DATA SETS
00632 
00633 print '--Concatenate the data sets--'
00634 os.system('cp -r l1.3mmcont.split.ms l02d.3mmcont.split.ms')
00635 os.system('cp -r l1.c34s.split.ms l02d.c34s.split.ms')
00636 os.system('cp -r l1.ch3oh.split.ms l02d.ch3oh.split.ms')
00637 os.system('cp -r l1.1mmcont.split.ms l02d.1mmcont.split.ms')
00638 default('concat')
00639 concat(concatvis='l02d.3mmcont.split.ms',vis='l2.3mmcont.split.ms',
00640        freqtol='10MHz',dirtol='0.1arcsec')
00641 concat(concatvis='l02d.1mmcont.split.ms',vis='l2.1mmcont.split.ms',
00642        freqtol='10MHz',dirtol='0.1arcsec')
00643 concat(concatvis='l02d.c34s.split.ms',vis='l2.c34s.split.ms',
00644        freqtol='10MHz',dirtol='0.1arcsec')
00645 concat(concatvis='l02d.ch3oh.split.ms',vis='l2.ch3oh.split.ms',
00646        freqtol='10MHz',dirtol='0.1arcsec')
00647 
00648 #image target source in 3mm continuum emission
00649 default('clean')
00650 clean(vis='l02d.3mmcont.split.ms',imagename='l02d.3mmcont',
00651       psfmode='clark',imagermode='',niter=1000,gain=0.1,nchan=1,start=0,width=1,
00652       spw='0~5',field='0',stokes='I',
00653       weighting='natural',interpolation='nearest',
00654       cell=[0.6,0.6],imsize=[128,128],mode='mfs',threshold=0.7)
00655 
00656 #image target source in 1mm continuum emission
00657 default('clean')
00658 clean(vis='l02d.1mmcont.split.ms',imagename='l02d.1mmcont',
00659       psfmode='clark',imagermode='',niter=1000,gain=0.1,nchan=1,start=0,width=1,
00660       spw='0~3',field='0',stokes='I',
00661       weighting='natural',interpolation='nearest',
00662       cell=[0.2,0.2],imsize=[128,128],mode='mfs',threshold=4.)
00663 
00664 #image target source in 3mm c34s (2-1) line
00665 default('clean')
00666 clean(vis='l02d.c34s.split.ms',imagename='l02d.c34s',
00667       psfmode='clark',imagermode='',niter=1000,gain=0.1,nchan=160,start=20,width=3,
00668       spw='0',field='0',stokes='I',
00669       weighting='natural',interpolation='nearest',
00670       cell=[0.6,0.6],imsize=[128,128],mode='channel',threshold=25.)
00671 
00672 #image target source in 3mm ch3oh 
00673 default('clean')
00674 clean(vis='l02d.ch3oh.split.ms',imagename='l02d.ch3oh',
00675       psfmode='clark',imagermode='',niter=1000,gain=0.1,nchan=160,start=20,width=3,
00676       spw='0',field='0',stokes='I',
00677       weighting='natural',interpolation='nearest',
00678       cell=[0.6,0.6],imsize=[128,128],mode='channel',threshold=18.)
00679 
00680 endProc=time.clock()
00681 endTime=time.time()
00682 
00683 # Regression
00684 
00685 ms.open('l02d.1mmcont.split.ms')
00686 thistest_1mm=max(ms.range(['amplitude']).get('amplitude'))
00687 ms.close()
00688 ms.open('l02d.3mmcont.split.ms')
00689 thistest_3mm=max(ms.range(['amplitude']).get('amplitude'))
00690 ms.close()
00691 ms.open('l02d.ch3oh.split.ms')
00692 thistest_ch3oh=max(ms.range(['amplitude']).get('amplitude'))
00693 ms.close()
00694 ms.open('l02d.c34s.split.ms')
00695 thistest_c34s=max(ms.range(['amplitude']).get('amplitude'))
00696 ms.close()
00697 ia.open('l02d.3mmcont.image')
00698 statistics=ia.statistics()
00699 cont3mmmax=statistics['max'][0]
00700 cont3mmrms=statistics['rms'][0]
00701 ia.close()
00702 ia.open('l02d.1mmcont.image')
00703 statistics=ia.statistics()
00704 cont1mmmax=statistics['max'][0]
00705 cont1mmrms=statistics['rms'][0]
00706 ia.close()
00707 ia.open('l02d.c34s.image')
00708 statistics=ia.statistics()
00709 c34smax=statistics['max'][0]
00710 c34srms=statistics['rms'][0]
00711 ia.close()
00712 ia.open('l02d.ch3oh.image')
00713 statistics=ia.statistics()
00714 ch3ohmax=statistics['max'][0]
00715 ch3ohrms=statistics['rms'][0]
00716 ia.close()
00717 
00718 # new test values following fix to data weights
00719 #  fed to BPOLY solution (2012/04/18 gmoellen)
00720 src3mm=0.4210
00721 src1mm=2.4906
00722 srcch3oh=405.2
00723 srcc34s=309.9
00724 im3mm=0.0238
00725 im1mm=0.2170
00726 imch3oh=0.403
00727 imc34s=0.168
00728 
00729 
00730 diff_3mm=abs((src3mm-thistest_3mm)/src3mm)
00731 diff_1mm=abs((src1mm-thistest_1mm)/src1mm)
00732 diff_ch3oh=abs((srcch3oh-thistest_ch3oh)/srcch3oh)
00733 diff_c34s=abs((srcc34s-thistest_c34s)/srcc34s)
00734 diff_im3mm=abs((im3mm-cont3mmmax)/im3mm)
00735 diff_im1mm=abs((im1mm-cont1mmmax)/im1mm)
00736 diff_imch3oh=abs((imch3oh-ch3ohmax)/imch3oh)
00737 diff_imc34s=abs((imc34s-c34smax)/imc34s)
00738 
00739 import datetime
00740 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00741 outfile='l02d.'+datestring+'.log'
00742 logfile=open(outfile,'w')
00743 
00744 print >>logfile,'********** Regression ***********'
00745 print >>logfile,'*                               *'
00746 if (diff_3mm<0.05): print >>logfile,'* Passed 3mm max amplitude test: '
00747 print >>logfile,'--3mm max amp '+str(thistest_3mm)+'  ('+str(src3mm)+', '+str(100*diff_3mm)+'%)'
00748 if (diff_1mm<0.05): print >>logfile,'* Passed 1mm max amplitude test '
00749 print >>logfile,'--1mm max amp '+str(thistest_1mm)+'  ('+str(src1mm)+', '+str(100*diff_1mm)+'%)'
00750 if (diff_ch3oh<0.05): print >>logfile,'* Passed CH3OH max amplitude test '
00751 print >>logfile,'--CH3OH max amp '+str(thistest_ch3oh)+'  ('+str(srcch3oh)+', '+str(100*diff_ch3oh)+'%)'
00752 if (diff_c34s<0.05): print >>logfile,'* Passed C34S max amplitude test '
00753 print >>logfile,'--C34S max amp '+str(thistest_c34s)+'  ('+str(srcc34s)+', '+str(100*diff_c34s)+'%)'
00754 if (diff_im3mm<0.05): print >>logfile,'* Passed image (3mm) max test'
00755 print >>logfile,'--Image max (3mm) '+str(cont3mmmax)+'  ('+str(im3mm)+', '+str(100*diff_im3mm)+'%)'
00756 if (diff_im1mm<0.05): print >>logfile,'* Passed image (1mm) max test'
00757 print >>logfile,'--Image max (1mm) '+str(cont1mmmax)+'  ('+str(im1mm)+', '+str(100*diff_im1mm)+'%)'
00758 if (diff_imch3oh<0.05): print >>logfile,'* Passed image (ch3oh) max test'
00759 print >>logfile,'--Image max (CH3OH) '+str(ch3ohmax)+'  ('+str(imch3oh)+', '+str(100*diff_imch3oh)+'%)'
00760 if (diff_imc34s<0.05): print >>logfile,'* Passed image (c34s) max test'
00761 print >>logfile,'--Image max (C34S) '+str(c34smax)+'  ('+str(imc34s)+', '+str(100*diff_imc34s)+'%)'
00762 
00763 
00764 if ((diff_3mm<0.05) & (diff_1mm<0.05) & (diff_ch3oh<0.05) & (diff_ch3oh<0.05) & (diff_im1mm<0.05) & (diff_im3mm<0.05) & (diff_imch3oh < 0.05) & (diff_imc34s<0.05)):
00765         regstate=True
00766         print >>logfile,'---'
00767         print >>logfile,'Passed Regression test for L02D'
00768         print >>logfile,'---'
00769         print ''
00770         print 'Regression PASSED'
00771         print ''
00772 else:
00773         regstate=False
00774         print >>logfile,'----FAILED Regression test for L02D'
00775         print ''
00776         print 'Regression FAILED'
00777         print ''
00778 
00779 print >>logfile,'*********************************'
00780 
00781 print >>logfile,''
00782 print >>logfile,''
00783 print >>logfile,'********* Benchmarking *****************'
00784 print >>logfile,'*                                      *'
00785 print >>logfile,'Total wall clock time was: '+str(endTime - startTime)
00786 print >>logfile,'Total CPU        time was: '+str(endProc - startProc)
00787 print >>logfile,'Processing rate MB/s  was: '+str(278./(endTime - startTime))
00788 #print >>logfile,'* Breakdown:                           *'
00789 #print >>logfile,'*   copy         time was: '+str(copytime-startTime)
00790 #print >>logfile,'*   flag         time was: '+str(flagtime-copytime)
00791 #print >>logfile,'*   cal ph 3mm   time was: '+str(calphase3mmtime-flagtime)
00792 #print >>logfile,'*   setjy 3mm    time was: '+str(setjy3mmtime-calphase3mmtime)
00793 #print >>logfile,'*   cal amp 3mm  time was: '+str(calamp3mmtime-setjy3mmtime)
00794 #print >>logfile,'*   correct 3mm  time was: '+str(correct3mmtime-calamp3mmtime)
00795 #print >>logfile,'*   split cal    time was: '+str(splitcaltime-correct3mmtime)
00796 #print >>logfile,'*   split src    time was: '+str(splitsrctime-splitcaltime)
00797 #print >>logfile,'*   image src    time was: '+str(image3mmtime-splitsrctime)
00798 #print >>logfile,'*   cal ph 1mm   time was: '+str(calphase1mmtime-image3mmtime)
00799 #print >>logfile,'*   setjy 1mm    time was: '+str(setjy1mmtime-calphase1mmtime)
00800 #print >>logfile,'*   cal amp 1mm  time was: '+str(calamp1mmtime-setjy1mmtime)
00801 #print >>logfile,'*   correct 1mm  time was: '+str(correct1mmtime-calamp1mmtime)
00802 #print >>logfile,'*   splitsrc 1mm time was: '+str(splitsrc1mmtime-correct1mmtime)
00803 #print >>logfile,'*   image 1mm    time was: '+str(image1mmtime-splitsrc1mmtime)
00804 #print >>logfile,'*   HCO cal      time was: '+str(hcocaltime-image1mmtime)
00805 #print >>logfile,'*   image HCO    time was: '+str(imagehcotime-hcocaltime)
00806 #print >>logfile,'*   CO cal       time was: '+str(cocaltime-imagehcotime)
00807 #print >>logfile,'*   image CO     time was: '+str(imagecotime-cocaltime)
00808 
00809 logfile.close()