-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasmodeus-plot.py
More file actions
executable file
·154 lines (116 loc) · 4.98 KB
/
asmodeus-plot.py
File metadata and controls
executable file
·154 lines (116 loc) · 4.98 KB
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
#!/usr/bin/env python
"""
Renders sky plkots and histograms using matplotlib
Requires: analyses
Outputs: plots
"""
from core import asmodeus, dataset, logger
from physics import coord
from utilities import colour as c, utilities as ut
class AsmodeusPlot(asmodeus.Asmodeus):
def __init__(self):
self.name = 'plot'
super().__init__()
def configure(self):
self.loadObservers()
self.dataset.require('sightings')
self.dataset.require('histograms')
self.dataset.reset('plots')
self.dataset.reset('histograms')
def run(self):
self.plotSky()
self.plotHistograms()
def plotHistograms(self):
for observer in self.observers:
observer.plotHistograms()
if __name__ == "__main__":
log = logger.setupLog('root')
asmo = AsmodeusPlot()
asmo.run()
#### Old crap below
def main(argv):
plotSky(observers)
plotHistograms(observers)
if config.multifit.magnitude.repeat == 0:
log.info("Skipping plot {}".format(colour('magnitude', 'name')))
else:
plotChiSquareMagnitude(observers, 'magnitude')
centroid('magnitude', 100)
if config.multifit.altitude.repeat == 0:
log.info("Skipping plot {}".format(colour('altitude', 'name')))
else:
plotChiSquareAltitude(observers, 'altitude')
def plotSky(observers):
context = {
'dataset': config.dataset.name,
'streaks': config.plot.streaks,
'dark': config.plot.dark,
'observers': observers,
'pixels': config.plot.pixels,
}
quantities = {}
if config.plot.sky.distance:
quantities[6] = 'distance'
if config.plot.sky.elevation:
quantities[7] = 'elevation'
if config.plot.sky.speed:
quantities[8] = 'speed'
if config.plot.sky.angularSpeed:
quantities[9] = 'angularSpeed'
if config.plot.sky.mass:
quantities[10] = 'mass'
if config.plot.sky.power:
quantities[11] = 'power'
if config.plot.sky.sighted:
quantities[14] = 'sighted'
context['quantities'] = quantities
for observer in observers:
fileName = os.path.join('datasets', config.dataset.name, 'plots', '{}.tsv'.format(observer))
if not os.path.exists(fileName):
raise FileNotFoundError("File {} not found!".format(colour(fileName, 'name')))
asmodeus.buildGnuplotTemplate('sky.gp', config.dataset.name, context, os.path.join('datasets', config.dataset.name))
log.info("Template {} finished, calling {}".format(colour('sky', 'name'), colour('gnuplot', 'script')))
os.system('gnuplot datasets/{}/sky.gp'.format(config.dataset.name))
def plotHistograms(observers):
context = {
'dataset': config.dataset.name,
'observers': observers,
'histograms': config.statistics.histograms,
}
asmodeus.buildGnuplotTemplate('histogram.gp', config.dataset.name, context, asmodeus.datasetPath('plots'))
log.info("Template {} finished, calling {}".format(colour('histogram', 'name'), colour('gnuplot', 'script')))
os.system('gnuplot {}'.format(asmodeus.datasetPath('plots', 'histogram.gp')))
def plotChiSquareMagnitude(observers, quantity):
context = {
'dataset': config.dataset.name,
'observers': observers,
'omega': config.multifit.magnitude.parameters.omega,
'limmag': config.multifit.magnitude.parameters.limit,
}
asmodeus.buildGnuplotTemplate('chiSquare-{}.gp'.format(quantity), config.dataset.name, context, asmodeus.datasetPath('plots'))
log.info("Template {} finished, calling {}".format(colour('chiSquare', 'name'), colour('gnuplot', 'script')))
os.system('gnuplot {}'.format(asmodeus.datasetPath('plots', 'chiSquare-{}.gp'.format(quantity))))
def centroid(quantity, count):
file = open(asmodeus.datasetPath('plots', 'chiSquare-{}.tsv'.format(quantity)), 'r')
data = []
for line in file:
(om, lm, cs) = map(float, line.rstrip('\n').split())
data.append((om, lm, cs))
data = sorted(data, key = lambda x: x[2])[0:count]
limmag = sum([x[0] for x in data]) / count
omega = sum([x[1] for x in data]) / count
chisq = sum([x[2] for x in data]) / count
log.info("Minimum for limiting magnitude {}, width {}, chi square is {}".format(
colour("{:.3f}".format(limmag), 'num'),
colour("{:.3f}".format(omega), 'num'),
colour("{:.6f}".format(chisq), 'num'),
))
def plotChiSquareAltitude(observers, quantity):
context = {
'dataset': config.dataset.name,
'observers': observers,
'exponent': config.multifit.altitude.parameters.exponent,
}
asmodeus.buildGnuplotTemplate('chiSquare-{}.gp'.format(quantity), config.dataset.name, context, asmodeus.datasetPath('plots'))
log.info("Template {} finished, calling {}".format(colour('chiSquare', 'name'), colour('gnuplot', 'script')))
os.system('gnuplot {}'.format(asmodeus.datasetPath('plots', 'chiSquare-{}.gp'.format(quantity))))