casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
fls3a_hi_regression.py
Go to the documentation of this file.
00001 ###############################
00002 #
00003 # FLS3a HI Reduction Script
00004 # Frequency-Switched data
00005 # Formatted for wide screen (150
00006 # characters wide)
00007 #
00008 ###############################
00009 #
00010 import time
00011 import os
00012 
00013 os.system('rm -rf FLS3a_HI.image FLS3a_HI.asap FLS3b_HI.asap FLS3a_calfs')
00014 
00015 casapath=os.environ['CASAPATH'].split()[0]
00016 datapath=casapath+'/data/regression/ATST5/FLS3/FLS3_all_newcal_SP'
00017 #copystring='cp -r '+datapath+' .'
00018 #os.system(copystring)
00019 
00020 startTime=time.time()
00021 startProc=time.clock()
00022 
00023 # Project: AGBT02A_007_01
00024 # Observation: GBT(1 antennas)
00025 # 
00026 #   Telescope Observation Date    Observer       Project
00027 #   GBT       [                   4.57539e+09, 4.5754e+09]Lockman        AGBT02A_007_01
00028 #   GBT       [                   4.57574e+09, 4.57575e+09]Lockman        AGBT02A_007_02
00029 #   GBT       [                   4.5831e+09, 4.58313e+09]Lockman        AGBT02A_031_12
00030 # 
00031 # Thu Feb 1 23:15:15 2007    NORMAL ms::summary:
00032 # Data records: 76860       Total integration time = 7.74277e+06 seconds
00033 #    Observed from   22:05:41   to   12:51:56
00034 # 
00035 # Thu Feb 1 23:15:15 2007    NORMAL ms::summary:
00036 # Fields: 2
00037 #   ID   Name          Right Ascension  Declination   Epoch
00038 #   0    FLS3a         17:18:00.00      +59.30.00.00  J2000
00039 #   1    FLS3b         17:18:00.00      +59.30.00.00  J2000
00040 # 
00041 # Thu Feb 1 23:15:15 2007    NORMAL ms::summary:
00042 # Spectral Windows:  (2 unique spectral windows and 1 unique polarization setups)
00043 #   SpwID  #Chans Frame Ch1(MHz)    Resoln(kHz) TotBW(kHz)  Ref(MHz)    Corrs
00044 #   0        1024 LSRK  1421.89269  2.44140625  2500        1420.64269  XX  YY
00045 #   1        1024 LSRK  1419.39269  2.44140625  2500        1418.14269  XX  YY
00046 
00047 
00048 # FLS3 data calibration
00049 # this is calibration part of FLS3 data
00050 #
00051 
00052 #Enable ASAP functionality by importing the library
00053 casapath=os.environ['CASAPATH']
00054 import asap as sd
00055 os.environ['CASAPATH']=casapath
00056 
00057 print '--Import--'
00058 #Load MeasurementSet data into an ASAP scantable (this takes a while)
00059 storage_sav=sd.rcParams['scantable.storage']
00060 sd.rc('scantable',storage='disk')               # Note this enables handling of large datasets with limited memory
00061 #s=sd.scantable('FLS3_all_newcal_SP',false)     # the 'false' indicates that no averaging should be done - this is
00062 s=sd.scantable(datapath,average=false,getpt=false)      # the 'false' indicates that no averaging should be done - this is
00063                                                 # always the case for data that hasn't been calibrated
00064 importproc=time.clock()
00065 importtime=time.time()
00066 
00067 print '--Split & Save--'
00068 # split out the data for the field of interest
00069 s0=s.get_scan('FLS3a*')                         # get all scans with FLS3a source
00070 s0.save('FLS3a_HI.asap')                        # save this data to an ASAP dataset on disk
00071 del s                                           # delete scantables that will not be used any further
00072 del s0
00073 splitproc=time.clock()
00074 splittime=time.time()
00075 
00076 print '--Calibrate--'
00077 s=sd.scantable('FLS3a_HI.asap',average=False)   # load in the saved ASAP dataset with FLS3a
00078 s.set_fluxunit('K')                             # set the fluxunit to 'K'; ASAP currently doesn't know about
00079                                                 # the GBT and mislabels the data as 'Jy'
00080 scanns = s.getscannos()                         # get a list of the scan numbers in the scantable
00081 sn=list(scanns)
00082 print "No. scans to be processed:", len(scanns)
00083 res=sd.calfs(s,sn)                              # Do a frequency switched calibration on the scans
00084 del s
00085 calproc=time.clock()
00086 caltime=time.time()
00087 
00088 print '--Save calibrated data--'
00089 res.save('FLS3a_calfs', 'MS2')                  # Save the calibrated data to a MeasurementSet (CASA) format
00090 del res
00091 saveproc=time.clock()
00092 savetime=time.time()
00093 
00094 print '--Image data--'
00095 #CASA                                                                   #AIPS++
00096 im.open('FLS3a_calfs')                  #set the data                   # myim:=imager('FLS3a_calfs_v4')
00097 im.selectvis(nchan=901,start=30,step=1, #choose a subset of the dataa   # myim.setdata(mode='channel',start=30,
00098 spw=0,field=0)                                                  # step=1,nchan=901,fieldid=1,spwid=1)
00099 dir='J2000 17:18:29 +59.31.23'          #set map center                 # dir=dm.direction('17h18m29s','+59d31m23s')
00100 im.defineimage(nx=150,cellx='1.5arcmin',#define image parameters        # myim.setimage(150,150,cellx='1.5arcmin',
00101 phasecenter=dir,mode='channel',start=30,                                # celly='1.5arcmin',mode='channel',nchan=901,
00102 nchan=901,step=1)                                                       # start=30,step=1,phasecenter=dir,doshift=T,
00103                                                                         # spwid=1)
00104 # choose SD gridding, gridding cache size
00105 im.setoptions(ftmachine='sd',cache=1000000000)                          # myim.setoptions(ftmachine='sd',gridfunction='SF')
00106 im.setsdoptions(convsupport=4)                                          # myim.setsdoptions(convsupport=supportsize)
00107 #make the image
00108 im.makeimage(type='singledish',image='FLS3a_HI.image')                  # myim.makeimage(image='test.image',type='singledish')
00109 imagetime=time.time()
00110 im.close()                                                              # myim.close()
00111 #ia.open('test.image')                                                  # ia:=image('test.image')
00112 #ia.setbrightnessunit('K')                                              # ia.setbrightnessunit('K')
00113 #ia.close()                                                             # ia.close()
00114 imageproc=time.clock()
00115 imagetime = time.time()
00116 
00117 #
00118 endProc = imageproc
00119 endTime = imagetime
00120 #
00121 # -- end of FLS3 HI script
00122 #
00123 # Regression
00124 ia.open('FLS3a_HI.image')
00125 statistics=ia.statistics()
00126 thistest_immax=statistics['max'][0]
00127 thistest_imrms=statistics['rms'][0]
00128 
00129 #
00130 #hi_max=25.577
00131 #hi_rms=1.013
00132 # Regression values of CASA 2.3(#6654)+ASAP 2.2.0(#1448)
00133 # on 64bit REL5.2 (2008/12/01)
00134 hi_max=25.58
00135 hi_rms=1.014
00136 
00137 diff_immax=abs((hi_max-thistest_immax)/hi_max)
00138 diff_imrms=abs((hi_rms-thistest_imrms)/hi_rms)
00139 
00140 import datetime
00141 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00142 outfile='fls3a.hi.'+datestring+'.log'
00143 logfile=open(outfile,'w')
00144 
00145 
00146 print >>logfile,''
00147 print >>logfile,'********** Regression ***********'
00148 print >>logfile,'*                               *'
00149 if (diff_immax < 0.05): print '* Passed image max test '
00150 print >>logfile,'*  Image max ',thistest_immax
00151 if (diff_imrms < 0.05): print '* Passed image rms test '
00152 print >>logfile,'*  Image rms ',thistest_imrms
00153 if ((diff_immax<0.05) & (diff_imrms<0.05)): 
00154         regstate=True
00155         print >>logfile,'---'
00156         print >>logfile,'Passed Regression test for FLS3a HI'
00157         print >>logfile,'---'
00158         print ''
00159         print 'Regression PASSED'
00160         print ''
00161 else: 
00162         regstate=False
00163         print ''
00164         print 'Regression FAILED'
00165         print ''
00166         print >>logfile,'----FAILED Regression test for FLS3a HI'
00167 print >>logfile,'*********************************'
00168 #
00169 print >>logfile,''
00170 print >>logfile,''
00171 print >>logfile,'********* Benchmarking *****************'
00172 print >>logfile,'*                                      *'
00173 print >>logfile,'Total wall clock time was: '+str(endTime - startTime)
00174 print >>logfile,'Total CPU        time was: '+str(endProc - startProc)
00175 print >>logfile,'Processing rate MB/s  was: '+str(4100/(endTime - startTime))
00176 print >>logfile,'* Breakdown: '
00177 print >>logfile,'*   import       time was: '+str(importtime-startTime)
00178 print >>logfile,'*            CPU time was: '+str(importproc-startProc)
00179 print >>logfile,'*   split        time was: '+str(splittime-importtime)
00180 print >>logfile,'*            CPU time was: '+str(splitproc-importproc)
00181 print >>logfile,'*   calibration  time was: '+str(caltime-splittime)
00182 print >>logfile,'*            CPU time was: '+str(calproc-splitproc)
00183 print >>logfile,'*   save         time was: '+str(savetime-caltime)
00184 print >>logfile,'*            CPU time was: '+str(saveproc-calproc)
00185 print >>logfile,'*   image        time was: '+str(imagetime-savetime)
00186 print >>logfile,'*            CPU time was: '+str(imageproc-saveproc)
00187 print >>logfile,'****************************************'
00188 
00189 
00190 logfile.close()
00191 ### Resore the previous storage setting
00192 sd.rc('scantable',storage=storage_sav)