Determine spectral slope of science source

From CARMA
(Difference between revisions)
Jump to: navigation, search
(Determine Spectral Index of Passband Calibrator)
 
(23 intermediate revisions by one user not shown)
Line 1: Line 1:
Work in progress! (12/07/2011, Shaye)
+
Work in progress, but the meat is all here now.
 +
There are probably several approaches to this problem, and this is one.
 +
(updated Feb 2012, Shaye)
  
 
''These notes are from a project to determine the spectral slope of DG Tau, which is a protostellar object.''
 
''These notes are from a project to determine the spectral slope of DG Tau, which is a protostellar object.''
Line 18: Line 20:
 
  set pass=3C84 # 3C84 was our passband calibrator
 
  set pass=3C84 # 3C84 was our passband calibrator
 
  set vis=uvdata # this is our visibility data
 
  set vis=uvdata # this is our visibility data
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ) # these are the 16 bands
+
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ) # these are the 16 bands ; on linux `seq 1 16` works as well
 
   
 
   
 
  #Brightness temperature of URANUS at our observing frequencies to be used during flux calibration command "bootflux"
 
  #Brightness temperature of URANUS at our observing frequencies to be used during flux calibration command "bootflux"
Line 47: Line 49:
 
   gpplt vis=$vis.$band yaxis=amp device=1/xs nxy=4,4   
 
   gpplt vis=$vis.$band yaxis=amp device=1/xs nxy=4,4   
 
   gpplt vis=$vis.$band yaxis=phase device=1/xs nxy=4,4   
 
   gpplt vis=$vis.$band yaxis=phase device=1/xs nxy=4,4   
 
 
 
   #Apply mfcal solution to correct for variation across the bandpass
 
   #Apply mfcal solution to correct for variation across the bandpass
 
   /bin/rm -Rf $vis.$band.pb  
 
   /bin/rm -Rf $vis.$band.pb  
Line 53: Line 54:
 
   
 
   
 
   #STARTING STEPS FOR BOOTFLUX  
 
   #STARTING STEPS FOR BOOTFLUX  
   #BANDPASS SOURCE PHASE CALIBRATION
+
 +
   #BANDPASS CALIBRATOR PHASE CALIBRATION
 
   #Run selfcal on bandpass source do derive gain solutions for the bandpass source
 
   #Run selfcal on bandpass source do derive gain solutions for the bandpass source
 
   #Interval can be short since just applying it to the same source (?)
 
   #Interval can be short since just applying it to the same source (?)
 
   mselfcal vis=$vis.$band.pb select="source("$pass")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
 
   mselfcal vis=$vis.$band.pb select="source("$pass")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
 
 
   #Check selfcal solution for bandpass source
 
   #Check selfcal solution for bandpass source
 
   smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
 
 
 
   #Apply selfcal phase solution from the bandpass calibrator to the bandpass calibrator
 
   #Apply selfcal phase solution from the bandpass calibrator to the bandpass calibrator
 
   /bin/rm -Rf $vis.$band.$pass.scp
 
   /bin/rm -Rf $vis.$band.$pass.scp
 
   uvcat vis=$vis.$band.pb out=$vis.$band.$pass.scp select="source("$pass")" options=nopass,nopol
 
   uvcat vis=$vis.$band.pb out=$vis.$band.$pass.scp select="source("$pass")" options=nopass,nopol
 
      
 
      
   #FLUX SOURCE PHASE CALIBRATION
+
   #FLUX CALIBRATOR PHASE CALIBRATION
 
   #Run selfcal on flux source to derive gain solutions for the flux source
 
   #Run selfcal on flux source to derive gain solutions for the flux source
 
   #Interval can be short since just applying it to the same source (?)
 
   #Interval can be short since just applying it to the same source (?)
 
   mselfcal vis=$vis.$band.pb select="source("$flux")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
 
   mselfcal vis=$vis.$band.pb select="source("$flux")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
 
 
 
   #Check selfcal solution for flux source
 
   #Check selfcal solution for flux source
 
   smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
 
   smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
 
 
 
   #Apply selfcal phase solution from the flux calibrator to the flux calibrator
 
   #Apply selfcal phase solution from the flux calibrator to the flux calibrator
 
   /bin/rm -Rf $vis.$band.$flux.scp
 
   /bin/rm -Rf $vis.$band.$flux.scp
