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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
import math
try:
import pyfits
except ImportError:
try:
from astropy.io import fits as pyfits
except ImportError:
raise ImportError("Cannot import either pyfits or astropy.io.fits")
from numpy import *
from matplotlib.pylab import figure, plot, xlabel, ylabel, loglog, clf
from matplotlib.pylab import semilogy, show, find, legend, hist, axis
def plotDvsR(ix, iy, fx, fy, R):
IR = argsort(R)
mR = []
mD = []
mI = []
# Look at index stars in order of R.
for ii in range(len(IR)):
i = IR[ii]
x = ix[i]
y = iy[i]
D = sqrt((fx - x)**2 + (fy - y)**2)
# Grab field stars within a matching radius.
r = 5
I = find( D < r )
for j in I:
mR.append(R[i])
mD.append(D[j])
mI.append(ii)
plot(mR, mD, 'ro')
xlabel('Distance from quad center')
ylabel('Match distance')
def plotIvsR(ix, iy, fx, fy, cx, cy):
RF = sqrt((fx - cx)**2 + (fy - cy)**2)
mD2 = []
mI2 = []
for i in range(len(RF)):
r = 5
D = sqrt((ix - fx[i])**2 + (iy - fy[i])**2)
I = find( D < r )
for j in I:
mD2.append(D[j])
mI2.append(i)
#plot(mI, mD, 'ro', mI2, mD2, 'bo')
plot(mI2, mD2, 'bo')
xlabel('Index star number')
ylabel('Match distance')
#legend(('Sorted by dist from quad center', 'Sorted by brightness'))
if __name__ == '__main__':
# Index stars
ixy = pyfits.open('ver/index.xy.fits')
ixy = ixy[1].data
ix = ixy.field(0)
iy = ixy.field(1)
NI = len(ix)
# Field stars
fxy = pyfits.open('ver/field.xy.fits')
fxy = fxy[1].data
fx = fxy.field(0)
fy = fxy.field(1)
NF = len(fx)
# The matched quad.
mf = pyfits.open('ver/match.fits')
mf = mf[1].data
quad = mf.field('quadpix')[0]
quad = quad[0:8].reshape(4,2)
qx = quad[:,0]
qy = quad[:,1]
# Quad center.
cx = mean(qx)
cy = mean(qy)
# Grab index stars that are within the field.
iok = find( (ix > min(fx)) *
(ix < max(fx)) *
(iy > min(fy)) *
(iy < max(fy)) )
ix = [ix[i] for i in iok]
iy = [iy[i] for i in iok]
figure(1)
clf()
I = [0, 2, 1, 3, 0]
plot(
[cx], [cy], 'ro',
qx[I], qy[I], 'r-',
ix, iy, 'rx',
fx, fy, 'b+',
)
# RMS quad radius
RQ = sqrt(sum((qx - cx)**2 + (qy - cy)**2) / 4)
# Distance from quad center.
RI = sqrt((ix - cx)**2 + (iy - cy)**2)
RF = sqrt((fx - cx)**2 + (fy - cy)**2)
# Angle from quad center.
AI = array([math.atan2(y - cy, x - cx) for (x,y) in zip(ix,iy)])
AF = array([math.atan2(y - cy, x - cx) for (x,y) in zip(fx,fy)])
# Look at index stars in order of R.
IR = argsort(RI)
allD = array([])
allDR = array([])
allDA = array([])
allR = array([])
allDist = array([])
for i in IR:
# regularizer...
reg = RQ
#
Distscale = 1
DRscale = 1 / RQ
dR = ((RI[i] + reg) / (RF + reg)) - 1.0
dA = AI[i] - AF
# handle wrap-around
absdA = abs(dA)
absdA = vstack((absdA, abs(absdA - 2*math.pi))).min(axis=0)
#D = sqrt(dR**2 + dA**2)
D = sqrt(dR**2 + absdA**2)
D = D / DRscale
Dist = sqrt((ix[i] - fx)**2 + (iy[i] - fy)**2)
Dist = Dist / Distscale
iSmall = array(find((D < 1) + (Dist < 1)))
allD = hstack((allD, D[iSmall]))
allDR = hstack((allDR, dR[iSmall]))
allDA = hstack((allDA, dA[iSmall]))
allR = hstack((allR, repeat(RI[i], len(iSmall))))
allDist = hstack((allDist, Dist[iSmall]))
figure(2)
clf()
plot(allDR, allDA, 'ro', ms=1)
xlabel('DR')
ylabel('DA')
figure(3)
clf()
#plot(allR/RQ, allD, 'r.')
#plot(allR/RQ, vstack((allD, allDist)).min(axis=0), 'r.')
plot(
#allR/RQ, vstack((allD, allDist)).min(axis=0), 'mo',
allR/RQ, allD, 'r+',
allR/RQ, allDist, 'bx'
)
xlabel('R (quad radiuses)')
#ylabel('min( Dist, D(R+A) )')
ylabel('Dist, D(R,A)')
a = axis()
axis([a[0], a[1], 0, 2.0])
legend(('D(R,A)', 'D'))
#allDist = array([])
#allRDist = array([])
#for i in IR:
# Dist = sqrt((ix[i] - fx)**2 + (iy[i] - fy)**2)
# iSmall = array(find(Dist < 5))
# allDist = hstack((allDist, Dist[iSmall]))
# allRDist = hstack((allRDist, repeat(RI[i], len(iSmall))))
#figure(4)
#clf()
#plot(allRDist/RQ, allDist, 'r.')
#xlabel('R')
#ylabel('Dist')
#figure(2)
#clf()
#plotDvsR(ix, iy, RI, fx, fy)
#figure(3)
#clf()
#plotDvsI(ix, iy, fx, fy, cx, cy)
|