This file is indexed.

/usr/lib/python/astrometry/util/plotshift.py is in astrometry.net 0.46-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
#! /usr/bin/env python

import sys
from optparse import OptionParser

import matplotlib
matplotlib.use('Agg')

from pylab import *
from numpy import *

from astrometry.libkd import spherematch

def plotshift(ixy, rxy, dcell=50, ncells=18, outfn=None, W=None, H=None, hist=False,
			  nhistbins=21):
			  #histbinsize=None):
	# correspondences we could have hit...
	radius = dcell * sqrt(2.)
	#print 'ixy', ixy.shape
	#print 'rxy', rxy.shape
	assert((len(rxy) == 0) or (rxy.shape[1] == 2))
	assert((len(ixy) == 0) or (ixy.shape[1] == 2))

	ix = ixy[:,0]
	iy = ixy[:,1]

	if W is None:
		W = max(ix)
	if H is None:
		H = max(iy)

	if len(rxy):
		keep = (rxy[:,0] > -dcell) * (rxy[:,0] < W+dcell) * (rxy[:,1] > -dcell) * (rxy[:,1] < H+dcell)
		rxy = rxy[keep]
    #print 'Cut to %i ref sources in range' % len(rxy)
	
	cellsize = sqrt(W * H / ncells)
	nw = int(round(W / cellsize))
	nh = int(round(H / cellsize))
	#print 'Grid cell size', cellsize
	#print 'N cells', nw, 'x', nh
	edgesx = linspace(0, W, nw+1)
	edgesy = linspace(0, H, nh+1)
	#print 'Edges:'
	#print '	 x:', edgesx
	#print '	 y:', edgesy
	if len(rxy) == 0:
		binx = array([])
		biny = array([])
	else:
		binx = digitize(rxy[:,0], edgesx)
		biny = digitize(rxy[:,1], edgesy)
	binx = clip(binx - 1, 0, nw-1)
	biny = clip(biny - 1, 0, nh-1)
	bin = biny * nw + binx

	clf()

	for i in range(nh):
		for j in range(nw):
			thisbin = i * nw + j
			R = (bin == thisbin)
			#print 'cell %i, %i' % (j, i)
			#print '%i ref sources' % sum(R)
			matchdx = []

			if sum(R) > 0:
				(inds,dists) = spherematch.match(rxy[R,:], ixy, radius)
				#print 'Found %i matches within %g pixels' % (len(dists), radius)
				ri = inds[:,0]
				# un-cut ref inds...
				ri = (flatnonzero(R))[ri]
				ii = inds[:,1]
				matchx	= rxy[ri,0]
				matchy	= rxy[ri,1]
				matchdx = ix[ii] - matchx
				matchdy = iy[ii] - matchy
				#print 'All matches:'
				#for dx,dy in zip(matchdx,matchdy):
				#	print '	 %.1f, %.1f' % (dx,dy)
				ok = (matchdx >= -dcell) * (matchdx <= dcell) * (matchdy >= -dcell) * (matchdy <= dcell)
				matchdx = matchdx[ok]
				matchdy = matchdy[ok]
				#print 'Cut to %i within %g x %g square' % (sum(ok), dcell*2, dcell*2)
				#print 'Cut matches:'
				#for dx,dy in zip(matchdx,matchdy):
				#	print '	 %.1f, %.1f' % (dx,dy)
			
			# Subplot places plots left-to-right, TOP-to-BOTTOM.
			subplot(nh, nw, 1 + ((nh - i - 1)*nw + j))

			if len(matchdx) > 0:
				#plot(matchdx, matchdy, 'ro', mec='r', mfc='r', ms=5, alpha=0.2)
				#plot(matchdx, matchdy, 'ro', mec='r', mfc='none', ms=5, alpha=0.2)
				if hist:
					#if histbinsize is None:
					#	histbinsize = dcell / 10.
					edges = linspace(-dcell, dcell, nhistbins+1)
					(H,xe,ye) = histogram2d(matchdx, matchdy, bins=(edges,edges))
					imshow(H.T, extent=(min(xe), max(xe), min(ye), max(ye)),
						   aspect='auto', origin='lower', interpolation='nearest')
					text(dcell, dcell, '%i' % H.max(), color='y',
						 horizontalalignment='right', verticalalignment='top')
						 
				else:
					plot(matchdx, matchdy, 'r.', alpha=0.3)

			if hist:
				axhline(0, color='b', alpha=0.8)
				axvline(0, color='b', alpha=0.8)
			else:
				axhline(0, color='k', alpha=0.5)
				axvline(0, color='k', alpha=0.5)
			if i == 0 and j == 0:
				xticks([-dcell,0,dcell])
				yticks([-dcell,0,dcell])
			else:
				xticks([],[])
				yticks([],[])
			axis('scaled')
			axis([-dcell, dcell, -dcell, dcell])
	if outfn is not None:
		#print 'Saving', outfn
		savefig(outfn)


if __name__ == '__main__':
	from astrometry.util.fits import fits_table
	
	parser = OptionParser('usage: %prog [options] <image xy> <reference xy> <plot name>')
	parser.add_option('-X', dest='xcol', help='Name of X column in image table')
	parser.add_option('-Y', dest='ycol', help='Name of Y column in image table')
	parser.add_option('-N', dest='nimage', type='int', help='Cut to the first N image sources')
	parser.add_option('-x', dest='rxcol', help='Name of X column in reference table')
	parser.add_option('-y', dest='rycol', help='Name of Y column in reference table')
	parser.add_option('-n', dest='nref', type='int', help='Cut to the first N reference sources')
	parser.add_option('-c', dest='cells', type='int', help='Approx. number of pieces to cut image into (default:18)')
	parser.add_option('-s', dest='cellsize', type='int', help='Search radius, in pixels (default 50)')
	parser.set_defaults(xcol='X', ycol='Y', nimage=0, cells=0, cellsize=0, rxcol='X', rycol='Y', nref=0)
	opt,args = parser.parse_args()

	if len(args) != 3:
		parser.print_help()
		sys.exit(-1)

	imxy = fits_table(args[0])
	refxy = fits_table(args[1])
	outfn = args[2]

	kwargs = {}
	if opt.cells:
		kwargs['ncells'] = opt.cells
	if opt.cellsize:
		kwargs['dcell'] = opt.cellsize

	ix = imxy.getcolumn(opt.xcol)
	iy = imxy.getcolumn(opt.ycol)
	ixy = vstack((ix,iy)).T
	if opt.nimage:
		ixy = ixy[:opt.nimage,:]

	rx = refxy.getcolumn(opt.rxcol)
	ry = refxy.getcolumn(opt.rycol)
	rxy = vstack((rx,ry)).T
	if opt.nref:
		rxy = rxy[:opt.nref,:]

	plotshift(ixy, rxy, outfn=outfn, **kwargs)