00001
00002
00003
00004 import time
00005 import os
00006 from regressframe import regressionframe
00007
00008 class regressverify :
00009
00010
00011
00012
00013 if os.path.exists('/opt/casa/data'):
00014 datarepos = '/opt/casa/data'
00015 elif os.path.exists('/home/casa/data'):
00016 datarepos = '/home/casa/data'
00017 elif os.path.exists(os.environ['CASAPATH'].split()[0] + "/data"):
00018 datarepos = os.environ['CASAPATH'].split()[0] + "/data"
00019 else:
00020 raise Exception('cannot find data repository')
00021
00022 def fill(self) :
00023 rstat = True
00024 print "Starting fill verification"
00025 ms.open('ngc5921.ms')
00026 if(ms.nrow() != 22653) :
00027 rstat = False
00028 print 'ms.nrow failed: got ',ms.nrow, ' expected 22653'
00029 suminfo = ms.summary()
00030 if suminfo['nfields'] != 3 :
00031 rstat = False
00032 print 'nfields failed got '+suminfo['nfields']+' expected 3'
00033 if suminfo['field_0']['name'] != '1331+30500002_0' :
00034 rstat = False
00035 print 'nfield_0 failed got '+suminfo['field_0']['name']
00036 if suminfo['field_1']['name'] != '1445+09900002_0' :
00037 rstat = False
00038 print 'nfield_1 failed got '+suminfo['field_1']['name']
00039 if suminfo['field_2']['name'] != 'N5921_2' :
00040 rstat = False
00041 print 'nfield_2 failed got '+suminfo['field_2']['name']
00042 if suminfo['timeref'] != 'TAI' :
00043 rstat = False
00044 print 'timeref failed got '+suminfo['timeref']
00045 ms.close()
00046 return rstat
00047 def flag(self) :
00048 rstat = True
00049 print "Starting flagging verification"
00050 flagsummary = tflagdata('ngc5921.ms',mode='summary')
00051 if(flagsummary['flagged'] != 203994) :
00052 rstat = false
00053 print 'flagged failed got ', flagsummary['flagged'], ' expected 203994'
00054 if(flagsummary['total'] != 2854278) :
00055 rstat = false
00056 print 'flagged failed got ', flagsummary['flagged'], ' expected 2854278'
00057 return rstat
00058 def calibrate(self) :
00059 import listing
00060 rstat = True
00061 print "Starting calibrate verification"
00062
00063
00064 listcalOut = 'ngc5921.listcal.out'
00065 os.system('mv ' + listcalOut + ' ' + listcalOut + '.tmp')
00066 os.system('tail -n +2 ' + listcalOut + '.tmp > ' + listcalOut)
00067 os.system('rm -f ' + listcalOut + '.tmp')
00068
00069
00070 print "Comparing listcal output with standard..."
00071 standardOut = self.datarepos+'/regression/ngc5921/listcal.default.out'
00072
00073
00074 if (not listing.diffMetadata(listcalOut,standardOut,prefix="ngc5921.listcal")):
00075 rstat = False
00076 print "failed calibrate meta data comparison"
00077
00078
00079 precision = '0.003'
00080 if (not listing.diffAmpPhsFloat(listcalOut,standardOut,prefix="ngc5921.listcal",
00081 precision=precision) ):
00082 rstat = False
00083 print "failed calibrate test data comparison"
00084
00085 return rstat
00086 def image(self) :
00087 rstat = True
00088 print "Starting image verification"
00089 cubestats = imstat(imagename='ngc5921.clean.image')
00090 if((cubestats['max'][0] - 0.052414759993553162)/0.052414759993553162 > 0.05) :
00091 print "failed clean image max test"
00092 rstat = False
00093 if((cubestats['rms'][0] - 0.0020218724384903908)/0.0020218724384903908 > 0.05) :
00094 print "failed clean image rms test"
00095 rstat = False
00096 return rstat
00097 def analysis(self) :
00098 rstat = True
00099 print "Starting analysis verification"
00100 momzerostats = imstat(imagename='ngc5921.moments.integrated')
00101 if((momzerostats['max'][0] - 1.48628211)/1.48628211 > 0.05) :
00102 print "failed momzero max test"
00103 rstat =False
00104 momonestats = imstat(imagename='ngc5921.moments.weighted_coord')
00105 if((momonestats['mean'][0] - 1484.22001478)/1484.22001478 > 0.05) :
00106 print "failed momone mean test"
00107 rstat =False
00108 return rstat
00109
00110
00111 pipeline = regressionframe()
00112 verify = regressverify()
00113
00114
00115
00116
00117 if os.path.exists('/opt/casa/data'):
00118 pipeline.datarepos = '/opt/casa/data'
00119 elif os.path.exists('/home/casa/data'):
00120 pipeline.datarepos = '/home/casa/data'
00121 elif os.path.exists(os.environ['CASAPATH'].split()[0] + "/data"):
00122 pipeline.datarepos = os.environ['CASAPATH'].split()[0] + "/data"
00123 else:
00124 raise Exception('cannot find data repository')
00125
00126 pipeline.workdir = './ngc5921_regression'
00127 pipeline.fill['tasks'] = ['importuvfits', 'listobs']
00128 pipeline.fill['importuvfits'] = {}
00129 pipeline.fill['listobs'] = {}
00130 pipeline.fill['importuvfits']['args'] = {'vis':'ngc5921.ms',
00131 'fitsfile':pipeline.datarepos+'/regression/ngc5921/ngc5921.fits',
00132 'antnamescheme':'new'
00133 }
00134 pipeline.fill['listobs']['args'] = {'vis':'ngc5921.ms',
00135 'verbose':True
00136 }
00137
00138 pipeline.fill['verify'] = verify.fill
00139
00140 pipeline.flag['tasks'] = ['tflagdata']
00141 pipeline.flag['tflagdata'] = {}
00142 pipeline.flag['tflagdata']['args'] = {'vis':'ngc5921.ms',
00143 'mode':'manual',
00144 'autocorr':True}
00145 pipeline.flag['verify'] = verify.flag
00146
00147 pipeline.calibrate['tasks'] = ['setjy', 'bandpass', 'gaincal', 'listcal', 'fluxscale', 'applycal', 'applycal', 'split', 'split', 'exportuvfits']
00148 pipeline.calibrate['applycal'] = {}
00149 pipeline.calibrate['setjy'] = {}
00150 pipeline.calibrate['bandpass'] = {}
00151 pipeline.calibrate['gaincal'] = {}
00152 pipeline.calibrate['listcal'] = {}
00153 pipeline.calibrate['verify'] = verify.calibrate
00154 pipeline.calibrate['fluxscale'] = {}
00155 pipeline.calibrate['setjy']['args'] = {'vis':'ngc5921.ms',
00156 'field' : '1331+305*',
00157 'modimage' : '',
00158 'standard':'Perley-Taylor 99'
00159 }
00160 pipeline.calibrate['bandpass']['args'] = {'vis':'ngc5921.ms',
00161 'caltable':'ngc5921.bcal',
00162 'gaintable' :'',
00163 'gainfield' : '',
00164 'interp' : '',
00165 'field' : '0',
00166 'spw' : '',
00167 'selectdata' : False,
00168 'gaincurve' : False,
00169 'opacity' : 0.0,
00170 'bandtype' : 'B',
00171 'solint' : 'inf',
00172 'combine' : 'scan',
00173 'refant' : 'VA15'
00174 }
00175 pipeline.calibrate['gaincal']['args'] = {'vis':'ngc5921.ms',
00176 'caltable':'ngc5921.gcal',
00177 'gaintable' : 'ngc5921.bcal',
00178 'gainfield' : '',
00179 'interp' : 'nearest',
00180 'field' : '0,1',
00181 'spw' : '0:6~56',
00182 'selectdata' : False,
00183 'gaincurve' : False,
00184 'opacity' : 0.0,
00185 'gaintype' : 'G',
00186 'solint' : 'inf',
00187 'combine' : '',
00188 'calmode' : 'ap',
00189 'minsnr' : 1.0,
00190 'refant' : '15'
00191 }
00192 pipeline.calibrate['listcal']['args'] = {'vis':'ngc5921.ms',
00193 'caltable':'ngc5921.gcal',
00194 'listfile':'ngc5921.listcal.out'
00195 }
00196 pipeline.calibrate['fluxscale']['args'] = {'vis':'ngc5921.ms',
00197 'fluxtable':'ngc5921.fluxscale',
00198 'caltable':'ngc5921.gcal',
00199 'reference' : '1331*',
00200 'transfer' : '1445*'
00201 }
00202 pipeline.calibrate['applycal'] = {0:{}, 1:{}}
00203 pipeline.calibrate['applycal'][0]['args'] = {'vis':'ngc5921.ms',
00204 'gaintable':['ngc5921.fluxscale','ngc5921.bcal'],
00205 'interp' : ['linear', 'nearest'],
00206 'spwmap' : [],
00207 'spw' : '',
00208 'selectdata' : False,
00209 'gaincurve' : False,
00210 'opacity' : 0.0,
00211 'field' : '1,2'
00212 }
00213 pipeline.calibrate['applycal'][1]['args'] = {'vis':'ngc5921.ms',
00214 'gaintable':['ngc5921.fluxscale','ngc5921.bcal'],
00215 'interp' : ['linear', 'nearest'],
00216 'spwmap' : [],
00217 'spw' : '',
00218 'selectdata' : False,
00219 'gaincurve' : False,
00220 'opacity' : 0.0,
00221 'field' : '0',
00222 'gainfield':['0','*']
00223 }
00224 pipeline.calibrate['split'] = {0:{}, 1:{}}
00225 pipeline.calibrate['split'][0]['args'] = {'vis':'ngc5921.ms',
00226 'outputvis' : 'ngc5921.cal.split.ms',
00227 'field' : '1445*',
00228 'spw':'',
00229 'datacolumn':'corrected',
00230 }
00231 pipeline.calibrate['split'][1]['args'] = {'vis':'ngc5921.ms',
00232 'outputvis' : 'ngc5921.src.split.ms',
00233 'field' : 'N5921*',
00234 'spw':'',
00235 'datacolumn':'corrected'
00236 }
00237 pipeline.calibrate['exportuvfits'] = {}
00238 pipeline.calibrate['exportuvfits']['args'] = { 'vis' : 'ngc5921.src.split.ms',
00239 'fitsfile' : 'ngc5921.split.uvfits',
00240 'datacolumn':'data',
00241 'multisource':True,
00242 'async':True
00243 }
00244
00245 pipeline.image['verify'] = verify.image
00246 pipeline.image['tasks'] = ['uvcontsub', 'clean', 'exportfits']
00247 pipeline.image['uvcontsub'] = {}
00248 pipeline.image['uvcontsub']['args'] = {'vis':'ngc5921.ms',
00249 'field' : 'N5921*',
00250 'fitspw':'0:4~6;50~59',
00251 'spw':'0',
00252 'solint':'int',
00253 'fitorder':0
00254 }
00255 pipeline.image['clean'] = {}
00256 pipeline.image['clean']['args'] = {'vis':'ngc5921.ms.contsub',
00257 'imagename':'ngc5921.clean',
00258 'mode':'channel',
00259 'nchan':46,
00260 'start':5,
00261 'width':1,
00262 'field':'0',
00263 'spw':'',
00264 'gain':0.1,
00265 'psfmode':'clark',
00266 'cell':[15.,15.],
00267 'niter':6000,
00268 'threshold':8.0,
00269 'weighting':'briggs',
00270 'robust':0.5,
00271 'mask':''
00272 }
00273 pipeline.image['exportfits'] = {}
00274 pipeline.image['exportfits']['args'] = {'imagename':'ngc5921.clean.image',
00275 'fitsimage':'ngc5921.clean.fits',
00276 'async':True
00277 }
00278
00279 pipeline.analysis['verify'] = verify.analysis
00280 pipeline.analysis['tasks'] = ['immoments']
00281 pipeline.analysis['imstat'] = {0:{},1:{}}
00282 pipeline.analysis['immoments'] = {}
00283 pipeline.analysis['immoments']['args'] = {'imagename':'ngc5921.clean.image',
00284 'moments':[0,1],
00285 'excludepix':[-100, 0.009],
00286 'chans':'',
00287 'outfile':'ngc5921.moments'
00288 }
00289
00290 pipeline.run("NGC5921 Regression")
00291
00292
00293
00294
00295
00296