Line 85: Line 83:
 
    
 
    
 
   #BOOTFLUX STEP
 
   #BOOTFLUX STEP
    #print out Tb of URANUS at this window
+
  #print out Tb of URANUS at this window
    echo $uranustb[$band]
+
  echo $uranustb[$band]
    #run bootflux and dump output into log file
+
  #run bootflux and dump output into log file
    bootflux vis=$vis.$band.btrdy select="source("$pass,$flux")" line=chan,1,1,39,39 taver=5.01 primary=$flux,$uranustb[$band] badres=70 log=bootfluxJ.$pass.log2
+
  bootflux vis=$vis.$band.btrdy select="source("$pass,$flux")" line=chan,1,1,39,39 taver=5.01 primary=$flux,$uranustb[$band] badres=70 log=bootfluxJ.$pass.log2
    #grep that log file and extract the bootstrapped Average Flux and Flux Error of 3C84 at this window
+
  #grep that log file and extract the bootstrapped Average Flux and Flux Error of 3C84 at this window
    grep Average bootfluxJ.$pass.log2 | grep Flux | cut -c 17-31 > script1_bootflux.$pass.$band
+
  grep Average bootfluxJ.$pass.log2 | grep Flux | cut -c 17-31 > script1_bootflux.$pass.$band
    #print the result to the screen
+
  #print the result to the screen
    set tempfluxpass = `awk 'NR==1' script1_bootflux.$pass.$band`
+
  set tempfluxpass = `awk 'NR==1' script1_bootflux.$pass.$band`
    echo $tempfluxpass
+
  echo $tempfluxpass
 
    
 
    
 
   #clean up
 
   #clean up
Line 100: Line 98:
 
  end
 
  end
  
== Determine Spectral Index of Phase Calibrator ==
+
You now have 16 files representing the flux of your passband calibrator at each band frequency.
 +
Use your favorite program to fit the spectral slope of the passband calibrator and find its flux at some reference frequency.
 +
You will use these three values (slope, reference frequency, flux at the reference frequency) in the next step.
  
set onsource=IRAS4
+
== Determine Spectral Index of Phase Calibrator ==
set flux=URANUS
+
set pass1=3C84
+
set pass2=3C84
+
set cal=3C84
+
set vis=uvdata
+
  
 +
set flux=URANUS # Flux calibrator
 +
set pass1=3C84 # Passband calibrator
 +
set pass2=3C454.3 # Secondary passband calibrator
 +
set cal=3C111 # Phase calibrator
 +
set vis=uvdata # visibility data
 
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
 
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
 
  set uranustb =  ( 124.89169 125.05010 125.20929 125.36919 125.52988 125.69135 125.85355 126.01654 121.49650 121.35417 121.21234 121.07124 120.93065 120.79076 120.65140 120.51263 )
 
  set uranustb =  ( 124.89169 125.05010 125.20929 125.36919 125.52988 125.69135 125.85355 126.01654 121.49650 121.35417 121.21234 121.07124 120.93065 120.79076 120.65140 120.51263 )
 
  set refant=8
 
  set refant=8
 
+
 +
#Run mfcal, using all channels to increase signal to noise, with the "flux" parameter set with values determined in the previous step
 +
#"flux" parameter takes: source flux density, reference frequency (GHz), source spectral index
 
  mfcal vis=$vis select="source("$pass1")" interval=0.1,10000. refant=$refant edge=2 line=chan,624,1,1,1 flux=1.868,103.0,-0.695
 
  mfcal vis=$vis select="source("$pass1")" interval=0.1,10000. refant=$refant edge=2 line=chan,624,1,1,1 flux=1.868,103.0,-0.695
 +
#Check mfcal solution
 +
gpplt vis=$vis yaxis=amp device=1/xs nxy=4,4 
 +
gpplt vis=$vis yaxis=phase device=1/xs nxy=4,4 
 +
#Apply mfcal solution to correct for variation across the bandpass
 
  /bin/rm -Rf $vis.fullpb
 
  /bin/rm -Rf $vis.fullpb
 
  uvcat vis=$vis out=$vis.fullpb options=nopol,nocal
 
  uvcat vis=$vis out=$vis.fullpb options=nopol,nocal
 
+
 +
