In [1]:
%matplotlib inline
In [2]:
import os.path
import pylab as pl
import numpy as np
import pwkit.environments.casa.tasks as tasks
import pwkit.environments.casa.util as util
from astropy import coordinates, units
qa = util.tools.quanta()
me = util.tools.measures()
In [3]:
# define functions
def convertms(sdmfile, msfile, scan):
%sx asdm2MS $sdmfile $msfile -s $scan
def applycal(msfile, gaintables, gainfield=None, targetfield=None, interp=None):
if not gainfield:
gainfield = ['' for _ in range(len(gaintables))]
if not interp:
interp = ['' for _ in range(len(gaintables))]
if not targetfield:
targetfield = '1'
cfg = tasks.ApplycalConfig()
cfg.vis = msfile
cfg.gaintable = gaintables
cfg.gainfield = gainfield
cfg.field = targetfield
cfg.interp = interp
cfg.calwt = [False]
tasks.applycal(cfg)
def makeimage(msfile, field='1', niter=50, cell=0.25, npix=4096, spw=''):
%sx rm -rf $msfile?*
cfg = tasks.MfscleanConfig()
cfg.vis = msfile
cfg.imbase = msfile
cfg.field = field
cfg.niter = niter
cfg.stokes = 'I'
cfg.cell = cell
cfg.imsize = [npix, npix]
cfg.spw = spw
tasks.mfsclean(cfg)
def fitimage(image, displaywindow=100, fitwindow=100, returnimfit=False):
# load image
ia = util.tools.image()
ia.open(image)
# summarize image
dd = ia.summary()
npixx,npixy,nch,npol = dd['shape']
print('Image shape: {0}'.format(dd['shape']))
imvals = ia.getchunk(0, int(npixx))[:,:,0,0]
peakx, peaky = np.where(imvals.max() == imvals)
print('Peak SNR at ({0},{1}) = {2}'.format(peakx[0], peaky[0], imvals.max()/imvals.std()))
print('Beam shape: {0}'.format(ia.history()[1].split('\n')[10].split(':')[5]))
# fit component and write residual image
box = '{0},{1},{2},{3}'.format(peakx[0]-fitwindow/2, peaky[0]-fitwindow/2,
peakx[0]+fitwindow/2, peaky[0]+fitwindow/2)
imfit = ia.fitcomponents(box=box, residual=msfile + 'fitresid')
# report on fit
if imfit['converged']:
print('{0} element(s) fit'.format(imfit['results']['nelements']))
direction = imfit['results']['component0']['shape']['direction']
az = direction['m0']['value']
el = direction['m1']['value']
az_err = direction['error']['latitude']['value']
el_err = direction['error']['longitude']['value']
peak_ra = qa.formxxx(qa.angle(qa.quantity(az, unitname='rad'), prec=9)[0], format='hms')
peak_dec = qa.formxxx(qa.angle(qa.quantity(el, unitname='rad'), prec=9)[0], format='dms')
print('{0} +- {1}"'.format(peak_ra, az_err))
print('{0} +- {1}"'.format(peak_dec, el_err))
print('Fiteak flux: {0} Jy'.format(imfit['results']['component0']['peak']['value']))
else:
print('fitcomponents did not converge')
# load residuals
ia = util.tools.image()
ia.open(msfile + 'fitresid')
dd = ia.summary()
npixx,npixy,nch,npol = dd['shape']
residvals = ia.getchunk(0, int(npixx))[:,:,0,0]
peakx_resid, peaky_resid = np.where(residvals.max() == residvals)
print('Residual SNR at ({0},{1}) = {2}'.format(peakx_resid[0], peaky_resid[0], residvals.max()/residvals.std()))
# show results
pl.figure(figsize=(15,8))
pl.subplot(131)
pl.imshow(np.log(imvals.transpose() - imvals.min()), interpolation='nearest', origin='bottom')
pl.colorbar()
pl.subplot(132)
pl.imshow(imvals[peakx[0]-displaywindow/2:peakx[0]+displaywindow/2,
peaky[0]-displaywindow/2:peaky[0]+displaywindow/2],
interpolation='nearest', origin='bottom')
pl.colorbar()
pl.subplot(133)
pl.imshow(residvals[peakx[0]-displaywindow/2:peakx[0]+displaywindow/2,
peaky[0]-displaywindow/2:peaky[0]+displaywindow/2],
interpolation='nearest', origin='bottom')
pl.colorbar()
if returnimfit:
return imfit
else:
return az, el, az_err, el_err
def getimage(image):
# load image
ia = util.tools.image()
ia.open(image)
# summarize image
dd = ia.summary()
npixx,npixy,nch,npol = dd['shape']
print('Image shape: {0}'.format(dd['shape']))
imvals = ia.getchunk(0, int(npixx))[:,:,0,0]
peakx, peaky = np.where(imvals.max() == imvals)
print('Peak SNR at pix ({0},{1}) = {2}'.format(peakx[0], peaky[0], imvals.max()/imvals.std()))
print('Beam shape: {0}'.format(ia.history()[1].split('\n')[10].split(':')[5]))
return imvals
In [4]:
fits = {}
In [7]:
cd ~/16A-459/fastimaging/
In [8]:
#bdf_dedisperse_cut.py -i 6:36024:1 -d 565.0 16A-459_TEST_1hr.57623.72670021991
sdmfile = '16A-459_TEST_1hr.57623.72670021991.ddcut'
msfile = sdmfile + 'ms'
scan = 6
caltables = ['../pipeline/57623/caltables/cal_57623_3s.G4', '../pipeline/57623/caltables/cal_57623_3s.K4',
'../pipeline/57623/caltables/cal_57623_3s.B4', '../pipeline/57623/caltables/selfcal.g0']
In [9]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield, gainfield=['0','','', ''], interp=['linear','','', ''])
makeimage(msfile, field=targetfield, niter=30)
In [10]:
# peak is lower than expected... redo ddcut?
# selcal solution available as selfcal.g0
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57623'] = (az, el, az_err, el_err)
In [7]:
# bdf_dedisperse_cut.py -i 7:9514:3 -d 557.0 -e scan7.ddcut 16A-459_TEST_1hr_000.57633.66130137732
sdmfile = '16A-459_TEST_1hr_000.57633.66130137732.scan7.ddcut'
msfile = sdmfile + 'ms'
scan = 7
caltables = ['../pipeline/57633/caltables/cal_57633_3s.G1', '../pipeline/57633/caltables/cal_57633_3s.K1',
'../pipeline/57633/caltables/cal_57633_3s.B1']
In [9]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield, gainfield=['0','',''], interp=['linear','',''])
makeimage(msfile, field=targetfield, niter=30)
In [8]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57633_scan7'] = (az, el, az_err, el_err)
In [9]:
# bdf_dedisperse_cut.py -i 13:10544:1 -d 560.0 -e scan13.ddcut 16A-459_TEST_1hr_000.57633.66130137732
sdmfile = '16A-459_TEST_1hr_000.57633.66130137732.scan13.ddcut'
msfile = sdmfile + 'ms'
scan = 13
caltables = ['../pipeline/57633/caltables/cal_57633_3s.G1', '../pipeline/57633/caltables/cal_57633_3s.K1',
'../pipeline/57633/caltables/cal_57633_3s.B1']
In [15]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield, gainfield=['0','',''], interp=['linear','',''])
makeimage(msfile, field=targetfield, niter=30)
In [12]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57633_scan13'] = (az, el, az_err, el_err)
In [11]:
# no strong source in the image. applycal not right?
fits.pop('57633_scan13')
Out[11]:
In [13]:
#
sdmfile = '16A-496_sb32698778_1_02h00m.57638.42695471065.ddcut'
msfile = sdmfile + 'ms'
scan = 29
caltables = ['../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.finaldelay.k',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.finalBPcal.b',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.averagephasegain.g',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.finalampgaincal.g',
'../pipeline/57638/caltables/16A-496_sb32698778_1_02h00m.57638.42695471065.avg.ms.finalphasegaincal.g']
In [19]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
makeimage(msfile, field=targetfield, niter=30)
In [14]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57638'] = (az, el, az_err, el_err)
In [15]:
# bdf_dedisperse_cut.py -i 29:5849:1 -d 560.0 16A-496_sb32698778_1_02h00m_001.57643.38562630787
sdmfile = '16A-496_sb32698778_1_02h00m_001.57643.38562630787.ddcut'
msfile = sdmfile + 'ms'
scan = 29
caltables = ['../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.finaldelay.k',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.finalBPcal.b',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.averagephasegain.g',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.finalampgaincal.g',
'../pipeline/57643/caltables/16A-496_sb32698778_1_02h00m_001.57643.38562630787.avg.ms.finalphasegaincal.g']
In [22]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
makeimage(msfile, field=targetfield, niter=30)
In [16]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57643'] = (az, el, az_err, el_err)
In [17]:
# bdf_dedisperse_cut.py -i 16:7526:1 -d 546 16A-496_sb32698778_1_02h00m.57645.38915079861
sdmfile = '16A-496_sb32698778_1_02h00m.57645.38915079861.ddcut'
msfile = sdmfile + 'ms'
scan = 16
caltables = ['../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.hifv_priorcals.s5_6.ants.tbl',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.finaldelay.k',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.finalBPcal.b',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.averagephasegain.g',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.finalampgaincal.g',
'../pipeline/57645/caltables/16A-496_sb32698778_1_02h00m.57645.38915079861.avg.ms.finalphasegaincal.g']
In [25]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
In [26]:
makeimage(msfile, field=targetfield, cell=0.15, spw='0:10~32,1~7')
In [18]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=30)
fits['57645'] = (az, el, az_err, el_err)
In [19]:
# bdf_dedisperse_cut.py -i 32:7562:1 -d 557.0 16A-496_sb32698778_1_02h00m_000.57646.38643644676
sdmfile = '16A-496_sb32698778_1_02h00m_000.57646.38643644676.ddcut'
msfile = sdmfile + 'ms'
scan = 32
caltables = ['../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.hifv_priorcals.s5_6.ants.tbl',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.finaldelay.k',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.finalBPcal.b',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.averagephasegain.g',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.finalampgaincal.g',
'../pipeline/57646/caltables/16A-496_sb32698778_1_02h00m_000.57646.38643644676.avg.ms.finalphasegaincal.g']
In [29]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
makeimage(msfile, field=targetfield, niter=30)
In [20]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57646'] = (az, el, az_err, el_err)
In [21]:
# bdf_dedisperse_cut.py -i 25:3879:1 -d 560.0 16A-496_sb32698778_1_02h00m_000.57648.37452900463
sdmfile = '16A-496_sb32698778_1_02h00m_000.57648.37452900463.ddcut'
msfile = sdmfile + 'ms'
scan = 25
caltables = ['../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.finaldelay.k',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.finalBPcal.b',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.averagephasegain.g',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.finalampgaincal.g',
'../pipeline/57648/caltables/16A-496_sb32698778_1_02h00m_000.57648.37452900463.avg.ms.finalphasegaincal.g']
In [32]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
makeimage(msfile, field=targetfield, niter=30)
In [22]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57648'] = (az, el, az_err, el_err)
In [23]:
# bdf_dedisperse_cut.py -i 31:10600:1 -d 557.0 16A-496_sb32698778_1_02h00m_001.57649.37461215278
sdmfile = '16A-496_sb32698778_1_02h00m_001.57649.37461215278.ddcut'
msfile = sdmfile + 'ms'
scan = 31
caltables = ['../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.hifv_priorcals.s5_3.gc.tbl',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.hifv_priorcals.s5_4.opac.tbl',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.hifv_priorcals.s5_5.rq.tbl',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.finaldelay.k',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.finalBPcal.b',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.averagephasegain.g',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.finalampgaincal.g',
'../pipeline/57649/caltables/16A-496_sb32698778_1_02h00m_001.57649.37461215278.avg.ms.finalphasegaincal.g']
In [35]:
convertms(sdmfile, msfile, scan)
msm = util.tools.msmetadata()
msm.open(msfile)
fieldnames = msm.fieldnames()
print(fieldnames)
targetfield = str(fieldnames.index('FRB121102-off'))
applycal(msfile, caltables, targetfield=targetfield)
makeimage(msfile, field=targetfield, niter=30)
In [24]:
az, el, az_err, el_err = fitimage(msfile + 'image', fitwindow=40)
fits['57649'] = (az, el, az_err, el_err)
In [25]:
# single-epoch localization
# con_casa = coordinates.SkyCoord('5h31m58.69495s', '+33d8m52.56074s', frame='icrs') # imfit to B+BnC data (Robert)
# con_az_err = 0.01209
# con_el_err = 0.00997
con_casa = {}
con_casa_err = {}
con_casa['57623'] = coordinates.SkyCoord(82.99460372*units.deg, 33.14796277*units.deg, frame='icrs')
con_casa_err['57623'] = (0.00000995, 0.00000507 )
# constant source same for scan 7 and 13
con_casa['57633_scan7'] = coordinates.SkyCoord(82.99458496*units.deg, 33.14795133*units.deg, frame='icrs')
con_casa_err['57633_scan7'] = (0.00000723, 0.00000436)
con_casa['57633_scan13'] = coordinates.SkyCoord(82.99458496*units.deg, 33.14795133*units.deg, frame='icrs')
con_casa_err['57633_scan13'] = (0.00000723, 0.00000436)
con_casa['57638'] = coordinates.SkyCoord(82.99457816*units.deg, 33.14793007*units.deg, frame='icrs')
con_casa_err['57638'] = (0.00001094, 0.00000303 )
con_casa['57643'] = coordinates.SkyCoord(82.99458527*units.deg, 33.14792721*units.deg, frame='icrs')
con_casa_err['57643'] = (0.00001317, 0.00000558)
con_casa['57645'] = coordinates.SkyCoord(82.99458191*units.deg, 33.14792454*units.deg, frame='icrs')
con_casa_err['57645'] = (0.00000336, 0.00000354)
con_casa['57646'] = coordinates.SkyCoord(82.99458183*units.deg, 33.14792251*units.deg, frame='icrs')
con_casa_err['57646'] = (0.00000636, 0.00000622)
con_casa['57648'] = coordinates.SkyCoord(82.99458296*units.deg, 33.14792605*units.deg, frame='icrs')
con_casa_err['57648'] = (0.00000320, 0.00000322)
con_casa['57649'] = coordinates.SkyCoord(82.99457118*units.deg, 33.14792951*units.deg, frame='icrs')
con_casa_err['57649'] = (0.00000457, 0.00000460)
con_casa['bryan2'] = coordinates.SkyCoord('05h31m58.69916s', '33d08m52.5578s', frame='icrs')
con_casa_err['bryan2'] = (0.0036/3600, 0.0026/3600)
con_casa['bryan3'] = coordinates.SkyCoord('05h31m58.69986s', '33d08m52.5519s', frame='icrs')
con_casa_err['bryan3'] = (0.0026/3600, 0.00203/3600)
con_casa['robert'] = coordinates.SkyCoord('05h31m58.69495s', '33d08m52.56074s', frame='icrs')
con_casa_err['robert'] = (3.4e-6, 2.8e-6)
In [27]:
pl.figure(figsize=(15,7))
for event in fits:
# get the fit
(az, el, frb_az_err, frb_el_err) = fits[event]
fit = coordinates.SkyCoord(az*units.rad, el*units.rad, frame='icrs')
# get the constant source
# con = con_casa[event]
# con_az_err, con_el_err = con_casa_err[event]
con = con_casa['bryan3']
con_az_err, con_el_err = con_casa_err['bryan3']
raoff, decoff = con.spherical_offsets_to(fit)
con_az_err = con_az_err*3600
con_el_err = con_el_err*3600
az_err = np.sqrt(frb_az_err**2 + con_az_err**2)
el_err = np.sqrt(frb_el_err**2 + con_el_err**2)
pl.subplot(121)
pl.errorbar(raoff.arcsec, decoff.arcsec, xerr=az_err, yerr=el_err, fmt='kx', ecolor='k', ms=0)
pl.text(raoff.arcsec, decoff.arcsec, event, horizontalalignment='right', verticalalignment='bottom')
if (int(event.split('_')[0]) > 57638):
pl.subplot(122)
pl.errorbar(raoff.arcsec, decoff.arcsec, xerr=az_err, yerr=el_err, fmt='kx', ecolor='k', ms=0)
pl.text(raoff.arcsec, decoff.arcsec, event, horizontalalignment='left', verticalalignment='top')
pl.subplot(121)
pl.title('FRB offset for all events')
pl.plot(0, 0, 'ro')
pl.text(0, 0, 'Counterpart', horizontalalignment='left', verticalalignment='top', color='r')
pl.xlabel('RA offset (arcsec)')
pl.ylabel('Dec offset (arcsec)')
pl.axis('equal')
pl.subplot(122)
pl.title('FRB offset for B+ configuration')
pl.plot(0, 0, 'ro')
pl.text(0, 0, 'Counterpart', horizontalalignment='right', verticalalignment='top', color='r')
pl.xlabel('RA offset (arcsec)')
pl.ylabel('Dec offset (arcsec)')
pl.axis('equal')
Out[27]:
In [28]:
for event in fits:
# get the fit
(az, el, frb_az_err, frb_el_err) = fits[event]
fit = coordinates.SkyCoord(az*units.rad, el*units.rad, frame='icrs')
# get the constant source location
# con = con_casa[event]
# con_az_err, con_el_err = con_casa_err[event]
con = con_casa['bryan3']
con_az_err, con_el_err = con_casa_err['bryan3']
raoff, decoff = con.spherical_offsets_to(fit)
con_az_err = con_az_err*3600
con_el_err = con_el_err*3600
az_err = np.sqrt(frb_az_err**2 + con_az_err**2)
el_err = np.sqrt(frb_el_err**2 + con_el_err**2)
if (int(event.split('_')[0]) > 57638):
# if (int(event.split('_')[0]) > 0):
pl.errorbar(raoff.arcsec, decoff.arcsec, xerr=az_err, yerr=el_err, fmt='kx', ecolor='k', ms=0)
pl.text(raoff.arcsec, decoff.arcsec, event, horizontalalignment='left', verticalalignment='top')
print(event, raoff.arcsec, decoff.arcsec, az_err, el_err)
pl.plot(0, 0, 'r*', linewidth=0, ms=10)
pl.text(0, 0, 'Counterpart', horizontalalignment='right', verticalalignment='bottom', color='r')
pl.xlabel('RA offset (arcsec)')
pl.ylabel('Dec offset (arcsec)')
Out[28]:
In [78]:
azall=0.
elall=0.
azeall=0.
eleall=0.
for event in fits:
# get the fit
if (int(event.split('_')[0]) > 57638):
(az, el, frb_az_err, frb_el_err) = fits[event]
azall += az/frb_az_err**2
elall += el/frb_el_err**2
azeall += 1./frb_az_err**2
eleall += 1./frb_el_err**2
fit = coordinates.SkyCoord(azall/azeall*units.rad, elall/eleall*units.rad, frame='icrs')
print(fit.ra.hms, fit.dec.dms)
print(np.sqrt(1./azeall), np.sqrt(1./eleall))
In [9]:
msfile = '16A-459_TEST_1hr_000.57633.66130137732.scan7.ddcutms'
ia = util.tools.image()
ia.open(msfile + 'image')
dd = ia.summary()
npixx,npixy,nch,npol = dd['shape']
imvals = ia.getchunk(0, int(npixx))[:,:,0,0]
peakx, peaky = np.where(imvals.max() == imvals)
displaywindow=100
extent = (1*0.25*displaywindow/2, -0.25*displaywindow/2, -0.25*displaywindow/2, 0.25*displaywindow/2)
# show results
fig = pl.figure(figsize=(8,8))
ax = fig.add_subplot(111)
pl.imshow(imvals[peakx[0]-displaywindow/2:peakx[0]+displaywindow/2, peaky[0]-displaywindow/2:peaky[0]+displaywindow/2],
interpolation='nearest', cmap='viridis', origin='bottom', extent=extent)
pl.xlabel('RA offset (arcsec)', fontsize=20)
pl.ylabel('Dec offset (arcsec)', fontsize=20)
xt = pl.setp(ax.get_xticklabels(), fontsize=14)
yt = pl.setp(ax.get_yticklabels(), fontsize=14)
ax.xaxis.set_tick_params(width=3, color='w')
ax.yaxis.set_tick_params(width=3, color='w')
In [14]:
print(dd)
In [15]:
np.degrees(1.21203420e-06)*3600
Out[15]:
In [ ]: