-
Notifications
You must be signed in to change notification settings - Fork 15
/
HumVI.py
executable file
·193 lines (150 loc) · 5.99 KB
/
HumVI.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
#!/usr/bin/env python
# =====================================================================
# Globally useful modules:
import numpy
import sys, getopt
from PIL import Image
import humvi
import os
# =====================================================================
def HumVI(argv):
"""
NAME
compose.py
PURPOSE
Make a color composite PNG image from 3 FITS images, using the Lupton
algorithm. Part of the HumVI package.
COMMENTS
Reads filter name and zero point from header and tries to set scales
automatically - unless scales are set on command line. Note
telescope/survey has to be recognised for this to work...
USAGE
compose.py [flags] red.fits green.fits blue.fits
FLAGS
-h Print this message
-v Verbose operation
-b --subtract-background
INPUTS
red.fits etc Names of FITS files containing image data
OPTIONAL INPUTS
-s --scales 3,2,4 Comma-separated scales for R,G,B channels [None]
-p --parameters 5,0.05 Non-linearity parameters Q,alpha
-o --output outfile Name of output filename [guessed]
-x --saturate-to style Saturation method, color or white [white]
-z --offset 0.1 Offset image level (+ve = gray background)
-m --mask -1.0 Mask images below level [don't]
OUTPUTS
stdout Useful information
outfile Output plot in png format
EXAMPLES
Note the different alpha required, to cope with survey depth!
CFHTLS:
HumVI.py -v -s 0.4,0.6,1.7 -z 0.0 -p 1.7,0.09 -m -1.0 \
-o examples/CFHTLS-test_gri.png \
examples/CFHTLS-test_i.fits \
examples/CFHTLS-test_r.fits \
examples/CFHTLS-test_g.fits
PS1 (Needs optimizing on a larger image.):
HumVI.py -v -s 0.6,0.6,1.7 -z 0.0 -p 1.7,0.00006 -m -1.0 \
-o examples/PS1-test_riz.png \
examples/PS1-test_z.fits \
examples/PS1-test_i.fits \
examples/PS1-test_r.fits
DES (Experimental. No images checked in.):
HumVI.py -v -s 1.0,1.2,2.8 -z 0.0 -p 1.0,0.03 -m -1.0 \
-o examples/DES-test_gri.png \
examples/DES-test_i.fits \
examples/DES-test_r.fits \
examples/DES-test_g.fits
VICS82:
HumVI.py -v -s 1.0,1.4,2.0 -z 0.0 -p 1.5,0.4 -m -1.0 \
-o examples/VICS82-test_iJKs.png \
examples/VICS82-test_Ks.fits \
examples/VICS82-test_J.fits \
examples/VICS82-test_i.fits
KiDS:
HumVI.py -v -s 0.4,0.6,1.7 -z 0.0 -p 1.5,0.02 -m -1.0 \
-o examples/KiDS-test_gri.png \
examples/KiDS-test_i.fits \
examples/KiDS-test_r.fits \
examples/KiDS-test_g.fits
BUGS
- Renormalized scales will not be appropriate if one image is in very
different units to another, or if images are in counts, not counts per
second or AB maggies.
- Code currently assumes one file per channel, whereas we might want to
use N>3 images in combination. The image to channel transformation
would be performed after scaling to flux units but before
stretching. Masking would need to be done at this point too.
- Should cope with just two, or even one, input image file(s).
HISTORY
2012-05-11 started Marshall (Oxford)
2012-07-?? integrated with wherry.py Sandford (NYU)
2012-12-19 defaults set for CFHTLS images Marshall (Oxford)
2013-02-21 defaults set for PS1 images Marshall (Oxford)
2013-02-26 experimenting with DES images Hirsch (UCL)
"""
# -------------------------------------------------------------------
try:
opts, args = getopt.getopt(argv, "hvp:s:n:o:x:z:blwm:",\
["help", "verbose", "scales", "pars", "output", "saturate-to", "offset", "subtract-background", "lupton", "wherry", "mask"])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
print(HumVI.__doc__)
return
vb = False
outfile = "color.png"
# Defaults optimized for CFHTLS...
pars = '1.7,0.09'
scales = '0.4,0.6,1.7'
# More general sensible choices:
backsub = False
saturation = 'white'
offset = 0.0
masklevel = None # Better default would be -1.0
for o, a in opts:
if o in ("-h", "--help"):
print(HumVI.__doc__)
return
elif o in ("-v", "--verbose"):
vb = True
elif o in ("-p", "--parameters"):
pars = a
elif o in ("-s", "--scales"):
scales = a
elif o in ("-x", "--saturate-to"):
saturation = a
elif o in ("-z", "--offset"):
offset = float(a)
elif o in ("-m", "--mask"):
masklevel = float(a)
elif o in ("-o", "--output"):
outfile = a
elif o in ("-b", "--subtract-background"):
backsub = True
else:
assert False, "Unhandled option"
# Check for datafiles in array args:
print(len(args))
if len(args) == 3:
rfile = args[0]
gfile = args[1]
bfile = args[2]
else:
print(HumVI.__doc__)
return
# Parse nonlinearity parameters:
Qs, alphas = pars.split(',')
Q = float(Qs)
alpha = float(alphas)
# Parse channel colour scales:
x, y, z = scales.split(',')
rscale, gscale, bscale = float(x), float(y), float(z)
# Compose the image!
humvi.compose(rfile, gfile, bfile, scales=(rscale, gscale, bscale), Q=Q, alpha=alpha, masklevel=masklevel, saturation=saturation, offset=offset, backsub=backsub, vb=vb, outfile=outfile)
return
# ======================================================================
if __name__ == '__main__':
HumVI(sys.argv[1:])
# ======================================================================