#LOOP OVER ALL 16 BANDS
 
  foreach band ($bands)
 
  foreach band ($bands)
 
   #Select individual window
 
   #Select individual window
 
   /bin/rm -Rf $vis.$band
 
   /bin/rm -Rf $vis.$band
 
   uvcat vis=$vis.fullpb out=$vis.$band select="'win($band)'" options=nocal,nopol,nopass
 
   uvcat vis=$vis.fullpb out=$vis.$band select="'win($band)'" options=nocal,nopol,nopass
 
+
 
 +
  #Run selfcal on phase calibrator to derive gain solutions for it
 
   mselfcal vis=$vis.$band select="source("$cal")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
 
   mselfcal vis=$vis.$band select="source("$cal")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
   #smagpplt vis=$vis.fullpb yaxis=phase device=3/xs nxy=4,4
+
   #Check selfcal solution for phase calibrator
 +
  smagpplt vis=$vis.fullpb yaxis=phase device=/xs nxy=4,4
 +
  smagpplt vis=$vis.fullpb yaxis=amp device=/xs nxy=4,4
 +
  #Apply selfcal phase solution from the phase calibrator to the phase calibrator
 
   /bin/rm -Rf $vis.$cal.$band.scp
 
   /bin/rm -Rf $vis.$cal.$band.scp
   uvcat vis=$vis.$band out=$vis.$cal.$band.scp select="source("$cal")" options=nopass,nopol  
+
   uvcat vis=$vis.$band out=$vis.$cal.$band.scp select="source("$cal")" options=nopass,nopol
 
+
 
 +
  #Run selfcal on flux calibrator to derive gain solutions for it
 
   mselfcal vis=$vis.$band select="source("$flux")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
 
   mselfcal vis=$vis.$band select="source("$flux")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
   #smagpplt vis=$vis.fullpb yaxis=phase device=3/xs nxy=4,4
+
   #Check selfcal solution for flux calibrator
 +
  smagpplt vis=$vis.fullpb yaxis=phase device=3/xs nxy=4,4
 +
  #Apply selfcal phase solution from the flux calibrator to the flux calibrator 
 
   /bin/rm -Rf $vis.$flux.$band.scp
 
   /bin/rm -Rf $vis.$flux.$band.scp
 
   uvcat vis=$vis.$band out=$vis.$flux.$band.scp select="source("$flux")" options=nopass,nopol  
 
   uvcat vis=$vis.$band out=$vis.$flux.$band.scp select="source("$flux")" options=nopass,nopol  
 
+
 
 +
  #UVCAT bandpass and phase corrected visiblity data for the PHASE and FLUX calibrator together
 +
  #This is the visibility file to use in bootflux
 
   /bin/rm -Rf $vis.$band.btrdy
 
   /bin/rm -Rf $vis.$band.btrdy
 
   uvcat vis=$vis.$cal.$band.scp,$vis.$flux.$band.scp out=$vis.$band.btrdy options=nopass,nopol,nocal
 
   uvcat vis=$vis.$cal.$band.scp,$vis.$flux.$band.scp out=$vis.$band.btrdy options=nopass,nopol,nocal
 
+
 
 
   bootflux vis=$vis.$band.btrdy select="source("$cal,$flux")" line=chan,1,1,39,39 taver=5.01 badres=70 primary=$flux,$uranustb[$band] log=bootfluxJ.$cal.log2
 
   bootflux vis=$vis.$band.btrdy select="source("$cal,$flux")" line=chan,1,1,39,39 taver=5.01 badres=70 primary=$flux,$uranustb[$band] log=bootfluxJ.$cal.log2
 
   grep Average bootfluxJ.$cal.log2 | grep Flux | cut -c 17-31 > script2_bootflux.$cal.$band
 
   grep Average bootfluxJ.$cal.log2 | grep Flux | cut -c 17-31 > script2_bootflux.$cal.$band
 
   set tempfluxcal = `awk 'NR==1' script2_bootflux.$cal.$band`
 
   set tempfluxcal = `awk 'NR==1' script2_bootflux.$cal.$band`
 
   echo $tempfluxcal
 
   echo $tempfluxcal
   
+
 
 
   /bin/rm -Rf $vis.$band $vis.$cal.$band.scp $vis.$flux.$band.scp $vis.$band.btrdy
 
   /bin/rm -Rf $vis.$band $vis.$cal.$band.scp $vis.$flux.$band.scp $vis.$band.btrdy
 
   /bin/rm -Rf bootfluxJ.$cal.log2
 
   /bin/rm -Rf bootfluxJ.$cal.log2
 
