-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (44 loc) · 1.89 KB
/
main.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
"""
Calculates the search distance and telescope size needed to find signs
of life, emitting light of a given minimum wavelength, with a given
confidence, given the average probability of life around stars in a
galactic disc of given dimensions and average stellar density.
"""
import database, graphing, loading, simulation
import json
from contextlib import closing
import sqlite3
def _run(galaxy, config):
"""
Run simulations of decreasing probability that each system bears
life.
"""
probabilities, search_distances, base_lengths = [], [], []
probability = galaxy.life_probability
while probability >= config.minimum_probability:
stars = simulation.trials(config.minimum_confidence, probability)
volume = stars / galaxy.stellar_density
search_distance = simulation.search_distance(
volume, galaxy.disc_half_thickness, galaxy.altitude_above_ecliptic)
base_length = simulation.base(galaxy.minimum_wavelength,
search_distance,
galaxy.life_sign_size)
probabilities.append(probability)
search_distances.append(search_distance)
base_lengths.append(base_length)
probability += config.probability_increment
return probabilities, search_distances, base_lengths
def main():
"""
Load configuration and galactic data, run a simulation, and graph
and save the output.
"""
with open("data.json", 'r') as f:
galaxy = loading.Galaxy(json.load(f))
with open("config.json", 'r') as f:
config = loading.Config(json.load(f))
probabilities, search_distances, base_lengths = _run(galaxy, config)
database.export(probabilities, search_distances, base_lengths)
graphing.distance_graph(probabilities, search_distances)
graphing.base_graph(probabilities, base_lengths)
if __name__ == "__main__": main()