/
loadMosaic.py
executable file
·216 lines (166 loc) · 6.25 KB
/
loadMosaic.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python
import argparse, sys
import datetime, time
import numpy
import ppgplot
import generalUtils, configHelper, os
import curses
from astropy.io import fits
from astropy.wcs import WCS
from astropy.vo.client.conesearch import conesearch
from astropy.table import Table, vstack
from astropy.utils import data
import astropy.table
def redraw():
ppgplot.pggray(boostedImage, xlimits[0], xlimits[1]-1, ylimits[0], ylimits[1]-1, imageMinMax[0], imageMinMax[1], imagePlot['pgPlotTransform'])
def checkMargins(margins):
if margins[0][0] < margins[1][0]:
temp = margins[0][0]
margins[0][0] = margins[1][0]
margins[1][0] = temp
if margins[0][1] < margins[1][1]:
temp = margins[0][1]
margins[0][1] = margins[1][1]
margins[1][1] = temp
return margins
def withinMargins(table, namedColumns):
print namedColumns
return True
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Loads an IFAS mosaic image. Displays it with PGPLOT.')
parser.add_argument('filename', type=str, help='The FITS image file.')
parser.add_argument('--save', action="store_true", help='Write the input parameters to the config file as default values.')
parser.add_argument('--ignorecache', action="store_true", help='Ignore the cached DR2 catalogue. Will overwrite one if it already exists.')
args = parser.parse_args()
print args
config = configHelper.configClass("inspectIPHASImage")
"""exposureTime = config.getProperty("ExposureTime")
if args.exposureTime!=None:
exposureTime = args.exposureTime
config.ExposureTime = exposureTime
if exposureTime == None:
print "Please specify an exposure time or save one in the config file."
sys.exit()
"""
paperSize = 6 # Paper size in inches
imageMinMax = (0, 255)
plotSources = True
invertedColours = True
if args.save:
config.save()
hdulist = fits.open(args.filename)
print hdulist.info()
for card in hdulist:
print card.header.keys()
print repr(card.header)
imageData = hdulist[0].data
wcsSolution = WCS(hdulist[0].header)
hdulist.close()
(height, width) = numpy.shape(imageData)
aspectRatio = float(height)/float(width)
print aspectRatio
""" Set up the PGPLOT windows """
imagePlot = {}
imagePlot['pgplotHandle'] = ppgplot.pgopen('/xs')
ppgplot.pgpap(paperSize, aspectRatio)
ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0)
ppgplot.pgswin(0, width, 0, height)
# ppgplot.pgenv(0., width,0., height, 1, -2)
imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1]
boostedImage = generalUtils.percentiles(imageData, 20, 99)
ppgplot.pggray(boostedImage, 0, width-1, 0, height-1, 0, 255, imagePlot['pgPlotTransform'])
# Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header
imageCentre = [ width/2, height/2]
ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0]
positionString = generalUtils.toSexagesimal((ra, dec))
print "RA, DEC of image centre is: ", positionString, ra, dec
margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1)
margins = checkMargins(margins)
print "ra, dec limits:", margins
xlimits = (0, width)
ylimits = (0, height)
# try:
x=width/2
y=height/2
newWidth = width
newHeight = height
ppgplot.pgsci(3)
keyPressed = None
while keyPressed != 'q':
ch = ppgplot.pgcurs(x, y)
x=ch[0]
y=ch[1]
keyPressed = ch[2]
# print "Key pressed:", ch[2]
if keyPressed== 'w':
imageMinMax = (imageMinMax[1], imageMinMax[0])
if invertedColours: invertedColours= False
else: invertedColours=True
redraw()
if keyPressed=='i':
print "Zoom requested at (%0.0f, %0.0f)"%(x, y)
zoomFactor = 1.5
currentWidth = (xlimits[1] - xlimits[0])
newWidth = currentWidth / zoomFactor
currentHeight = (ylimits[1] - ylimits[0])
newHeight = currentHeight / zoomFactor
if (newWidth<100) or (newHeight<100):
print "Maximum zoom reached."
continue
else:
xlimits = (int(x - newWidth/2), int(x + newWidth/2))
if xlimits[0] < 0:
xlimits = (0, xlimits[1] + abs(xlimits[0]))
if xlimits[1] > width:
xlimits = (width - newWidth, width)
ylimits = (int(y - newHeight/2), int(y + newHeight/2))
if ylimits[0] < 0:
ylimits = (0, ylimits[1] + abs(ylimits[0]))
if ylimits[1] > height:
ylimits = (height - newHeight, height)
xlimits = (int(xlimits[0]), int(xlimits[1]))
ylimits = (int(ylimits[0]), int(ylimits[1]))
print "new limits:", xlimits, ylimits
ra_limits, dec_limits = wcsSolution.all_pix2world(numpy.array(xlimits), numpy.array(ylimits), 1)
print "new limits (world)", ra_limits, dec_limits
ppgplot.pgswin(xlimits[0], xlimits[1], ylimits[0], ylimits[1])
margins = [[ra_limits[0], dec_limits[0]], [ra_limits[1], dec_limits[1]]]
redraw()
if keyPressed=='o':
if newWidth == width: continue
print "Zoom out requested at (%0.0f, %0.0f)"%(x, y)
zoomFactor = 0.5
currentWidth = (xlimits[1] - xlimits[0])
newWidth = currentWidth / zoomFactor
currentHeight = (ylimits[1] - ylimits[0])
newHeight = currentHeight / zoomFactor
if (newWidth >= width) or (newHeight>=height):
print "Back to 1:1 scale."
newWidth = width
newHeight = height
xlimits = (int(x - newWidth/2), int(x + newWidth/2))
if xlimits[0] < 0:
xlimits = (0, xlimits[1] + abs(xlimits[0]))
if xlimits[1] > width:
xlimits = (width - newWidth, width)
ylimits = (int(y - newHeight/2), int(y + newHeight/2))
if ylimits[0] < 0:
ylimits = (0, ylimits[1] + abs(ylimits[0]))
if ylimits[1] > height:
ylimits = (height - newHeight, height)
xlimits = (int(xlimits[0]), int(xlimits[1]))
ylimits = (int(ylimits[0]), int(ylimits[1]))
print "new limits:", xlimits, ylimits
ra_limits, dec_limits = wcsSolution.all_pix2world(numpy.array(xlimits), numpy.array(ylimits), 1)
margins = [[ra_limits[0], dec_limits[0]], [ra_limits[1], dec_limits[1]]]
print "new limits (world)", ra_limits, dec_limits
ppgplot.pgswin(xlimits[0], xlimits[1], ylimits[0], ylimits[1])
redraw()
if plotSources: sourceStatus = "ON"
else: sourceStatus = "OFF"
if invertedColours: invertStatus = "ON"
else: invertStatus = "OFF"
print "PlotSources[%s] Invert Greyscale[%s]"%(sourceStatus, invertStatus)
# except KeyboardInterrupt:
# print "Ctrl-C pressed, but I dealt with it. "
ppgplot.pgclos()