+
 
  end
 
  end
 
 
  /bin/rm -Rf $vis.fullpb
 
  /bin/rm -Rf $vis.fullpb
  
 +
You now have 16 files representing the flux of your phase calibrator at each band frequency.
 +
Use your favorite program to fit the spectral slope of the passband calibrator and find its flux at some reference frequency.
 +
You will use these three values (slope, reference frequency, flux at the reference frequency) in the next step.
  
 
== Determine Spectral Index of Science Source ==
 
== Determine Spectral Index of Science Source ==
  
  set onsource=IRAS03
+
  set onsource=DGTAU #unresolved science target
  set flux=URANUS
+
  set flux=URANUS #flux calibrator
  set cal=3C84
+
  set cal=3C111 #phase calibrator
  set vis=uvdata
+
set pass1=3C84 #passband calibrator
 
+
  set vis=uvdata #visibility data
 
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
 
  set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
 
  set uranustb = ( 125.027 125.201 125.376 125.552 125.729 125.906 126.085 126.265 121.987 121.829 121.672 121.515 121.360 121.204 121.050 120.896 )
 
  set uranustb = ( 125.027 125.201 125.376 125.552 125.729 125.906 126.085 126.265 121.987 121.829 121.672 121.515 121.360 121.204 121.050 120.896 )
set sources = ( IRAS03 B1c HH211 IRAS2A )
 
 
  set refant=8
 
  set refant=8
 +
 +
#Flux derived for phase calibrator in steps above
 
  set fg=11.868
 
  set fg=11.868
  
  foreach onsource ( $sources )
+
  #Run mfcal, using all channels to increase signal to noise, with the "flux" parameter set with values determined in the first step
    mfcal vis=$vis select="source("$cal")" interval=0.1,10000. refant=$refant edge=2 line=chan,624,1,1,1 flux=11.868,103.0,-0.695
+
mfcal vis=$vis.uflag select="source("$pass1")" interval=0.1,100000. refant=10 edge=2 line=chan,624,1,1,1 flux=18.755055,104.0,-0.5073
    /bin/rm -Rf $vis.fullpb
+
/bin/rm -Rf $vis.fullpb  
    uvcat vis=$vis out=$vis.fullpb options=nopol,nocal
+
uvcat vis=$vis.uflag out=$vis.fullpb options=nopol,nocal
 +
#Run phase selfcal on the phase calibrator to be applied to the target source
 +
mselfcal vis=$vis.fullpb select="source("$cal")" interval=18.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,624,624
 +
smauvplt vis=$vis.fullpb axis=time,phase device=/xs yrange=-180,180 nxy=1,1 options=nobase
 +
/bin/rm -Rf $vis.scp
 +
uvcat vis=$vis.fullpb select="source("$cal,$onsource,$pass1")" out=$vis.scp options=nopass,nopol
 +
#Run amplitude selfcal on phase calibrator to be applied to the target source
 +
#Input the flux of the phase calibrator derived from previous step
 +
#(Don't we need to account for the slope of the phase calibrator?)
 +
mselfcal vis=$vis.scp select="source("$cal")" interval=40.01 options=noscale,amplitude refant=$refant line=chan,1,1,624,624 flux=$fg
 +
/bin/rm -Rf $vis.scpa
 +
uvcat vis=$vis.scp select="source("$cal,$onsource,$pass1")" out=$vis.scpa options=nopass,nopol
 +
#Now our science target has been calibrated completely.
 +
#If the source is alone in the primary beam, we can use uvamp on each band to determine the amplitude (Jy) in that band
 +
#Let's do this for the science source, the phase calibrator, and the passband calibrator
 +
foreach band ($bands)
 +
  uvamp vis=$vis.scpa select="source("$onsource"),win("$band")" bin=1,50,klam log=script3_uvamp.$onsource.$band
 +
  uvamp vis=$vis.scpa select="source("$cal"),win("$band")" bin=1,50,klam log=script3_uvamp.$cal.$band
 +
  uvamp vis=$vis.scpa select="source("$pass1"),win("$band")" bin=1,50,klam log=script3_uvamp.$pass1.$band
 +
end
 +
#clean up
 +
/bin/rm -Rf $vis.fullpb $vis.scp $vis.scpa
  
    mselfcal vis=$vis.fullpb select="source("$cal")" interval=18.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,624,624
