GreenBankObservatory / dysh

https://dysh.readthedocs.io
Other
9 stars 3 forks source link

implement VEGAS channel flagging #30

Open mpound opened 1 year ago

mpound commented 1 year ago

per discussion, a preprocessing step that flags certain VEGAS backend channels may be needed before calibration. COMMENT Columns describing VEGAS spur locations 
 COMMENT SPUR_CHANNEL = (J-VSPRVAL)*VSPDELT+VSPRPIX

COMMENT 0 <= J <= 32 
 COMMENT spur channels are along the frequency axis

where VSP* keywords are in the FITS bintable header. Also need to check primary HDU header for INSTRUMEN and bintable header for BACKEND

..the data value at the location of the central VEGAS ADC spur is replaced by the average of the two adjacent channels and hence does not need to be flagged (sdfits also does not flag that spur). A new keyword, flagcenteradc, was added to enable flagging of that spur by this routine." 
https://safe.nrao.edu/wiki/bin/view/GB/Software/GbtidlReleaseNotes_2_10_1

mpound commented 9 months ago

This needs to be changed to Q9 when we have all the milestones annotated.

astrofle commented 3 months ago

Just to confirm that this is doable. The location of the VEGAS channels that need to be flagged can be retrieved using:

fitsfile = "/home/dysh/acceptance_testing/data/AGBT15B_244_07/AGBT15B_244_07.raw.vegas/AGBT15B_244_07.raw.vegas.A.fits"
hdu = fits.open(fitsfile)
table = hdu[1].data
chans = [(j-table["VSPRVAL"][0])*table["VSPDELT"][0]+table["VSPRPIX"][0] - 1 for j in range(0,33)]
print(chans, len(table["DATA"][0]), set(table["IFNUM"]))

chans matches the spurious channels as indicated in the .flag file (/home/dysh/acceptance_testing/data/AGBT15B_244_07/AGBT15B_244_07.raw.vegas/AGBT15B_244_07.raw.vegas.A.flag).

For files with multiple windows in one VEGAS bank, it seems that the flag file is missing some spurs.

import numpy as np
from astropy.io import fits

fitsfile = "/home/dysh/acceptance_testing/data/AGBT18B_014_02/AGBT18B_014_02.raw.vegas/AGBT18B_014_02.raw.vegas.A.fits"
hdu = fits.open(fitsfile)
table = hdu[1].data
arr = np.array([np.arange(33.0)]*len(table))
nchan = len(table["DATA"][0])
schans = table["VSPRPIX"][:,np.newaxis] + table["VSPDELT"][:,np.newaxis] * (arr - table["VSPRVAL"][:,np.newaxis]) - 1
spurMask = (schans > 0) & (schans <= nchan)
spurMask1D = np.any(spurMask, axis=1)
print(table["IFNUM"][spurMask1D][::4][:5], schans[spurMask][::4][:5])
[1 3 4 5 6] [5888. 3072. 1216. 1088. 7872.]

The flag file is missing the flagged channel for window 3: 3072.