-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbitalPeriods.py
34 lines (28 loc) · 1.2 KB
/
OrbitalPeriods.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
from Solar import Solar
# this class is to create a log file to output the relative periods of orbits
# as fractions of an earth year
class OrbitalPeriods(object):
#initialise a simulation and the filename of the logfile
def __init__(self):
self.sim = Solar('solardata.csv')
self.logfile = 'relativeOrbitalPeriods.txt'
# use the method to calculate the periods and then divide by the period of earth
# return a dictionary file with keys being the planet names and values as the relative periods
def relativePeriods(self):
earth = self.sim.getPlanet('Earth')
eathPeriod = self.sim.calculateOrbitalPeriods(earth)
relativePeriods = {}
for i in self.sim.planets:
relativePeriods[i.name] = self.sim.calculateOrbitalPeriods(i)/eathPeriod
return relativePeriods
# write the data to a file
def logRelativePeriods(self):
rel_periods = self.relativePeriods()
with open(self.logfile, 'w') as myFile:
for val in rel_periods:
myFile.write(str(val) + " has period " + str(rel_periods[val]) + " Years" + '\n')
# run code
def __main__():
a = OrbitalPeriods()
a.logRelativePeriods()
__main__()