+
You now have 16 files representing the flux of your science source at each band frequency.  
    /bin/rm -Rf $vis.scp
+
Use your favorite program to fit the spectral slope of the science source.
    uvcat vis=$vis.fullpb select="source("$cal,$onsource")" out=$vis.scp options=nopass,nopol
+
 
+
    mselfcal vis=$vis.scp select="source("$cal")" interval=40.01 options=noscale,amplitude refant=$refant line=chan,1,1,624,624 flux=$fg
+
    /bin/rm -Rf $vis.$onsource.scpa
+
    uvcat vis=$vis.scp select="source("$cal,$onsource")" out=$vis.$onsource.scpa options=nopass,nopol
+
 
+
    #Remove DGTAUB with uvmodel
+
    #/bin/rm -Rf $vis.scpam $vis.scpam2 $vis.calibrators $vis.scpamf
+
    #uvmodel vis=$vis.scpa out=$vis.scpam select="source("$onsource")" options=subtract flux=0.015 offset=-28.592,-45.934
+
    #uvmodel vis=$vis.scpam out=$vis.scpam2 select="source("$onsource")" options=subtract flux=0.0010 offset=-28.887,-43.999
+
    #uvcat vis=$vis.scpa out=$vis.calibrators select="source("$cal,$pass1,$pass2")" options=nopass,nocal,nopol
+
    #uvcat vis=$vis.calibrators,$vis.scpam2 out=$vis.scpamf options=nopass,nocal,nopol
+
   
+
    #Make image of IRAS2A to see peak flux is at expected phase center
+
    /bin/rm -Rf $vis.fullmap $vis.fullbm $vis.fullcln $vis.$onsource.scpamres
+
    invert vis=$vis.$onsource.scpa select="source("$onsource")" map=$vis.fullmap beam=$vis.fullbm imsize=257,257 cell=1,1 options=systemp robust=0 line=chan,1,1,624,624
+
    clean map=$vis.fullmap beam=$vis.fullbm out=$vis.fullcln gain=0.1 niters=2000
+
    restor model=$vis.fullcln beam=$vis.fullbm map=$vis.fullmap out=$vis.$onsource.scpamres
+
 
+
    #Is phase center of DGTau where expected?
+
    #imhead in=$vis.scpamres > script3_imhead
+
    #imfit in=$vis.scpamres object=gaussian region="rel,box(-20,-20,21,21)" > script3_imfit.tbl
+
   
+
    #extract ra and dec position of center position from imfit
+
    #grep Declination script3_imfit.tbl | cut -c 35-36 > script3_deccenter1
+
    #grep Declination script3_imfit.tbl | cut -c 38-39 > script3_deccenter2
+
    #grep Declination script3_imfit.tbl | cut -c 41-46 > script3_deccenter3
+
    #set deccenterval1 = `awk 'NR==1' script3_deccenter1`
+
    #set deccenterval2 = `awk 'NR==1' script3_deccenter2`
+
    #set deccenterval3 = `awk 'NR==1' script3_deccenter3`
+
    #grep Ascension script3_imfit.tbl | cut -c 30-35 > script3_racenter1
+
    #grep Ascension script3_imfit.tbl | cut -c 37-38 > script3_racenter2
+
    #grep Ascension script3_imfit.tbl | cut -c 40-45 > script3_racenter3
+
    #set racenterval1 = `awk 'NR==1' script3_racenter1`
+
    #set racenterval2 = `awk 'NR==1' script3_racenter2`
+
    #set racenterval3 = `awk 'NR==1' script3_racenter3`
+
    #Correct phase center
+
    #/bin/rm -Rf temp.scpamf
+
    #uvedit vis=$vis.scpamf out=temp.scpamf source=$onsource ra=$racenterval1,$racenterval2,$racenterval3 dec=$deccenterval1,$deccenterval2,$deccenterval3 options=nouv
+
    #/bin/rm -Rf $vis.scpamf
+
    #uvcat vis=temp.scpamf out=$vis.scpamf options=nopass,nocal,nopol
+
   
+
    foreach band ($bands)
+
    uvamp vis=$vis.$onsource.scpa select="source("$onsource"),win("$band")" bin=10,5,klam log=script3_uvamp.$onsource.$band
+
    uvamp vis=$vis.$onsource.scpa select="source("$cal"),win("$band")" bin=1,50,klam log=script3_uvamp.$cal.$band
+
    end
+
   
