forked from PlanetHuntingInPython/PlanetHuntingStudents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
73 lines (66 loc) · 2.66 KB
/
test.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
from data_handler import LocalDataHandler
from data_analyser import DataAnalyser
from time import perf_counter
import matplotlib.pyplot as plt
import formulas
class Timing():
def __init__(self, sinceLastOut=True, ms=True):
self.s = perf_counter()
self.last = self.s
self.sinceLastOut = sinceLastOut
self.unit = 1000 if ms else 1
self.unitPrefix = 'm'*ms + 's'
def out(self,label=None):
print(f"{label + ':' if label else ''} {((e := perf_counter()) - self.last)*self.unit} {self.unitPrefix}")
if self.sinceLastOut:
self.last = e
def totalOut(self, label=""):
if not self.sinceLastOut:
self.out(label)
print(f"Total: {(perf_counter() - self.s)*self.unit} {self.unitPrefix}")
def skip(self):
self.last = perf_counter()
def timedTest(dataID, plotType=None):
print(f"{dataID} results:")
t = Timing(True, True)
analyser = DataAnalyser(dataID)
t.out("Initialisation")
transitDuration = analyser.getTransitDuration()
phase = analyser.getPhase()
period = analyser.getOrbitalPeriod()
peak = analyser.getModel().getPeak()
threshold = analyser.transits.getTransitThreshold()
planetaryRadius = analyser.getPlanetaryRadius()
orbitalInclination = analyser.getOrbitalInclination()
semiMajorAxis = analyser.getSemiMajorAxis()
impactParameter = analyser.getImpactParameter()
t.out("Parameters")
print(f"{period = }, {phase = }, {transitDuration = }, {peak = }, {threshold = }, {semiMajorAxis = }, {planetaryRadius = }, {impactParameter = }, {orbitalInclination = }")
print(f"Anomalous Flux Regions: {analyser.transits.getAnomalousRegions()}")
t.totalOut()
if plotType is not None:
analyser.plot(plotType)
def iterTest():
t = Timing(True, True)
failed = []
i = 0
print(f"{'N':<6} | {'Data ID':<15} | {'Period':<20} | {'Planetary Radius':<20} | {'Semi Major Axis':<20} | {'Impact Parameter':<20} | {'Orbital Inclination':<20} | {'Time'}")
for d in DataAnalyser():
i += 1
try:
d.getModel()
print(f"{i:<6} | {d.dataID:<15} | {d.getOrbitalPeriod():<20} | {d.getPlanetaryRadius():<20} | {d.getSemiMajorAxis():<20} | {d.getImpactParameter():<20} | {d.getOrbitalInclination():<20} |", end=" ")
t.out()
except Exception:
failed.append(d.dataID)
t.skip()
if failed:
print(f"Failed: {len(failed)}/{i}")
for dataID in failed:
print(dataID)
else:
print(f"No fails. 0/{i}")
t.totalOut()
#print(DataAnalyser("KPLR011673802").getOrbitalPeriod())
#timedTest("kplr009825625", "c")
iterTest()