-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage_distances.py
154 lines (111 loc) · 6.2 KB
/
page_distances.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
"""
CosmOracleApp
Created December 2021
@authors:
[Marco Bonici](https://github.com/marcobonici),
[Niko Sarcevic](https://github.com/nikosarcevic) and
[Matthijs van der Wild](https://github.com/lonbar)
"""
import numpy as np
import streamlit as st
import background as bg
<<<<<<< HEAD
from helpers import plot_graph, get_parametersets, get_cosmologies, store_data
=======
from helpers import plot_graph, get_parametersets, get_cosmologies, store_data, get_redshifts
>>>>>>> f52f80ce39b7cf8c1fd2cf5848093a09d67cc2ca
def show_page():
section_title = "Cosmological Distances"
# Set default values
parameterset = st.sidebar.selectbox("Parameter set", get_parametersets())
cosmologies = get_cosmologies(parameterset)
ΩM = cosmologies['matter-density']
ΩDE = cosmologies['DE-density']
ΩR = cosmologies['rad-density']
w0 = cosmologies['w0']
wa = cosmologies['wa']
H0 = cosmologies['Hubble0']
z_value = st.sidebar.text_input('Redshift')
H0_value = st.sidebar.text_input('Hubble Constant [km/s/Mpc]', str(H0))
ΩM_value = st.sidebar.text_input('Matter Density', str(ΩM))
ΩDE_value = st.sidebar.text_input('Dark Energy Density', str(ΩDE))
ΩR_value = st.sidebar.text_input('Radiation Density', str(ΩR))
w0_value = st.sidebar.text_input('w0', str(w0))
wa_value = st.sidebar.text_input('wa', str(wa))
sig_digits = int(st.sidebar.text_input('Significant Digits', str(4)))
if z_value:
z_array = np.linspace(0, float(z_value), 300)
inputParms = bg.distanceData(z_array, float(H0_value), float(ΩM_value), float(ΩDE_value),
float(ΩR_value), float(w0_value), float(wa_value))
st.title('Results')
st.write('Comoving distance at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.comoving_distance[-1], sig_digits)), 'Mpc')
st.write('Transverse comoving distance at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.transverse_comoving_distance[-1], sig_digits)), 'Mpc')
st.write('Luminosity distance at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.luminosity_distance[-1], sig_digits)), 'Mpc')
st.write('Angular diameter distance at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.angular_diameter_distance[-1], sig_digits)), 'Mpc')
st.write('An object spanning an angle of 1 arcsec at redshift', str(inputParms.redshift[-1]), 'is therefore',
str(round(inputParms.proper_separation[-1], sig_digits)), 'kpc across.')
st.write('Comoving volume at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.comoving_volume[-1], sig_digits)), 'Gpc³')
st.write('Lookback time at redshift', str(inputParms.redshift[-1]), 'is:',
str(round(inputParms.lookback_time[-1], sig_digits)), 'Gyrs')
rz_array = inputParms.comoving_distance
trz_array = inputParms.transverse_comoving_distance
DLz_array = inputParms.luminosity_distance
DAz_array = inputParms.angular_diameter_distance
VCz_array = inputParms.comoving_volume
tlz_array = inputParms.lookback_time
store_data(inputParms)
st.write(" ")
plot_rz = st.checkbox('Plot Comoving Distance Dc(z)')
plot_trz = st.checkbox('Plot Transverse Comoving Distance Dm(z)')
plot_DLz = st.checkbox('Plot Luminosity Distance Dl(z)')
plot_DAz = st.checkbox('Plot Angular Diameter Distance Da(z)')
st.write(" ")
if plot_rz or plot_trz or plot_DLz or plot_DAz:
width = st.slider("plot width", 1, 25, 10)
height = st.slider("plot height", 1, 25, 5)
log_checkbox = st.checkbox('Switch to semi-log scale')
st.write(" ")
plot = plot_graph(width, height, z_array,
(plot_rz, rz_array, "Comoving distance"),
(plot_trz, trz_array, "Transverse comoving distance"),
(plot_DLz, DLz_array, "Luminosity distance"),
(plot_DAz, DAz_array, "Angular diameter distance"),
is_log = log_checkbox)
st.pyplot(plot)
st.write(" ")
my_expander = st.expander(label='Click for more plots')
with my_expander:
plot_VCz = st.checkbox('Plot Comoving Volume Vc(z)')
plot_tlz = st.checkbox('Plot Lookback Time tl(z)')
if plot_VCz:
width = st.slider("Plot width Vc(z)", 1, 25, 10)
height = st.slider("Plot height Vc(z)", 1, 25, 5)
log_checkbox = st.checkbox('Switch to semi-log scale Vc(z)')
st.write(" ")
plot = plot_graph(width, height, z_array,
(plot_VCz, inputParms.comoving_volume, "Comoving Volume"),
axis_label = "Comoving volume [Gpc³]", is_log = log_checkbox)
st.pyplot(plot)
if plot_tlz:
width = st.slider("Plot width tl(z)", 1, 25, 10)
height = st.slider("Plot height tl(z)", 1, 25, 5)
log_checkbox = st.checkbox('Switch to semi-log scale tl(z)')
st.write(" ")
plot = plot_graph(width, height, z_array,
(plot_tlz, inputParms.lookback_time, "Lookback time"),
axis_label = "Lookback time [Gyr]", is_log = log_checkbox)
st.pyplot(plot)
st.write(" ")
st.header('Download calculated data as a text file')
f = open("output.txt", encoding = 'utf-8')
file_name = st.text_input('Name the file', "filename.txt")
st.download_button('Click to download', f, file_name = file_name)
else:
st.title(section_title)
st.write('Enter the value of redshift and cosmological parameters in the sidebar and press enter.')
return