+
    /bin/rm -Rf $vis.fullpb $vis.scp
+
    /bin/rm -Rf $vis.scpam $vis.scpam2 $vis.calibrators
+
    /bin/rm -Rf $vis.fullmap $vis.fullbm $vis.fullcln $vis.scpamres
+
    /bin/rm -Rf temp.scpamf
+
+
end
+

Latest revision as of 12:48, 23 February 2012

Work in progress, but the meat is all here now. There are probably several approaches to this problem, and this is one. (updated Feb 2012, Shaye)

These notes are from a project to determine the spectral slope of DG Tau, which is a protostellar object.

  • We assume your data has been properly flagged.
  • There are 16 continuum windows (500 MHz BW, 39 channels) in this example.

Contents

[edit] Overview

1. Determine spectral slope of bandpass calibrator and its flux at some reference frequency.

2. Determine spectral slope of phase calibrator and its flux at some reference frequency.

3. Determine spectral slope of science sources using the above values to prevent any slope due to calibration process.

[edit] Determine Spectral Index of Passband Calibrator

set flux=URANUS # Uranus was our flux calibrator
set pass=3C84 # 3C84 was our passband calibrator
set vis=uvdata # this is our visibility data
set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ) # these are the 16 bands  ; on linux `seq 1 16` works as well

#Brightness temperature of URANUS at our observing frequencies to be used during flux calibration command "bootflux"
#Derived using function provided by A. Isella. He derived it from WMAP data (and references therein).
#We hope this is more accurate than the models provided in Miriad. 
   #Tb=b1 + b2*log(x) + b3*log(x)^2 + b4*log(x)^3
   #b1=154.813 b2=106.598 b3=-91.0474 b4=15.0796
set uranustb = ( 125.02683 125.20088 125.37588 125.55175 125.72856 125.90630 126.08495 126.26458 121.98721 121.82910 121.67174 121.51508 121.35952 121.20437 121.04997 120.89625 )

#C8 picked as refant since it is at the center of this D-array and looks good
set refant=8

#Prepare data
rm -Rf $vis 
uvcat vis=c0800.4D_102HH211.2.miriad out=$vis select="-auto" options=nopass,nocal,nopol

#Flagging of visibility data already done
#LOOP OVER ALL 16 BANDS
foreach band ( $bands )  
 #Select individual window
 /bin/rm -Rf $vis.$band
 uvcat vis=$vis out=$vis.$band select="'win($band)'" options=nocal,nopol,nopass
 
 #Run mfcal on this window on very short timescale to minimize decorrelation
 mfcal vis=$vis.$band select="source("$pass")" interval=0.1,10000. refant=$refant edge=2 line=chan,39,1,1,1
 #Check mfcal solution
 gpplt vis=$vis.$band yaxis=amp device=1/xs nxy=4,4  
 gpplt vis=$vis.$band yaxis=phase device=1/xs nxy=4,4  
 #Apply mfcal solution to correct for variation across the bandpass
 /bin/rm -Rf $vis.$band.pb 
 uvcat vis=$vis.$band out=$vis.$band.pb options=nocal,nopol

 #STARTING STEPS FOR BOOTFLUX 

  #BANDPASS CALIBRATOR PHASE CALIBRATION
  #Run selfcal on bandpass source do derive gain solutions for the bandpass source
  #Interval can be short since just applying it to the same source (?)
  mselfcal vis=$vis.$band.pb select="source("$pass")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
  #Check selfcal solution for bandpass source
  smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
  smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
  #Apply selfcal phase solution from the bandpass calibrator to the bandpass calibrator
  /bin/rm -Rf $vis.$band.$pass.scp
  uvcat vis=$vis.$band.pb out=$vis.$band.$pass.scp select="source("$pass")" options=nopass,nopol
   
  #FLUX CALIBRATOR PHASE CALIBRATION
  #Run selfcal on flux source to derive gain solutions for the flux source
  #Interval can be short since just applying it to the same source (?)
  mselfcal vis=$vis.$band.pb select="source("$flux")" interval=1.01 options=apriori,noscale,phase refant=$refant line=chan,1,1,39,39
  #Check selfcal solution for flux source
  smagpplt vis=$vis.$band.pb  yaxis=phase device=/xs nxy=4,4
  smagpplt vis=$vis.$band.pb  yaxis=amp device=/xs nxy=4,4
  #Apply selfcal phase solution from the flux calibrator to the flux calibrator
  /bin/rm -Rf $vis.$band.$flux.scp
  uvcat vis=$vis.$band.pb out=$vis.$band.$flux.scp select="source("$flux")" options=nopass,nopol
  
  #UVCAT bandpass and phase corrected visiblity data for the BANDPASS and FLUX calibrator together
  #This is the visibility file to use in bootflux
  /bin/rm -Rf $vis.$band.btrdy
  uvcat vis=$vis.$band.$pass.scp,$vis.$band.$flux.scp out=$vis.$band.btrdy options=nopass,nopol,nocal
  
  #BOOTFLUX STEP
  #print out Tb of URANUS at this window
  echo $uranustb[$band]
  #run bootflux and dump output into log file
  bootflux vis=$vis.$band.btrdy select="source("$pass,$flux")" line=chan,1,1,39,39 taver=5.01 primary=$flux,$uranustb[$band] badres=70 log=bootfluxJ.$pass.log2
  #grep that log file and extract the bootstrapped Average Flux and Flux Error of 3C84 at this window
  grep Average bootfluxJ.$pass.log2 | grep Flux | cut -c 17-31 > script1_bootflux.$pass.$band
  #print the result to the screen
  set tempfluxpass = `awk 'NR==1' script1_bootflux.$pass.$band`
  echo $tempfluxpass
  
  #clean up
  /bin/rm -Rf $vis.$band $vis.$band.pb $vis.$band.$pass.scp $vis.$band.$flux.scp $vis.$band.btrdy bootflux.$pass.log2

