-
Notifications
You must be signed in to change notification settings - Fork 3
/
plotwcs.py
executable file
·115 lines (85 loc) · 2.99 KB
/
plotwcs.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
#!/usr/bin/env python
import sys
import numpy
import os
from podi_definitions import *
import astropy.io.fits as pyfits
import datetime
from astLib import astWCS
from podi_wcs import *
import bottleneck
import podi_logging
import matplotlib
import matplotlib.pyplot
wcs_offset = numpy.array([2,2])
corners = numpy.array([[4096, 4096],
[4096, 0],
[ 0, 0],
[ 0, 4096],
[4096, 4096]])
corners += [1,1]
if __name__ == "__main__":
filename = sys.argv[1]
hdulist = pyfits.open(filename)
fig = matplotlib.pyplot.figure()
ax = fig.add_subplot(111)
try:
extname = sys.argv[2]
except:
extname = None
for idx, ext in enumerate(hdulist):
if (not type(ext)== pyfits.hdu.image.ImageHDU):
continue
# Read input WCS
ext.header['NAXIS'] = 2
ext.header['NAXIS1'] = 4096
ext.header['NAXIS2'] = 4096
if (cmdline_arg_isset("-zero")):
ext.header['CRVAL1'] = 0.
ext.header['CRVAL2'] = 0.
ext.header['CRVAL1'] += wcs_offset[0]
ext.header['CRVAL2'] += wcs_offset[1]
wcs = astWCS.WCS(ext.header, mode='pyfits')
# compute coords of the 4 corners
softbin = ext.header['SOFTBIN'] if 'SOFTBIN' in ext.header else 1
# correct OTA-corner positions for software binning
_corners = corners / softbin
radec = numpy.array(wcs.pix2wcs(_corners[:,0], _corners[:,1]))
radec -= wcs_offset
if (extname is not None and ext.name == extname):
print("\n",radec[:4,:])
#print radec, radec.shape
# Compute all individual cell coordinates
x,y = numpy.indices((8,8))
x1 = (x * 508).reshape((-1,1))
x2 = x1+480
y1 = (505*(7-y)).reshape((-1,1))
y2 = y1 + 494
# correct cell-corner positions for software binning
_x1, _x2, _y1, _y2 = x1/softbin, x2/softbin, y1/softbin, y2/softbin
radec_c1 = numpy.array(wcs.pix2wcs(_x1,_y1))
radec_c2 = numpy.array(wcs.pix2wcs(_x1,_y2))
radec_c3 = numpy.array(wcs.pix2wcs(_x2,_y2))
radec_c4 = numpy.array(wcs.pix2wcs(_x2,_y1))
cell_corners = numpy.empty((64,5,2))
cell_corners[:,0,:] = radec_c1
cell_corners[:,1,:] = radec_c2
cell_corners[:,2,:] = radec_c3
cell_corners[:,3,:] = radec_c4
cell_corners[:,4,:] = radec_c1
cell_corners -= wcs_offset
coll = matplotlib.collections.PolyCollection(
cell_corners,
facecolor='none',
edgecolor='#808080',
linestyle='-'
)
ax.add_collection(coll)
ax.plot(radec[:,0], radec[:,1], "b-")
center = numpy.average(radec[:-1,:], axis=0)
#print center
ax.text(center[0], center[1], ext.name, ha='center', va='center', color='black')
# break
ax.set_title(filename)
fig.show()
matplotlib.pyplot.show()