-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucamObjectClass.py
executable file
·167 lines (129 loc) · 4.71 KB
/
ucamObjectClass.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
import math, json, numpy
import ultracamutils
class colourObject:
""" This class is the storage holder for a merged object
"""
colours = ['r', 'g', 'b']
def __init__(self, id):
self.id = id
self.isComparison = False;
self.meanPosition = {'r': (0, 0), 'g': (0, 0), 'b': (0, 0)}
self.photometry = {'r': [], 'g': [], 'b':[] }
self.colourID = { 'r': -1, 'g': -1, 'b': -1 }
self.deviations = { 'r': -1, 'g': -1, 'b': -1 }
self.comparisonFlags = { 'r': False, 'g': False, 'b': False }
def setMeanPosition(self, colour, meanPosition):
self.meanPosition[colour] = meanPosition
def addExposure(self, colour, exposure):
self.photometry[colour].append(exposure)
return len(self.photometry[colour])
def calculateSigma(self):
for c in colourObject.colours:
data = self.photometry[c]
measurement = []
for e in data:
measurement.append(e['magnitude'])
standardDeviation = numpy.std(measurement)
mean = numpy.mean(measurement)
fractionalstd = standardDeviation/mean
print "%s mean: %f, stdev: %f, std/mean: %f"%(c, mean, standardDeviation, fractionalstd)
self.deviations[c] = fractionalstd
def getPhotometry(self, c, frameIndex):
data = self.photometry[c]
for e in data:
if e['frameIndex'] == frameIndex:
return e['magnitude']
return -1
def setPhotometry(self, c, frameIndex, value):
data = self.photometry[c]
for e in data:
if e['frameIndex'] == frameIndex:
e['magnitude'] = value
self.photometry[c] = data
def removePhotometry(self, c, frameIndex):
data = self.photometry[c]
print c, len(data)
for e in data:
if e['frameIndex'] == frameIndex:
data.remove(e)
self.photometry[c] = data
print c, len(data)
def getAllPhotometryByColour(self, c):
photometry = []
data = self.photometry[c]
for e in data:
photometry.append((e['frameIndex'], e['magnitude']))
return photometry
def __str__(self):
retStr = "ID: %d\n"%self.id
for c in colourObject.colours:
retStr+= '%s(%d,%d)[%d][%d]'%(c, int(self.meanPosition[c][0]), int(self.meanPosition[c][1]), len(self.photometry[c]), self.colourID[c])
if self.comparisonFlags[c]: retStr+= 'c';
retStr+= ' '
return retStr
def setComparisonFlag(self, colour):
self.comparisonFlags[colour] = True
def testComparison(self):
if (self.comparisonFlags['r'] & self.comparisonFlags['g'] & self.comparisonFlags['b']):
self.isComparison = True
return True
else:
return False
def toJSON(self):
testObject = {}
testObject['id'] = self.id
testObject['colourID'] = self.colourID
testObject['meanPosition'] = self.meanPosition
testObject['comparisonFlags'] = self.comparisonFlags
shortPhotometry = {'r': [], 'g': [], 'b':[]}
for c in colourObject.colours:
measurements = self.photometry[c]
for m in measurements:
reading = [ m['frameIndex'], m['magnitude'], m['fwhm'], m['position'][0], m['position'][1] ]
shortPhotometry[c].append(reading)
testObject['photometry'] = shortPhotometry
jsonString = json.dumps(testObject)
return jsonString
class timeLine:
""" This class encapsulates info about the individual frames from a run
"""
def __init(self):
self.MJDs = [] # Keeps track of the MJD for each frame
self.objectsPerFrame = [] # Keeps track of the count of identified objects for each frame
self.numFrames = 0
self.duration = 0
class frameObject:
""" Encapsulates info about a particular frame
"""
def __init__(self, *args):
if len(args)>0: self.MJD = args[0]
else: self.MJD = 0
if len(args)>1: self.frameNumber = args[1]
else: self.frameNumber = 0
if len(args)>2: self.frameIndex = args[2]
else: self.frameIndex = 0
self.objects = {'r':0, 'g':0, 'b':0}
self.comparisonPhotometry = {'r': -1, 'g': -1, 'b': -1}
def setObjectCount(self, colour, number):
self.objects[colour] = number
def __str__(self):
outStr = "Index: %d MJD: %s "%(self.frameIndex, str(self.MJD))
outStr+= "[r: %d, g: %d, b:%d]"%(self.objects['r'], self.objects['g'], self.objects['b'])
outStr+= " frameNumber: %d"%self.frameNumber
return outStr
def setComparisonPhotometry(self, colour, photometry):
self.comparisonPhotometry[colour] = photometry
def toJSON(self):
testObject = {'frameNumber': self.frameNumber, 'frameIndex': self.frameIndex}
testObject['objects'] = self.objects
testObject['MJD'] = self.MJD
testObject['c'] = self.comparisonPhotometry
jsonString = json.dumps(testObject)
return jsonString
def setFromObject(self, object):
self.MJD = object['MJD']
self.frameNumber = object['frameNumber']
self.frameIndex = object['frameIndex']
self.objects['r'] = object['objects']['r']
self.objects['g'] = object['objects']['g']
self.objects['b'] = object['objects']['b']