-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSeeKAT_subbanding.py
146 lines (124 loc) · 5.42 KB
/
SeeKAT_subbanding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
#Tiaan Bezuidenhout, 2020. For inquiries: [email protected]
#NB: REQUIRES Python 3
import SK.utils as ut
import SK.coordinates as co
import SK.plotting as Splot
import SeeKAT as SK
import argparse
import numpy as np
import math
import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.coordinates import SkyCoord
import astropy.units as u
import astropy.wcs as wcs
from sys import stdout
import matplotlib.patches as patches
def parseOptions(parser):
'''Options:
-f Input file
--o Fractional sensitivity level at which CBs are tiled to overlap
--r Resolution of PSF in units of arcseconds per pixel
--n Number of beams to consider when creating overlap contours. Will
pick the specified number of beams with the highest S/N values.
'''
parser.add_argument('-l', dest='locFile',
nargs = 1,
type = str,
required=True)
parser.add_argument('-c', dest='config',
nargs = 1,
type = str,
help="Configuration (json) file",
required=False)
parser.add_argument('-s', dest='snrFile',
nargs = 1,
type = str,
required=True)
parser.add_argument('-p',dest='psf',
type=str,
nargs = '+',
help="PSF file",
required=True)
parser.add_argument('--o', dest='overlap',
type = float,
help = "Fractional sensitivity level at which the coherent beams overlap",
default = 0.25,
required = False)
parser.add_argument('--r', dest='res',
nargs = 1,
type=float,
help="Distance in arcseconds represented by one pixel of the PSF",
default = 1,
required = True)
parser.add_argument('--n',dest='npairs',
nargs = 1,
type = int,
default = [1000000])
parser.add_argument('--nsig',dest='nsig',
nargs = 1,
type = int,
help='Draws uncertainty contours up to this number of standard deviations.',
default = [2])
parser.add_argument('--s', dest='source',
nargs = 1,
type=str,
help="Draws given coordinate location (degrees) on localisation plot",
required = False)
parser.add_argument('--scalebar', dest='sb',
nargs = 1,
type = float,
help = "Length of scale bar on the localisation plot in arcseconds. Set to 0 to omit altogether",
default = [10],
required = False)
parser.add_argument('--ticks', dest='tickspacing',
nargs = 1,
type = float,
help = "Sets the number of pixels between ticks on the localisation plot",
default = [50],
required = False)
parser.add_argument('--clip', dest='clipping',
nargs = 1,
type = float,
help = "Sets values of the PSF below this number to zero. Helps minimise the influence of low-level sidelobes",
default = [0.08],
required = False)
parser.add_argument('--fits', dest='fitsOut',
help = "Outputs .fits file of localisation region",
action = 'store_true')
options= parser.parse_args()
return options
if __name__ == "__main__":
parser = argparse.ArgumentParser()
options = parseOptions(parser)
#data,c,boresight = ut.readCoords(options)
dataLocs,dataSNR,c,boresight = ut.readSubbandingFiles(options)
psfCube = ut.makeSubbandingPSFcube(options)
c,w,array_width,array_height = co.deg2pix(c,psfCube[:,:,0],boresight,options.res[0])
f, ax = plt.subplots(figsize=(10,10))
if options.source:
Splot.plot_known(w,options.source[0])
Splot.make_ticks(ax,array_width,array_height,w,fineness=options.tickspacing[0])
fullbandLogLikelihood = np.zeros((array_height,array_width))
for subband in range(0,psfCube.shape[2]):
print("\n---Localising in subband %d/%d---" % (subband+1,psfCube.shape[2]))
subbandSNRs = []
for line in dataSNR:
if line["fil"][-2:] == "."+str(subband):
subbandSNRs.append(line["SNR"])
subbandData = {"SN":np.asarray(subbandSNRs)}
loglikelihood = SK.make_map(array_height,array_width,c,psfCube[:,:,subband],options,subbandData)
#plt.imshow(likelihood)
#plt.show()
fullbandLogLikelihood+=loglikelihood#*np.max(subbandData["SN"])
#fullbandLogLikelihood /= np.amax(fullbandLikelihood)
Splot.likelihoodPlot(f,ax, w, fullbandLogLikelihood,options)
max_deg = []
max_loc = np.where(fullbandLogLikelihood==np.nanmax(fullbandLogLikelihood))
if len(max_loc) == 2:
max_loc = (max_loc[1],max_loc[0])
ut.printCoords(max_loc,w)
else:
print('Multiple equally possible locations')
plt.show()