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