The script below, bandcal.csh, is a working example how Jin Koda's M51 data can be passband calibrated. Courtesy Stuart Vogel.
1 #! /bin/csh -f 2 # 3 # 1. Uses noise source for narrow-band channel to channel bandpass calibration 4 # Conjugate LSB for USB 5 # 2. Uses astronomical source for wideband and low-order polynomical narrow- 6 # band passband calibration 7 # 3. Uses hybrid mode data for band-offset phase calibration 8 # 4. Generates temporal phase calibration from phase calibrator using 9 # super-wideband (average of all three bands from both sidebands) 10 # 5. Applies calibrations to each of the source data bands 11 # 6. Glues source bands back together 12 # 7. Flags bad channels in overlap region between bands. 13 14 # Assumes that a relatively bright quasar has been observed in the following 15 # modes: 16 # 1. 500/500/500 17 # 2. nb / nb/ nb nb=narrowband 18 # 3. With 2 bands in narrowband and the other in 500. aka "hybrid" mode 19 # Note - easy mod to script to use 1 band in nb, others in hybrid. 20 # 21 # SNV 2/18/2007 22 23 # Assumes data properly flagged so that self cal solutions are good!! 24 # Make sure refant is a good choice! 25 26 # To-do list: 27 # 1. this script assumes just one visibility calibrator 28 29 # User parameters 30 31 set vis = c0064.jk_m51co_c.4.miriad # visibility file 32 set refant=9 # reference antenna 33 set cal = 3C279 # passband calibrator 34 set viscal = 1153+495 # visibility calibrator 35 set source = M51MOS # source 36 set nb_array = ( 4 5 6 ) # spectral line bands to calibrate 37 set wide_array = ( 5 6 5 ) # hybrid band with wide setup 38 # For each element in nb_array, the 39 # corresponding element in wide_array 40 # should be the hybrid band that is wideband 41 set superwidewin = "2,3,5,6" # windows to use for super-wideband 42 set superwidechan = "1,1,60" # Channels for superwide 43 set bw = 64 # Spectral Line bandwidth 44 set wideline = "1,3,11,11" # line type for 500 MHz 45 set narrowline = "1,3,58,58" # line type for narrow band 46 set sideband = "usb" # Sideband (used for noise conjugation) 47 set calint = 0.2 # passband calibration interval (minutes) 48 set vcalint = 42 # visibility calibrator cal interval 49 set order = 1 # polynomial order for smamfcal fit 50 set edge = 3 # # of edge channels to discard in smamfcal 51 set badants = "2,3,5" # bad antennas to flag 52 # Do heavy uvflagging prior to script 53 set badchan1 = "6,61,1,1" # bad overlap channels between 1st 2 bands 54 set badchan2 = "6,124,1,1" # bad overlap channels between 2nd 2 bands 55 set restfreq = 115.271203 # rest frequency of line 56 57 # End user parameters 58 59 uvflag vis=$vis select=anten'('$badants')' flagval=flag 60 61 rm -rf all.wide all.nb 62 rm -rf $cal.wide* $cal.nb* $cal.hyb* 63 64 # Select all-wideband and all-narrowband data 65 bwsel vis=$vis bw=500,500,500 nspect=6 out=all.wide 66 bwsel vis=$vis bw=$bw,$bw,$bw nspect=6 out=all.nb 67 68 # First get super-wideband on passband calibrator and phase calibrator 69 rm -r $cal.wide $cal.wide.0 $viscal.v.wide $viscal.v.wide.0 70 uvcat vis=all.wide out=$cal.wide.0 \ 71 "select=-auto,source($cal)" options=nocal,nopass 72 uvcat vis=all.wide out=$viscal.v.wide.0 \ 73 "select=-auto,source($viscal)" options=nocal,nopass 74 75 # mfcal passband on superwideband 76 # Don't bother using noise source for superwideband 77 mfcal vis=$cal.wide.0 interval=$calint refant=$refant 78 echo "**** Plot super-wideband passband on $cal.wide.0 " 79 gpplt vis=$cal.wide.0 options=bandpass yaxis=phase nxy=4,4 yrange=-360,360 device=bp$cal.wide.0.ps/ps 80 gv bp$cal.wide.0.ps 81 82 # Inspect temporal phase variation on superwideband 83 echo "**** Check temporal phase variations on superwideband $cal.wide.0 " 84 gpplt vis=$cal.wide.0 yaxis=phase yrange=-360,360 nxy=4,4 device=p$cal.wide.0.ps/ps 85 gv p$cal.wide.0.ps 86 87 # Apply superwideband passband for later use in band offset cal 88 uvcat vis=$cal.wide.0 out=$cal.wide options=nocal 89 90 # Copy wideband passband to visibility calibrator 91 gpcopy vis=$cal.wide.0 out=$viscal.v.wide.0 options=nocal,nopol 92 uvcat vis=$viscal.v.wide.0 out=$viscal.v.wide options=nocal 93 94 # Determine phase gain variations on visibility calibrator using superwide 95 rm -r $viscal.v.wide.sw 96 uvcat vis=$viscal.v.wide out=$viscal.v.wide.sw select='win('$superwidewin')' 97 selfcal vis=$viscal.v.wide.sw line=channel,$superwidechan \ 98 interval=$vcalint options=phase refant=$refant 99 echo "**** Phases on the superwideband visibility calibrator $viscal.v.wide.sw" 100 gpplt vis=$viscal.v.wide.sw device=p$viscal.v.wide.sw.ps/ps yaxis=phase yrange=-360,360 nxy=4,4 101 gv p$viscal.v.wide.sw.ps 102 103 # LOOP OVER EACH NARROW BAND 104 105 set nblength = $#nb_array 106 if $nblength == 1 set list = 1 107 if $nblength == 2 set list = ( 1 2 ) 108 if $nblength == 3 set list = ( 1 2 3 ) 109 110 foreach i ( $list ) 111 112 set nb = $nb_array[$i] 113 set wide = $wide_array[$i] 114 rm -r all.hyb 115 116 # Select hybrid data 117 # NB: assumes only 1 band is in wideband mode; if two bands are in wideband 118 # mode, change hybrid selection to select on nb and modify bw= 119 if ( $wide == 1 || $wide == 4 ) then 120 if ($nb == 2 || $nb == 5) then 121 bwsel vis=$vis nspect=6 bw=500,$bw,0 out=all.hyb 122 else 123 bwsel vis=$vis nspect=6 bw=500,0,$bw out=all.hyb 124 endif 125 endif 126 if ( $wide == 2 || $wide == 5 ) then 127 if ($nb == 1 || $nb == 4) then 128 bwsel vis=$vis nspect=6 bw=$bw,500,0 out=all.hyb 129 else 130 bwsel vis=$vis nspect=6 bw=0,500,$bw out=all.hyb 131 endif 132 endif 133 if ( $wide == 3 || $wide == 6 ) then 134 if ($nb == 1 || $nb == 4) then 135 bwsel vis=$vis nspect=6 bw=$bw,0,500 out=all.hyb 136 else 137 bwsel vis=$vis nspect=6 bw=0,$bw,500 out=all.hyb 138 endif 139 endif 140 set test = `uvio vis=all.hyb | grep -i source | awk '{if (NR==1) print $4}'` 141 if ($test == "") then 142 echo 143 echo "FATAL! There appears to be no valid data in all.hyb" 144 echo "This is likely to be because wide_array[$i] = $wide is not valid" 145 echo "(i.e. band $wide is not really wideband), or one of the other " 146 echo "bands is not really narrowband. Use uvindex to sort this out" 147 exit 148 endif 149 150 echo "**** Be sure that bands are found by inspecting uvlist output!" 151 echo "**** If no frequency info is found, that bwsel parameters are wrong" 152 uvlist vis=all.hyb options=spectra 153 154 # Now we need to select single bands to process in this pass 155 # Select by source and band 156 # First get the two bands in all-wideband mode 157 # Note that we use super-wideband calibrated file for the wide mode 158 rm -rf $cal.win$nb* $cal.win$wide* $cal.wide.win$wide* $cal.wide.win$nb* 159 rm -rf $cal.hyb.win$nb* $cal.hyb.win$wide* noise.nb.win$nb* 160 uvcat vis=$cal.wide out=$cal.wide.win$wide "select=-auto,source($cal),win($wide)" \ 161 options=nocal,nopass 162 uvcat vis=$cal.wide out=$cal.wide.win$nb "select=-auto,source($cal),win($nb)" \ 163 options=nocal,nopass 164 165 # Now select hybrid wideband band 166 uvcat vis=all.hyb out=$cal.hyb.win$wide.0 "select=-auto,source($cal),win($wide)" \ 167 options=nocal,nopass 168 # Now select the hybrid and all-narrowband narrow bands 169 # nb bands require extra step (applying noise source) 170 # we did not bother with noise source for wideband 171 uvcat vis=all.hyb out=$cal.hyb.win$nb.00 "select=-auto,source($cal),win($nb)" \ 172 options=nocal,nopass 173 uvcat vis=all.nb out=$cal.nb.win$nb.00 "select=-auto,source($cal),win($nb)" \ 174 options=nocal,nopass 175 176 # copy wideband passband determined from all-wideband mode to hybrid wideband 177 gpcopy vis=$cal.wide.0 out=$cal.hyb.win$wide.0 options=nocal,nopol 178 uvcat vis=$cal.hyb.win$wide.0 out=$cal.hyb.win$wide options=nocal 179 180 # get the noise source data. Use the noise source data obtained in all 181 # narrowband mode, and assume it also can be applied to hybrid narrowband 182 183 if ($sideband == "USB" || $sideband == "usb" ) then 184 echo " **** PROCESSING USB" 185 rm -r noise.lsb noise.usb 186 @ lsbnb = $nb - 3 187 uvcat vis=all.nb out=noise.lsb "select=-auto,source(NOISE),win($lsbnb)" \ 188 options=nocal,nopass 189 uvcat vis=all.nb out=noise.usb "select=-auto,source(NOISE),win($nb)" \ 190 options=nocal,nopass 191 set sdf = `uvio vis=noise.usb | grep sdf | grep DATA | awk '{print $5}'` 192 set sfreq = `uvio vis=noise.usb | grep sfreq | grep DATA | awk '{if (NR==1) print $5}'` 193 uvcal vis=noise.lsb out=noise.nb.win$nb.00 options=conjugate 194 puthd in=noise.nb.win$nb.00/sfreq value=$sfreq type=d 195 puthd in=noise.nb.win$nb.00/sdf value=$sdf type=d 196 else 197 uvcat vis=all.nb out=noise.nb.win$nb.00 "select=-auto,source(NOISE),win($nb)" \ 198 options=nocal,nopass 199 endif 200 201 # For narrowband windows, first do a passband cal using noise source 202 mfcal vis=noise.nb.win$nb.00 refant=$refant 203 echo "**** Passband cal using noise source" 204 gpplt vis=noise.nb.win$nb.00 device=bpnoise.nb.win$nb.00.ps/ps options=bandpass yaxis=phase nxy=4,4 \ 205 yrange=-90,90 206 gv bpnoise.nb.win$nb.00.ps 207 208 # Copy noise passband to astronomical all-narrowband and hybrid narrowbands, 209 # and apply 210 gpcopy vis=noise.nb.win$nb.00 out=$cal.nb.win$nb.00 options=nocal,nopol 211 gpcopy vis=noise.nb.win$nb.00 out=$cal.hyb.win$nb.00 options=nocal,nopol 212 uvcat vis=$cal.nb.win$nb.00 out=$cal.nb.win$nb.0 options=nocal 213 uvcat vis=$cal.hyb.win$nb.00 out=$cal.hyb.win$nb.0 options=nocal 214 215 # use smamfcal with 1st order polynomial to 216 # get passband on hybrid narrowband and copy to all narrowband 217 smamfcal vis=$cal.hyb.win$nb.0 interval=$calint refant=$refant edge=$edge options=opolyfit \ 218 polyfit=$order 219 echo "**** Hybrid narrowband passband on $cal.hyb.win$nb.0 " 220 gpplt vis=$cal.hyb.win$nb.0 options=bandpass yaxis=phase nxy=4,4 yrange=-90,90 \ 221 device=bp$cal.hyb.win$nb.0.ps/ps 222 gv bp$cal.hyb.win$nb.0.ps 223 224 # Copy narrowband passband from hybrid to all-narrowband mode 225 gpcopy vis=$cal.hyb.win$nb.0 out=$cal.nb.win$nb.0 options=nocal,nopol 226 227 #Check that all-narrowband passband is flat 228 rm -r test.pass 229 uvcat vis=$cal.nb.win$nb.0 out=test.pass 230 mfcal vis=test.pass refant=$refant 231 echo "**** Narrowband passband (should be flat!) on $cal.hyb.win$nb.0 " 232 gpplt vis=test.pass options=bandpass yaxis=phase nxy=4,4 yrange=-90,90 \ 233 device=bptest.ps/ps 234 gv bptest.ps 235 236 # Apply astronomical narrowband passband to hybrid and all-narrowband 237 uvcat vis=$cal.hyb.win$nb.0 out=$cal.hyb.win$nb options=nocal 238 uvcat vis=$cal.nb.win$nb.0 out=$cal.nb.win$nb options=nocal 239 240 # Selfcal on hybrid wideband to remove temporal variations 241 # prior to band offset calibration 242 selfcal vis=$cal.hyb.win$wide line=channel,$wideline \ 243 interval=$calint options=phase refant=$refant 244 245 # Copy selfcal solution over to narrow hybrid band and apply 246 copyhd in=$cal.hyb.win$wide out=$cal.hyb.win$nb items=gains,ngains,nsols,interval 247 uvcat vis=$cal.hyb.win$nb out=$cal.hyb.win$nb.a 248 249 # Selfcal on narrow band of hybrid to determine band offset 250 selfcal vis=$cal.hyb.win$nb.a line=channel,$narrowline \ 251 interval=9999 options=phase refant=$refant 252 echo "**** Band offset between hybrid-narrowband $cal.hyb.win$nb.a" 253 echo "**** and hybrid-wideband $cal.hyb.win$nb" 254 gplist vis=$cal.hyb.win$nb.a options=phase 255 # Also copy band offset to text file 256 gplist vis=$cal.hyb.win$nb.a options=phase >! mnband_offset.$cal.hybwin$nb.txt 257 258 # Test by applying to calibrator observed in all-narrowband mode 259 copyhd in=$cal.hyb.win$nb.a out=$cal.nb.win$nb items=gains,ngains,nsols,interval 260 uvcat vis=$cal.nb.win$nb out=$cal.nb.win$nb.a 261 262 # Remove antenna phase gain using super-wideband 263 rm -r $cal.wide.sw 264 uvcat vis=$cal.wide out=$cal.wide.sw select='win('$superwidewin')' 265 selfcal vis=$cal.wide.sw line=channel,$superwidechan \ 266 interval=9999 options=phase refant=$refant 267 # Copy super-wideband gain to narrowband and apply 268 copyhd in=$cal.wide.sw out=$cal.nb.win$nb.a items=gains,ngains,nsols,interval 269 uvcat vis=$cal.nb.win$nb.a out=$cal.nb.win$nb.a.sc 270 271 # Selfcal to check that phases are roughly zero 272 # to within amount expected given temporal variations over interval 273 # between superwideband and all-narrowband observerations 274 selfcal vis=$cal.nb.win$nb.a.sc line=channel,$narrowline \ 275 interval=9999 options=phase refant=$refant 276 277 # List gains, which should be near zero except for temporal variations 278 # over interval between wideband and narrow band observations of cal 279 echo "**** Phase offset between super-wideband $cal.wide.sw " 280 echo "**** and all-narrow narrow band $cal.nb.win$nb.a.sc " 281 echo "**** Check that phases are near zero, limited by atmospheric flucatuations" 282 gplist vis=$cal.nb.win$nb.a.sc options=phase 283 284 # Now apply calibrations to source data 285 rm -r $source.win$nb* $source.win$nb.bcal 286 # First select source data 287 uvcat vis=all.nb out=$source.win$nb.00 \ 288 "select=-auto,source($source),win($nb)" options=nocal,nopass 289 # Copy and apply noise passband to source 290 gpcopy vis=noise.nb.win$nb.00 out=$source.win$nb.00 options=nocal,nopol 291 uvcat vis=$source.win$nb.00 out=$source.win$nb.0 options=nocal 292 # Copy and apply astronomical passband 293 gpcopy vis=$cal.hyb.win$nb.0 out=$source.win$nb.0 options=nocal,nopol 294 uvcat vis=$source.win$nb.0 out=$source.win$nb options=nocal 295 # Copy band offset to source 296 copyhd in=$cal.hyb.win$nb.a out=$source.win$nb items=gains,ngains,nsols,interval 297 rm -r $source.win_$i 298 # Apply band offset using smachunkglue naming convention 299 uvcat vis=$source.win$nb out=$source.win_$i 300 301 # end nb loop 302 end 303 304 # glue together 3 bands 305 set nblength = $#nb_array 306 307 308 if ($nblength == 2) then 309 set cfile=$source.$nb_array[1]$nb_array[2] 310 rm -r $cfile 311 smachunkglue vis=$source.win nfiles=$nblength out=$cfile 312 uvflag vis=$cfile line=channel,$badchan1 flagval=flag 313 else if ($nblength == 3) then 314 set cfile=$source.$nb_array[1]$nb_array[2]$nb_array[3] 315 rm -r $cfile 316 smachunkglue vis=$source.win nfiles=$nblength out=$cfile 317 # flag bad overlap channels 318 uvflag vis=$cfile line=channel,$badchan1 flagval=flag 319 uvflag vis=$cfile line=channel,$badchan2 flagval=flag 320 else 321 set cfile=$source.$nb_array[1] 322 rm -r $cfile 323 uvcat vis=$source.win out=$cfile 324 endif 325 326 # put in restfreq 327 puthd in=$cfile/restfreq type=double value=$restfreq 328 329 # copy super-wideband gains to source 330 copyhd in=$viscal.v.wide.sw out=$cfile items=gains,ngains,nsols,interval 331 332 echo "Calibrated source file: $cfile"