end
You now have 16 files representing the flux of your passband calibrator at each band frequency. 
Use your favorite program to fit the spectral slope of the passband calibrator and find its flux at some reference frequency. 
You will use these three values (slope, reference frequency, flux at the reference frequency) in the next step.

[edit] Determine Spectral Index of Phase Calibrator

set flux=URANUS # Flux calibrator
set pass1=3C84 # Passband calibrator
set pass2=3C454.3 # Secondary passband calibrator 
set cal=3C111 # Phase calibrator
set vis=uvdata # visibility data
set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
set uranustb =  ( 124.89169 125.05010 125.20929 125.36919 125.52988 125.69135 125.85355 126.01654 121.49650 121.35417 121.21234 121.07124 120.93065 120.79076 120.65140 120.51263 )
set refant=8

#Run mfcal, using all channels to increase signal to noise, with the "flux" parameter set with values determined in the previous step
#"flux" parameter takes: source flux density, reference frequency (GHz), source spectral index
mfcal vis=$vis select="source("$pass1")" interval=0.1,10000. refant=$refant edge=2 line=chan,624,1,1,1 flux=1.868,103.0,-0.695
#Check mfcal solution
gpplt vis=$vis yaxis=amp device=1/xs nxy=4,4  
gpplt vis=$vis yaxis=phase device=1/xs nxy=4,4  
#Apply mfcal solution to correct for variation across the bandpass
/bin/rm -Rf $vis.fullpb
uvcat vis=$vis out=$vis.fullpb options=nopol,nocal

#LOOP OVER ALL 16 BANDS
foreach band ($bands)
 #Select individual window
 /bin/rm -Rf $vis.$band
 uvcat vis=$vis.fullpb out=$vis.$band select="'win($band)'" options=nocal,nopol,nopass
 
 #Run selfcal on phase calibrator to derive gain solutions for it
 mselfcal vis=$vis.$band select="source("$cal")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
 #Check selfcal solution for phase calibrator
 smagpplt vis=$vis.fullpb yaxis=phase device=/xs nxy=4,4
 smagpplt vis=$vis.fullpb yaxis=amp device=/xs nxy=4,4
 #Apply selfcal phase solution from the phase calibrator to the phase calibrator
 /bin/rm -Rf $vis.$cal.$band.scp
 uvcat vis=$vis.$band out=$vis.$cal.$band.scp select="source("$cal")" options=nopass,nopol
 
 #Run selfcal on flux calibrator to derive gain solutions for it
 mselfcal vis=$vis.$band select="source("$flux")" interval=1.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,39,39
 #Check selfcal solution for flux calibrator
 smagpplt vis=$vis.fullpb yaxis=phase device=3/xs nxy=4,4
 #Apply selfcal phase solution from the flux calibrator to the flux calibrator  
 /bin/rm -Rf $vis.$flux.$band.scp
 uvcat vis=$vis.$band out=$vis.$flux.$band.scp select="source("$flux")" options=nopass,nopol 
 
 #UVCAT bandpass and phase corrected visiblity data for the PHASE and FLUX calibrator together
 #This is the visibility file to use in bootflux
 /bin/rm -Rf $vis.$band.btrdy
 uvcat vis=$vis.$cal.$band.scp,$vis.$flux.$band.scp out=$vis.$band.btrdy options=nopass,nopol,nocal
 
 bootflux vis=$vis.$band.btrdy select="source("$cal,$flux")" line=chan,1,1,39,39 taver=5.01 badres=70 primary=$flux,$uranustb[$band] log=bootfluxJ.$cal.log2
 grep Average bootfluxJ.$cal.log2 | grep Flux | cut -c 17-31 > script2_bootflux.$cal.$band
 set tempfluxcal = `awk 'NR==1' script2_bootflux.$cal.$band`
 echo $tempfluxcal
 
 /bin/rm -Rf $vis.$band $vis.$cal.$band.scp $vis.$flux.$band.scp $vis.$band.btrdy
 /bin/rm -Rf bootfluxJ.$cal.log2

