-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsub_apphot.py
executable file
·176 lines (147 loc) · 5.28 KB
/
sub_apphot.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
#!/usr/bin/env python
"""
================================
| HOTPANTS Data Analysis Pipeline |
| v1.1 |
================================
| sub_appphot.py |
==============
Summary:
Calculates the photometry for your given object, both in the normal images and the noise images (for errors).
Usage:
sub_apphot.py -d directory -b band -o objectfile
if a file called "fwhm.dat" exists within the image folder, it will use this as the FWHM. Format, "FWHM", if not there, SExtractor is used.
"""
import sys
from optparse import OptionParser
from python.imclass.image import imFits, imObject
__author__ = "Jonny Elliott"
__copyright__ = "Copyright 2012"
__credits__ = "Felipe Olivares"
__license__ = "GPL"
__version__ = "1.1"
__maintainer__ = "Jonny Elliott"
__email__ = "[email protected]"
__status__ = "Prototype"
def main(directory, band, objectfile, fap=False, fdan=False, fan=False, cube="best"):
# Open and parse objectfile
objectOfInterest = imObject()
if objectfile:
objintfile = open(objectfile, "r")
obji = objintfile.readlines()[0].replace("\n", "").split(" ")
objectOfInterest._Name = obji[0]
objectOfInterest._ra = float(obji[1])
objectOfInterest._dec = float(obji[2])
objintfile.close()
else:
print __doc__
sys.exit(0)
#objectOfFakeness = imObject()
#objectOfFakeness._Name =
#objectOfFakeness._ra =
#objectOfFakeness._dec =
# Script outline
# 1. Initial image
#
# Acquire the FWHM and background STDDEV from the original uncut image
#
# 2. Normal Image
#
# Load the image and take photometry at the given position
#
# 3. Noise Image
#
# Do the same as on the normal image
#
# 4. Save the output in a file
# Normal image
InitialImage = imFits()
InitialImage._Band = band
InitialImage._Name = "%s/%s/remcut_%s.fits" % (directory, InitialImage._Band, InitialImage._Band)
InitialImage.getBackgroundSTDEV()
fwhmfile = "%s/%s/fwhm.dat" % (directory, band)
try:
fwhmf = open(fwhmfile, "r")
fwhm = float(fwhmf.readlines()[0].replace("\n",""))
print "FWHM taken from file"
InitialImage._MEDFWHM = fwhm
except:
print "FWHM calculated by SExtractor"
InitialImage.getMyMedianFWHM()
# SubtractedImage
SubtractedImage = imFits()
SubtractedImage._Band = band
SubtractedImage._Name = "%s/%s/sub/%s/diff_%s.fits" % (directory, SubtractedImage._Band, cube, SubtractedImage._Band)
SubtractedImage._skySTDEV = InitialImage._skySTDEV
SubtractedImage._MEDFWHM = InitialImage._MEDFWHM
SubObject = imObject()
SubObject._parentimage = SubtractedImage._Name
SubObject.copyObjectProperties(objectOfInterest)
SubObject.findLogicalPosition(write=True)
# Photometry
#
# Normal image
#
fwhm = InitialImage._MEDFWHM
if fap and fdan and fan:
print "User defined apertures"
print ""
print "fap fdan fan"
print "%f %f %f" % (fap, fdan, fan)
fap = fap
fdan = fdan
fan = fan
else:
fap = fwhm
fdan = 2*fwhm
fan = 2.2*fwhm
SubObject.setAps(fap=fap, fdan=fdan, fan=fan, scale=1)
SubObject.getAps(write=True)
SubtractedImage.runApperturePhotometryOnObject(SubObject)
#
# Noise image
#
NoiseImage = imFits()
NoiseImage._Band = band
NoiseImage._Name = "%s/%s/sub/%s/diff_%s_noise.fits" % (directory, NoiseImage._Band, cube, NoiseImage._Band)
# Noise Squared
NoiseSquaredImage = imFits()
NoiseSquaredImage._Band = band
NoiseSquaredImage._Name = NoiseImage.squareMyself()
#NoiseSquaredImage._skySTDEV = InitialImage._skySTDEV
NoiseSquaredImage.getBackgroundSTDEV()
NoiseSquaredImage._MEDFWHM = InitialImage._MEDFWHM
NoiseObject = imObject()
NoiseObject._parentimage = NoiseSquaredImage._Name
NoiseObject.copyObjectProperties(objectOfInterest)
NoiseObject.setAps(fap=fap, fdan=fdan, fan=fan, scale=1)
NoiseObject.findLogicalPosition(write=True)
NoiseSquaredImage.runApperturePhotometryOnObject(NoiseObject)
subError = NoiseSquaredImage.calculateError(SubObject, NoiseObject)
InitialImage.loadHeader()
#timeError = InitialImage.getHeader("EXPTIME")
# Set the subtracted error from the noise image and not the error from the subtracted image
SubObject._appMagErr = subError
SubObject.printInfo()
return SubObject._midMJD, SubObject._midMJDErr, SubObject._appMag, SubObject._appMagErr, NoiseObject._appMag, SubObject._appMagErr, SubObject, NoiseObject
if __name__ == "__main__":
parser = OptionParser()
parser.add_option('-d', dest='directory', help='directory of OBs', default=None)
parser.add_option('-b', dest='band', help='band', default=None)
parser.add_option('-o', dest='objint', help='object of interest', default=None)
parser.add_option('-a', dest='apertures', help='apertures', default=None)
(options, args) = parser.parse_args()
if options.directory and options.band and options.objint:
if options.apertures:
apfil = open(options.apertures, "r")
apf = apfil.readlines()
apfil.close()
aps = apf[0].replace("\n","").split(" ")
fap, fdan, fan = float(aps[0]), float(aps[1]), float(aps[2])
print main(options.directory, options.band, options.objint, fap=fap, fdan=fdan, fan=fan)
else:
print main(options.directory, options.band, options.objint)
else:
print __doc__
sys.exit(0)
# Mon Dec 12 13:39:20 CET 2011