casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
irc_cs_task_regression.py
Go to the documentation of this file.
00001 ###############################
00002 #
00003 # IRC+10216 13CS Reduction Script
00004 # using new sd tasks
00005 # Nod data
00006 # 
00007 # tasks used
00008 # sdlist
00009 # sdcal
00010 # sdsmooth
00011 # sdbaseline
00012 # sdplot
00013 # sdstat
00014 # sdsave
00015 ###############################
00016 import time
00017 import os
00018 
00019 os.system('rm -rf IRC+10216_rawACSmod IRC+10216_rawACSmod_cal IRC+10216_rawACSmod_cal_sm IRC+10216_rawACSmod_cal_sm_bs  irc_cs_reducedSCAN0_CYCLE0_BEAM0_IF0.txt irc_cs_reduced.eps irc_cs_fit.txt')
00020 
00021 #enable/disable plotting
00022 doplot = False
00023 
00024 casapath=os.environ['CASAPATH'].split()[0]
00025 datapath=casapath+'/data/regression/ATST5/IRC+10216/IRC+10216_rawACSmod'
00026 copystring='cp -r '+datapath+' .'
00027 os.system(copystring)
00028 
00029 startTime=time.time()
00030 startProc=time.clock()
00031 
00032 #   Project: AGBT06A_018_01
00033 #Observation: GBT(1 antennas)
00034 #
00035 #Tue Jan 30 20:24:29 2007    NORMAL ms::summary:
00036 #Data records: 4992       Total integration time = 4244.15 seconds
00037 #   Observed from   10:31:01   to   11:41:45
00038 #
00039 #Tue Jan 30 20:24:29 2007    NORMAL ms::summary:
00040 #Fields: 3
00041 #  ID   Name          Right Ascension  Declination   Epoch
00042 #  0    IRC+10216     09:47:57.38      +13.16.43.70  J2000
00043 #  1    IRC+10216     09:47:57.38      +13.16.43.70  J2000
00044 #  2    IRC+10216     09:47:57.38      +13.16.43.70  J2000
00045 #
00046 #Tue Jan 30 20:24:29 2007    NORMAL ms::summary:
00047 #Spectral Windows:  (13 unique spectral windows and 1 unique polarization setups)
00048 #  SpwID  #Chans Frame Ch1(MHz)    Resoln(kHz) TotBW(kHz)  Ref(MHz)    Corrs
00049 #  0        4096 LSRK  48263.5858  12.2067945  49999.0303  48288.5853  RR  LL H2CO
00050 #  1        4096 LSRK  45899.1486  12.2067945  49999.0303  45924.1481  RR  LL H213CO
00051 #  2        4096 LSRK  43857.1942  12.2067945  49999.0303  43882.1937  RR  LL 13CS
00052 #  3        4096 LSRK  48970.0031  12.2067945  49999.0303  48995.0026  RR  LL CS
00053 #  7        4096 LSRK  46226.6452  12.2067949  49999.0319  46251.6447  RR  LL 
00054 #  17       4096 LSRK  45469.0638  12.2067955  49999.0343  45494.0633  RR  LL HC3N
00055 #  18       4096 LSRK  45280.5214  12.2067955  49999.0343  45305.5209  RR  LL HCC13CN
00056 #  19       4096 LSRK  44054.8331  12.2067955  49999.0343  44079.8326  RR  LL CH3OH
00057 #  20       4096 LSRK  44146.1063  12.2067955  49999.0343  44171.1058  RR  LL HCCC15N
00058 #  27       4096 LSRK  43941.6784  12.206796   49999.0365  43966.6779  RR  LL HN13CO
00059 #  28       4096 LSRK  42625.1528  12.206796   49999.0365  42650.1523  RR  LL H15NCO
00060 #  29       4096 LSRK  41574.856   12.206796   49999.0365  41599.8556  RR  LL HNC18O
00061 #  30       4096 LSRK  43402.4488  12.206796   49999.0365  43427.4483  RR  LL SiO
00062 
00063 # Scans: 230-231,233-236,253-256 Setup 1 H2CO et al
00064 # Scans: 237-240,249-252 Setup 2 HC3N et al
00065 # Scans: 241-248         Setup 3 SiO et al
00066 
00067 
00068 asap_init()                             #load ASAP module
00069 
00070                                         #scan numbers (zero-based) as compared to GBTIDL
00071                                         #changes made to get to IRC+10216_rawACSmod
00072                                         #  -- merge spectral windows with tolerance
00073 
00074 # summary
00075 #default(sdlist)
00076 #infile='IRC+10216_rawACSmod'
00077 #sdlist()
00078 
00079 if doplot:
00080    localplotlevel = 1
00081 else:
00082    localplotlevel = 0
00083 
00084 # calibartion and averaging
00085 # calibrate nod scans for CS line (IF=3)
00086 default(sdcal)
00087 infile='IRC+10216_rawACSmod'
00088 fluxunit='K'
00089 calmode='nod'
00090 scanlist=[229,230]
00091 iflist=[3]
00092 scanaverage=False
00093 timeaverage=True # average in time
00094 tweight='tintsys' # weighted by integ time and Tsys for time averaging
00095 polaverage=True  # average polarization
00096 pweight='tsys'   # weighted by Tsys for pol. averaging
00097 tau=0.09         # do opacity correction
00098 overwrite=True
00099 plotlevel=localplotlevel
00100 sdcal()
00101 # output
00102 localoutfile=infile+'_cal'
00103 
00104 #smoothing
00105 # do boxcar smoothing with channel width=5
00106 default(sdsmooth)
00107 infile = localoutfile
00108 kernel='boxcar'
00109 kwidth=5
00110 overwrite=True
00111 plotlevel=localplotlevel
00112 sdsmooth()
00113 localoutfile=infile+'_sm'
00114 
00115 #fit and remove baselines
00116 # do baseline fit with cubic spline with one knot (npiece=2)
00117 # 3-sigma clipping plus 1 iteration applied.
00118 # automatically detect lines to exclude from fitting
00119 default(sdbaseline)
00120 infile=localoutfile
00121 maskmode='auto'
00122 #edge=[50]
00123 thresh=5
00124 avg_limit=4
00125 #blfunc='poly'
00126 #order=1
00127 blfunc='cspline'
00128 npiece=2
00129 clipthresh=3.0
00130 clipniter=1
00131 overwrite=True
00132 plotlevel=localplotlevel
00133 sdbaseline()
00134 localoutfile=infile+'_bs'
00135 
00136 #plotting the reslut
00137 #plot the spectrum and save to a postscript file
00138 if doplot:
00139    default(sdplot)
00140    infile=localoutfile
00141    specunit='GHz'
00142    outfile='irc_cs_reduced.eps'
00143    #sd.plotter.set_histogram(hist=True)     # draw spectrum using histogram                 # histogram
00144    #sd.plotter.axhline(color='r',linewidth=2) # zline                                       # zline
00145    sdplot()
00146 else:
00147    print "Plotting the result is skipped."
00148 
00149 # statistics
00150 default(sdstat)
00151 # select line free regions to get rms
00152 infile=localoutfile
00153 masklist=[800,1500]
00154 xstat=sdstat()
00155 rms=xstat['rms']
00156 #rms=
00157 #
00158 # select the line region
00159 masklist=[1850,2300]
00160 xstat=sdstat()
00161 xstat
00162 max=xstat['max']
00163 sum=xstat['sum']
00164 median=xstat['median']
00165 mean=xstat['mean']
00166 
00167 # Save the spectrum
00168 # in different formats
00169 default(sdsave)
00170 infile=localoutfile
00171 outfile='irc_cs_reduced'
00172 outform='ASCII'
00173 overwrite=True
00174 sdsave()
00175 #outfile='irc_cs_reduced.ms'
00176 #outform='MS2'
00177 #sdsave()
00178 
00179 #
00180 endProc = time.clock()
00181 endTime = time.time()
00182 
00183 # --- end of irc cs script
00184 
00185 #irc_max=3.3
00186 #irc_rms=0.147
00187 #irc_sum=627.5
00188 # Regression values of CASA 2.3(#6654)+ASAP 2.2.0(#1448)
00189 # on 64bit REL5.2 (2008/12/01)
00190 #irc_max=3.325
00191 #irc_rms=0.1473
00192 #irc_sum=627.9
00193 # Regression values of CASA 3.1+ASAP3 on 64bit RHEL5.5 (2010/10?)
00194 # Regression values of CASA 3.2(#14238)+ASAP3(#2031) on 64bit RHEL5.5
00195 #   using cspline with (npiece,clipthresh,clipniter)=(2,3.0,1) in sdbaseline (2011/03/25 WK)
00196 irc_max=3.3270
00197 irc_rms=0.1472
00198 irc_sum=630.75
00199 
00200 diff_max = abs((irc_max-max)/irc_max)
00201 diff_rms = abs((irc_rms-rms)/irc_rms)
00202 diff_sum = abs((irc_sum-sum)/irc_sum)
00203 
00204 import datetime
00205 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00206 outfile='irc.cs.task'+datestring+'.log'
00207 logfile=open(outfile,'w')
00208 
00209 print >>logfile,''
00210 print >>logfile,'********** Regression ***********'
00211 print >>logfile,'*                               *'
00212 if (diff_max < 0.05): print >>logfile,'* Passed spectrum max test '
00213 print >>logfile,'*  Spectrum max '+str(max)
00214 if (diff_rms < 0.05): print >>logfile,'* Passed spectrum rms test '
00215 print >>logfile,'*  Spectrum rms '+str(rms)
00216 if (diff_sum < 0.05): print >>logfile,'* Passed spectrum (line) sum test'
00217 print >>logfile,'*  Line integral '+str(sum)
00218 if ((diff_max<0.05) & (diff_rms<0.05) & (diff_sum<0.05)):
00219         regstate=True
00220         print ''
00221         print 'Regression PASSED'
00222         print ''
00223         print >>logfile,'---'
00224         print >>logfile,'Passed Regression test for IRC-CS'
00225         print >>logfile,'---'
00226 else:
00227         regstate=False
00228         print ''
00229         print 'Regression FAILED'
00230         print ''
00231         print >>logfile,'----FAILED Regression test for IRC-CS'
00232 print >>logfile,'*********************************'
00233 
00234 print >>logfile,''
00235 print >>logfile,''
00236 print >>logfile,'********* Benchmarking *****************'
00237 print >>logfile,'*                                      *'
00238 print >>logfile,'Total wall clock time was: '+str(endTime - startTime)
00239 print >>logfile,'Total CPU        time was: '+str(endProc - startProc)
00240 #print 'Processing rate MB/s  was: ', 35.1/(endTime - startTime)
00241 
00242 logfile.close()