00001 ############################################################################# 00002 ## $Id:$ 00003 # Test Name: # 00004 # Regression Test Script to reduce a wide-field image # 00005 # # 00006 # Rationale for Inclusion: # 00007 # It ensures that the the mosaic is successfully created # 00008 # taking into account the outliers. The data has been # 00009 # already calibrated. # 00010 # # 00011 # Features tested: # 00012 # 1) Is the task working properly? # 00013 # 2) Is the task producing the same results as the reference? # 00014 # The script will as well test the following features: # 00015 # # 00016 # Input Data Process Output Data # 00017 # widefield_model.fits---> importuvfits ----> widefield.ms # 00018 # | # 00019 # v # 00020 # classic mode clean ----> wf_h.* # 00021 # | # 00022 # v # 00023 # wide-field mode clean ------> wf_x.* # 00024 # | # 00025 # v # 00026 # imstat # 00027 # # 00028 # # 00029 # Input data: # 00030 # widefield_model.fits, outliers.txt # 00031 # # 00032 # Author: Ed Fomalont # 00033 # # 00034 # Note: all input data have relative paths to the local directory # 00035 ############################################################################# 00036 00037 00038 import os 00039 import time 00040 import regression_utility as tstutl 00041 from __main__ import default 00042 from tasks import * 00043 from taskinit import * 00044 00045 00046 # Enable benchmarking? 00047 benchmarking = True 00048 usedasync = False 00049 00050 # 00051 # Set up some useful variables 00052 # 00053 # This is where the NGC1333 UVFITS data will be 00054 fitsdata='widefield_model.uvfits' 00055 00056 # The testdir where all output files will be kept 00057 testdir='wf_regression' 00058 00059 # The prefix to use for output files. 00060 #prefix=testdir+"/"+'widefield' 00061 prefix='widefield' 00062 # Make new test directory 00063 # (WARNING! Removes old test directory of the same name if one exists) 00064 tstutl.maketestdir(testdir) 00065 00066 # Start benchmarking 00067 if benchmarking: 00068 startTime = time.time() 00069 startProc = time.clock() 00070 00071 # 00072 #===================================================================== 00073 # 00074 # Import the data from FITS to MS 00075 # 00076 try: 00077 00078 print '--Import--' 00079 00080 # Safest to start from task defaults 00081 default('importuvfits') 00082 00083 # Set up the MS filename and save as new global variable 00084 msfile = prefix + '.ms' 00085 00086 # Set up image names 00087 nimage = 'wf_h' 00088 wimage = 'wf_x' 00089 00090 # Use task importuvfits 00091 fitsfile = fitsdata 00092 vis = msfile 00093 antnamescheme="new" 00094 importuvfits() 00095 00096 # Record import time 00097 if benchmarking: 00098 importtime = time.time() 00099 00100 # 00101 #===================================================================== 00102 # 00103 # Run normal clean and create 5 images 00104 # 00105 print '--Clean in classic mode--' 00106 default('clean') 00107 vis = msfile 00108 outlierfile = 'outliers.txt' 00109 niter = 1000 00110 imagename = nimage 00111 field = '0' 00112 imsize = 128 00113 cell = '0.3arcsec' 00114 weighting = 'briggs' 00115 pbcor = False 00116 usescratch = False 00117 # async = T 00118 clean() 00119 00120 # Record clean completion time 00121 if benchmarking: 00122 clean1time = time.time() 00123 00124 00125 # 00126 #===================================================================== 00127 # 00128 # Run clean using widefield mode with 5 outliers 00129 # 00130 print '--Clean in widefield mode--' 00131 taskname = 'clean' 00132 default(taskname) 00133 vis = msfile 00134 imagename = wimage 00135 gridmode = 'widefield' 00136 wprojplanes = 64 00137 niter = 500 00138 interactive = False 00139 imsize = 4096 00140 cell = '0.4arcsec' 00141 weighting = 'briggs' 00142 usescratch = False 00143 async = False 00144 clean() 00145 00146 # Record clean completion time 00147 if benchmarking: 00148 clean2time = time.time() 00149 00150 # It will create the following files: 00151 #wf_h_0.flux, wf_h_0.image, wf_h_0.model, wf_h_0.psf 00152 #wf_h_1.flux, wf_h_1.image, wf_h_1.model, wf_h_1.psf 00153 #wf_h_2.flux, wf_h_2.image, wf_h_2.model, wf_h_2.psf 00154 #wf_h_3.flux, wf_h_3.image, wf_h_3.model, wf_h_3.psf 00155 #wf_h_4.flux, wf_h_4.image, wf_h_4.model, wf_h_4.psf 00156 00157 # and for the widefield case: 00158 # wf_x.flux, wf_x.image, wf_x.model, wf_x.residual, wf_x.mask 00159 # wf_x.psf 00160 00161 # Get statistics of individual images 00162 print '--Imstat--' 00163 default('imstat') 00164 imagename = wimage+'.image' 00165 wstats =imstat() 00166 00167 print "" 00168 print ' Wide-field results ' 00169 print ' =============== ' 00170 00171 print '' 00172 print ' --Regression Tests--' 00173 print '' 00174 00175 sumnpts = 0 00176 for i in range(5): 00177 imagename = nimage+'_%s'%i+'.image' 00178 nstats = imstat() 00179 00180 # Compare the number of points in wide-field 00181 # image and in individual images 00182 print nstats['max'][0] 00183 print nstats['min'][0] 00184 # sumnpts += nstats['npts'][0] 00185 00186 # print "sum_n_npts=%s, w_npts=%s" %(sumnpts,wstats['npts'][0]) 00187 print 'wide-field stats' 00188 print wstats['max'][0] 00189 print wstats['min'][0] 00190 00191 # Pull the max from the nstats dictionary 00192 # created above using imstat 00193 # thistest_immax=nstats['max'][0] 00194 # oldtest_immax = 7.50 00195 # print ' Clean image max should be ',oldtest_immax 00196 # print ' Found : Image Max = ',thistest_immax 00197 # diff_immax = abs((oldtest_immax-thistest_immax)/oldtest_immax) 00198 # print ' Difference (fractional) = ',diff_immax 00199 # 00200 # print '' 00201 # # Pull the rms from the nstats dictionary 00202 # thistest_imrms=nstats['rms'][0] 00203 # oldtest_imrms = 0.134 00204 # print ' Clean image rms should be ',oldtest_imrms 00205 # print ' Found : Image rms = ',thistest_imrms 00206 # diff_imrms = abs((oldtest_imrms-thistest_imrms)/oldtest_imrms) 00207 # print ' Difference (fractional) = ',diff_imrms 00208 00209 # Record processing completion time 00210 if benchmarking: 00211 endProc = time.clock() 00212 endTime = time.time() 00213 00214 except Exception, instance: 00215 print >> sys.stderr, "Regression test failed for wide-field instance = ", instance 00216