casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
ori_sio_task_regression.py
Go to the documentation of this file.
00001 ###############################
00002 #
00003 # ORION-S SiO Reduction Script
00004 # using SD tasks 
00005 # Position-Switched data
00006 #
00007 # used tasks
00008 # sdlist
00009 # sdcal
00010 # sdsmooth
00011 # sdbaseline
00012 # sdplot
00013 # sdstat
00014 # sdfit
00015 # sdsave
00016 ###############################
00017 #
00018 import time
00019 import os
00020 
00021 os.system('rm -rf OrionS_rawACSmod OrionS_rawACSmod_cal OrionS_rawACSmod_cal_sm OrionS_rawACSmod_cal_sm_bs orions_sio_reducedSCAN0_CYCLE0_BEAM0_IF0.txt orions_sio_reduced.eps orions_sio_fit.txt')
00022 
00023 #enable/disable plotting
00024 doplot = False 
00025 
00026 casapath=os.environ['CASAPATH']
00027 datapath=casapath.split()[0]+'/data/regression/ATST5/OrionS/OrionS_rawACSmod'
00028 copystring='cp -r '+datapath+' .'
00029 os.system(copystring)
00030 
00031 startTime=time.time()
00032 startProc=time.clock()
00033 
00034 #           MeasurementSet Name:  /home/rohir3/jmcmulli/SD/OrionS_rawACSmod      MS Version 2
00035 #
00036 # Project: AGBT06A_018_01
00037 # Observation: GBT(1 antennas)
00038 #
00039 #Data records: 256       Total integration time = 1523.13 seconds
00040 #   Observed from   01:45:58   to   02:11:21
00041 #
00042 #Fields: 4
00043 #  ID   Name          Right Ascension  Declination   Epoch
00044 #  0    OrionS        05:15:13.45      -05.24.08.20  J2000
00045 #  1    OrionS        05:35:13.45      -05.24.08.20  J2000
00046 #  2    OrionS        05:15:13.45      -05.24.08.20  J2000
00047 #  3    OrionS        05:35:13.45      -05.24.08.20  J2000
00048 #
00049 #Spectral Windows:  (8 unique spectral windows and 1 unique polarization setups)
00050 #  SpwID  #Chans Frame Ch1(MHz)    Resoln(kHz) TotBW(kHz)  Ref(MHz)    Corrs
00051 #  0        8192 LSRK  45464.3506  6.10423298  50005.8766  45489.3536  RR  LL HC3N
00052 #  1        8192 LSRK  45275.7825  6.10423298  50005.8766  45300.7854  RR  LL HN15CO
00053 #  2        8192 LSRK  44049.9264  6.10423298  50005.8766  44074.9293  RR  LL CH3OH
00054 #  3        8192 LSRK  44141.2121  6.10423298  50005.8766  44166.2151  RR  LL HCCC15N
00055 #  12       8192 LSRK  43937.1232  6.10423356  50005.8813  43962.1261  RR  LL HNCO
00056 #  13       8192 LSRK  42620.4173  6.10423356  50005.8813  42645.4203  RR  LL H15NCO
00057 #  14       8192 LSRK  41569.9768  6.10423356  50005.8813  41594.9797  RR  LL HNC18O
00058 #  15       8192 LSRK  43397.8198  6.10423356  50005.8813  43422.8227  RR  LL SiO
00059 
00060 # Scans: 21-24  Setup 1 HC3N et al
00061 # Scans: 25-28  Setup 2 SiO et al
00062 
00063 asap_init()                             #load ASAP module
00064                                         #Orion-S (SiO line reduction only)
00065                                         #Notes:
00066                                         #scan numbers (zero-based) as compared to GBTIDL
00067 
00068                                         #changes made to get to OrionS_rawACSmod
00069                                         #modifications to label sig/ref positions
00070 #os.environ['CASAPATH']=casapath
00071 
00072 
00073 # summary
00074 #default(sdlist)
00075 #infile='OrionS_rawACSmod'
00076 #sdlist()
00077 
00078 if doplot:
00079    localplotlevel = 1
00080 else:
00081    localplotlevel = 0
00082 
00083 # calibartion and averaging
00084 # calibrate position-switched CH3OH scans (IF=15) 
00085 default(sdcal)
00086 infile='OrionS_rawACSmod'
00087 fluxunit='K' 
00088 calmode='ps'
00089 scanlist=[24,25,26,27]
00090 iflist=[15]
00091 scanaverage=False
00092 timeaverage=True # average in time
00093 tweight='tintsys' #weighted by integ time and Tsys for time averaging
00094 polaverage=True  # average polarization
00095 pweight='tsys'   # weighted by Tsys for pol averaging
00096 tau=0.09         # do opacity correction 
00097 overwrite=True
00098 plotlevel=localplotlevel  
00099 sdcal() 
00100 # output
00101 localoutfile=infile+'_cal'
00102 
00103 #smoothing
00104 # do boxcar smoothing with channel width=5
00105 default(sdsmooth)
00106 infile = localoutfile
00107 kernel='boxcar'
00108 kwidth=10
00109 overwrite=True
00110 plotlevel=localplotlevel
00111 sdsmooth()
00112 localoutfile=infile+'_sm'
00113 
00114 #fit and remove baselines
00115 # do baseline fit with polynomial order of 2
00116 # automatically detect lines to exclude from fitting
00117 default(sdbaseline)
00118 infile=localoutfile
00119 maskmode='list'
00120 masklist=[[500,3500],[5000,7500]]
00121 blfunc='poly'
00122 order=5
00123 overwrite=True
00124 plotlevel=localplotlevel
00125 sdbaseline()
00126 localoutfile=infile+'_bs'
00127 #sd.plotter.plot(spave)                 # plot                                          # baseline
00128 
00129 #plotting the reslut
00130 #plot the spectrum and save to a postscript file 
00131 if doplot:
00132    default(sdplot)
00133    infile=localoutfile
00134    specunit='GHz'
00135    outfile='orions_sio_reduced.eps'
00136    #sd.plotter.set_histogram(hist=True)     # draw spectrum using histogram                 # histogram
00137    #sd.plotter.axhline(color='r',linewidth=2) # zline                                       # zline
00138    sdplot()
00139 else:
00140    print "Plotting the result is skipped."
00141 
00142 # statistics
00143 default(sdstat)
00144 # select line free regions to get rms
00145 infile=localoutfile
00146 masklist=[1000,3000]
00147 xstat=sdstat()
00148 rms=xstat['rms']
00149 #rms= 0.037199538201093674 [CASA 2.3(#6654)+ASAP 2.2.0(#1448)]
00150 #
00151 # select the line region
00152 masklist=[3900,4300]
00153 xstat=sdstat()
00154 xstat
00155 max=xstat['max']
00156 sum=xstat['sum']
00157 median=xstat['median']
00158 mean=xstat['mean']
00159 
00160 # fitting
00161 default(sdfit)
00162 infile=localoutfile
00163 #sd.plotter.plot(spave)                 # plot spectrum
00164 fitmode='list'
00165 maskline=[3900,4300]    # create region around line
00166 nfit=1
00167 plotlevel=localplotlevel
00168 outfile='orions_sio_fit.txt'
00169 xstat=sdfit()
00170 xstat  # print fit statistics 
00171 
00172 # Save the spectrum
00173 # in different formats
00174 default(sdsave)
00175 infile=localoutfile
00176 outfile='orions_sio_reduced'
00177 outform='ASCII'
00178 overwrite=True
00179 sdsave()
00180 outfile='orions_sio_reduced.ms'
00181 outform='MS2'
00182 
00183 endProc = time.clock()
00184 endTime = time.time()
00185 #
00186 # --- end of orion-s ch3oh script
00187 # Regression
00188 
00189 #ori_max=0.366
00190 #ori_rms=0.037
00191 #ori_sum=49.9
00192 # Regression values of CASA 2.3(#6654)+ASAP 2.2.0(#1448)
00193 # on 64bit REL5.2 (2008/12/01)
00194 ori_max=0.3662
00195 ori_rms=0.03720
00196 ori_sum=49.95
00197 diff_max = abs((ori_max-max)/ori_max)
00198 diff_rms = abs((ori_rms-rms)/ori_rms)
00199 diff_sum = abs((ori_sum-sum)/ori_sum)
00200 
00201 import datetime
00202 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00203 outfile='ori.sio.task.'+datestring+'.log'
00204 logfile=open(outfile,'w')
00205 print >>logfile,''
00206 print >>logfile,'********** Regression ***********'
00207 print >>logfile,'*                               *'
00208 if (diff_max < 0.05): print >>logfile,'* Passed spectrum max test '
00209 print >>logfile,'*  Spectrum max '+str(max)
00210 if (diff_rms < 0.05): print >>logfile,'* Passed spectrum rms test '
00211 print >>logfile,'*  Spectrum rms '+str(rms)
00212 if (diff_sum < 0.05): print >>logfile,'* Passed spectrum (line) sum test'
00213 print >>logfile,'*  Line integral '+str(sum)
00214 if ((diff_max<0.05) & (diff_rms<0.05) & (diff_sum<0.05)): 
00215         regstate=True
00216         print >>logfile,'---'
00217         print >>logfile,'Passed Regression test for OrionS-SiO'
00218         print >>logfile,'---'
00219         print ''
00220         print 'Regression PASSED'
00221         print ''
00222 else: 
00223         regstate=False
00224         print >>logfile,'----FAILED Regression test for OrionS-SiO'
00225         print ''
00226         print 'Regression FAILED'
00227         print ''
00228 
00229 print >>logfile,'*********************************'
00230 
00231 print >>logfile,''
00232 print >>logfile,''
00233 print >>logfile,'********* Benchmarking *****************'
00234 print >>logfile,'*                                      *'
00235 print >>logfile,'Total wall clock time was: '+str(endTime - startTime)
00236 print >>logfile,'Total CPU        time was: '+str(endProc - startProc)
00237 #print 'Processing rate MB/s  was: ', 35.1/(endTime - startTime)
00238 
00239 logfile.close()