-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_widths.py
133 lines (110 loc) · 4.28 KB
/
calc_widths.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
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from scipy.integrate import quad
import scipy.constants as const
import pandas as pd
from scipy.optimize import fsolve, minimize
from comet import ref_rock, ref_ice
from camera import Camera
from unibe import *
from make_filters import make_filter, init_filters_thomas
from SNR import snr
from motion_blurr import get_possible_detector_time
snr_target = 100
def get_mirror():
df_mirror = pd.read_csv("data/mirrors_transmission.txt", delimiter="\s")
M = interp1d(df_mirror.wavelength, df_mirror.transmission, fill_value="extrapolate")
# percent
return M
def get_detector():
df_qe = pd.read_csv("data/qe.txt", delimiter=",")
Q = interp1d(df_qe.Wavelength, df_qe.QE / 100, fill_value="extrapolate")
# electrons per photons
return Q
def get_solar():
df_solar = pd.read_csv("data/solar.csv", delimiter=";", skiprows=1)
S = interp1d(df_solar["Wavelength (nm)"], df_solar["Extraterrestrial W*m-2*nm-1"], fill_value="extrapolate")
# W per meter squared per nanometer
return S
def solve_for_widths(coca, alpha=0):
M = get_mirror()
Q = get_detector()
S = get_solar()
def integrand(w, alpha=0):
return w * M(w) * Q(w) * ref_rock(w, alpha) * S(w)
widths100 = []
widths80 = []
widths60 = []
centers = range(400, 1051, 50)
for filter_center in centers:
def func(width):
i = quad(integrand, filter_center - width / 2, filter_center + width / 2, args=(alpha))[
0]
signal = coca.A_Omega / coca.G * coca.t_exp * i / (const.h * const.c * coca.r_h ** 2) * 1e-9
print(f"snr: {snr(signal * coca.G):4.2f}")
return 100 - snr(signal * coca.G)
sol = fsolve(func, 100)
print(filter_center, sol)
widths100.append(sol[0])
def func(width):
i = quad(integrand, filter_center - width / 2, filter_center + width / 2, args=(alpha))[
0]
signal = coca.A_Omega / coca.G * coca.t_exp * i / (const.h * const.c * coca.r_h ** 2) * 1e-9
print(f"snr: {snr(signal * coca.G):4.2f}")
return 80 - snr(signal * coca.G)
sol = fsolve(func, 100)
print(filter_center, sol)
widths80.append(sol[0])
def func(width):
i = quad(integrand, filter_center - width / 2, filter_center + width / 2, args=(alpha))[
0]
signal = coca.A_Omega / coca.G * coca.t_exp * i / (const.h * const.c * coca.r_h ** 2) * 1e-9
print(f"snr: {snr(signal * coca.G):4.2f}")
return 60 - snr(signal * coca.G)
sol = fsolve(func, 100)
print(filter_center, sol)
widths60.append(sol[0])
widths100 = np.array(widths100)
widths80 = np.array(widths80)
widths60 = np.array(widths60)
print(widths100)
print(widths80)
print(widths60)
data = {"c": centers,
"widths_100": widths100,
"widths_80": widths80,
"widths_60": widths60,
}
df = pd.DataFrame(data=data)
df.to_csv(f"data/widths_snr.csv", index=False)
return
def main(v=30, phase_angle=11):
CoCa = Camera()
df = pd.read_csv("data/texp.csv")
t10 = interp1d(df.alpha, df["texp10"], fill_value="extrapolate")
t80 = interp1d(df.alpha, df["texp80"], fill_value="extrapolate")
t_exp = (t80(phase_angle) + t10(phase_angle)) / 2
t_exp = t10(phase_angle) / (v / 10)
t_exp /= 1000
CoCa.t_exp = get_possible_detector_time(t_exp)
print(CoCa.t_exp)
solve_for_widths(CoCa, alpha=phase_angle)
c = np.linspace(400, 1000, 100)
df = pd.read_csv(f"data/widths_snr.csv")
widths100_avg = df.widths_100
widths80_avg = df.widths_80
widths60_avg = df.widths_60
centers = df.c
width100 = interp1d(centers, widths100_avg, kind="linear", fill_value="extrapolate")
width80 = interp1d(centers, widths80_avg, kind="linear", fill_value="extrapolate")
width60 = interp1d(centers, widths60_avg, kind="linear", fill_value="extrapolate")
plt.plot(c, width100(c), label="SNR 100")
plt.plot(c, width80(c), label="SNR 80")
plt.plot(c, width60(c), label="SNR 60")
plt.xlabel("center [nm]")
plt.ylabel("width [nm]")
plt.legend()
plt.show()
if __name__ == "__main__":
main()