end
/bin/rm -Rf $vis.fullpb
You now have 16 files representing the flux of your phase calibrator at each band frequency. 
Use your favorite program to fit the spectral slope of the passband calibrator and find its flux at some reference frequency. 
You will use these three values (slope, reference frequency, flux at the reference frequency) in the next step.

[edit] Determine Spectral Index of Science Source

set onsource=DGTAU #unresolved science target
set flux=URANUS #flux calibrator
set cal=3C111 #phase calibrator
set pass1=3C84 #passband calibrator
set vis=uvdata #visibility data
set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
set uranustb = ( 125.027 125.201 125.376 125.552 125.729 125.906 126.085 126.265 121.987 121.829 121.672 121.515 121.360 121.204 121.050 120.896 )
set refant=8
#Flux derived for phase calibrator in steps above
set fg=11.868
#Run mfcal, using all channels to increase signal to noise, with the "flux" parameter set with values determined in the first step
mfcal vis=$vis.uflag select="source("$pass1")" interval=0.1,100000. refant=10 edge=2 line=chan,624,1,1,1 flux=18.755055,104.0,-0.5073
/bin/rm -Rf $vis.fullpb 
uvcat vis=$vis.uflag out=$vis.fullpb options=nopol,nocal
#Run phase selfcal on the phase calibrator to be applied to the target source
mselfcal vis=$vis.fullpb select="source("$cal")" interval=18.01 options=noscale,phase,apriori refant=$refant line=chan,1,1,624,624
smauvplt vis=$vis.fullpb axis=time,phase device=/xs yrange=-180,180 nxy=1,1 options=nobase 
/bin/rm -Rf $vis.scp
uvcat vis=$vis.fullpb select="source("$cal,$onsource,$pass1")" out=$vis.scp options=nopass,nopol
#Run amplitude selfcal on phase calibrator to be applied to the target source
#Input the flux of the phase calibrator derived from previous step
#(Don't we need to account for the slope of the phase calibrator?)
mselfcal vis=$vis.scp select="source("$cal")" interval=40.01 options=noscale,amplitude refant=$refant line=chan,1,1,624,624 flux=$fg
/bin/rm -Rf $vis.scpa 
uvcat vis=$vis.scp select="source("$cal,$onsource,$pass1")" out=$vis.scpa options=nopass,nopol
#Now our science target has been calibrated completely.
#If the source is alone in the primary beam, we can use uvamp on each band to determine the amplitude (Jy) in that band
#Let's do this for the science source, the phase calibrator, and the passband calibrator
foreach band ($bands)
 uvamp vis=$vis.scpa select="source("$onsource"),win("$band")" bin=1,50,klam log=script3_uvamp.$onsource.$band
 uvamp vis=$vis.scpa select="source("$cal"),win("$band")" bin=1,50,klam log=script3_uvamp.$cal.$band
 uvamp vis=$vis.scpa select="source("$pass1"),win("$band")" bin=1,50,klam log=script3_uvamp.$pass1.$band
end
#clean up
/bin/rm -Rf $vis.fullpb $vis.scp $vis.scpa
You now have 16 files representing the flux of your science source at each band frequency. 
Use your favorite program to fit the spectral slope of the science source.
Personal tools