Determine spectral slope of science source

From CARMA
(Difference between revisions)
Jump to: navigation, search
(Determine Spectral Index of Phase Calibrator)
(Determine Spectral Index of Passband Calibrator)
 
(40 intermediate revisions by one user not shown)
Line 1: Line 1:
These notes are from a project to determine the spectral slope of DG Tau, which is a protostellar object.
+
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)
  
We assume your data has been properly flagged.
+
''These notes are from a project to determine the spectral slope of DG Tau, which is a protostellar object.''
  
There are 16 continuum windows (500 MHz BW) in this example.
+
* We assume your data has been properly flagged.
 +
* There are 16 continuum windows (500 MHz BW, 39 channels) in this example.
  
== Determine Spectral Index of Passband Calibrator ==
+
== Overview ==
 +
1. Determine spectral slope of bandpass calibrator and its flux at some reference frequency.
  
: #! /bin/csh -f
+
2. Determine spectral slope of phase calibrator and its flux at some reference frequency.
  
: #Set variable names
+
3. Determine spectral slope of science sources using the above values to prevent any slope due to calibration process.
: set flux=URANUS
+
: set pass=3C84
+
: set vis=uvdata
+
  
: #Correlator bands
+
== Determine Spectral Index of Passband Calibrator ==
: set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
+
  
: #Brightness temperature of URANUS at our observing frequencies for flux calibration
+
set flux=URANUS # Uranus was our flux calibrator
: #Derived using function provided by A. Isella. He derived it from WMAP data (and references therein).
+
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
 
     #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
 
     #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 )
+
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 at center of this D-array
+
#C8 picked as refant since it is at the center of this D-array and looks good
set refant=8
+
set refant=8
 
+
: #Prepare data
+
#Prepare data
rm -Rf $vis
+
rm -Rf $vis  
uvcat vis=c0800.4D_102HH211.2.miriad out=$vis select="-auto" options=nopass,nocal,nopol
+
uvcat vis=c0800.4D_102HH211.2.miriad out=$vis select="-auto" options=nopass,nocal,nopol
 
+
: #Flag visibility data
+
#Flagging of visibility data already done
  
foreach band ( $bands )   
+
#LOOP OVER ALL 16 BANDS
 +
foreach band ( $bands )   
 
   #Select individual window
 
   #Select individual window
 
   /bin/rm -Rf $vis.$band
 
   /bin/rm -Rf $vis.$band
 
   uvcat vis=$vis out=$vis.$band select="'win($band)'" options=nocal,nopol,nopass
 
   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
 
   #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
 
   mfcal vis=$vis.$band select="source("$pass")" interval=0.1,10000. refant=$refant edge=2 line=chan,39,1,1,1
 
 
   #Check mfcal solution
 
   #Check mfcal solution
   #gpplt vis=$vis.$band yaxis=amp device=1/xs nxy=4,4   
+
   gpplt vis=$vis.$band yaxis=amp device=1/xs nxy=4,4   
   #set text = "Press ENTER .."
+
   gpplt vis=$vis.$band yaxis=phase device=1/xs nxy=4,4 
  #if ($#argv > 0) set text = "$* >>"
+
  #printf "\n$text"
+
  #set junk = ($<)
+
 
+
 
   #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 52: 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=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
 +
  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
 
   
 
   
    #Check selfcal solution for flux source
+
end
 
+
    #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.
  
 
== Determine Spectral Index of Phase Calibrator ==
 
== Determine Spectral Index of Phase Calibrator ==
  
#Set variable names
+
set flux=URANUS # Flux calibrator
set onsource=IRAS4
+
set pass1=3C84 # Passband calibrator
set flux=URANUS
+
set pass2=3C454.3 # Secondary passband calibrator
set pass1=3C84
+
set cal=3C111 # Phase calibrator
set pass2=3C84
+
set vis=uvdata # visibility data
set cal=3C84
+
set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )
set vis=uvdata
+
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 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 )
+
#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
set refant=8
+
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
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
+
gpplt vis=$vis yaxis=amp device=1/xs nxy=4,4 
/bin/rm -Rf $vis.fullpb
+
gpplt vis=$vis yaxis=phase device=1/xs nxy=4,4 
uvcat vis=$vis out=$vis.fullpb options=nopol,nocal
+
#Apply mfcal solution to correct for variation across the bandpass
 
+
/bin/rm -Rf $vis.fullpb
foreach band ($bands)
+
uvcat vis=$vis out=$vis.fullpb options=nopol,nocal
 +
 +
#LOOP OVER ALL 16 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
 +
/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 ==
 +
 +
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
  
end
+
#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
  
/bin/rm -Rf $vis.fullpb
+
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.

Latest revision as of 11: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