# Determine spectral slope of science source

(Difference between revisions)

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) in this example.

## Determine Spectral Index of Passband Calibrator

1. ! /bin/csh -f
1. Set variable names

set flux=URANUS set pass=3C84 set vis=uvdata

1. Correlator bands

set bands = ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )

1. Brightness temperature of URANUS at our observing frequencies for flux calibration
2. Derived using function provided by A. Isella. He derived it from WMAP data (and references therein).
```   #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 )

1. C8 at center of this D-array

set refant=8

1. Prepare data

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

1. Flag visibility data

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
#set text = "Press ENTER .."
#if (\$#argv > 0) set text = "\$* >>"
#printf "\n\$text"
#set junk = (\$<)
```
``` #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 SOURCE 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

#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 SOURCE 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
```
```   #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