def func(widths): blu_width, ora_width, red_width, nir_width, seed = widths t_exp = self.t_exp if mode != "C": # BLU blu_center = seed - ora_width / 2 - blu_width / 2 blu_signal = self.signal(blu_center, blu_width, t_exp) # ORA ora_center = seed ora_signal = self.signal(ora_center, ora_width, t_exp) # RED red_center = seed + ora_width / 2 + red_width / 2 red_signal = self.signal(red_center, red_width, t_exp) # NIR nir_center = seed + ora_width / 2 + red_width + nir_width / 2 nir_signal = self.signal(nir_center, nir_width, t_exp) else: # BLU blu_center = seed - red_width / 2 - ora_width - blu_width / 2 blu_signal = self.signal(blu_center, blu_width, t_exp) # ORA ora_center = seed - red_width / 2 - ora_width / 2 ora_signal = self.signal(ora_center, ora_width, t_exp) # RED red_center = seed red_signal = self.signal(red_center, red_width, t_exp) # NIR nir_center = seed + red_width / 2 + nir_width / 2 nir_signal = self.signal(nir_center, nir_width, t_exp) snr_diff_blu = self.snr_target - snr(blu_signal * self.coca.G) snr_diff_ora = self.snr_target - snr(ora_signal * self.coca.G) snr_diff_red = self.snr_target - snr(red_signal * self.coca.G) snr_diff_nir = self.snr_target - snr(nir_signal * self.coca.G) print( f"BLU snr = {snr(blu_signal * self.coca.G):.1f} width = {widths[0]:.1f}" ) print( f"ORA snr = {snr(ora_signal * self.coca.G):.1f} width = {widths[1]:.1f}" ) print( f"RED snr = {snr(red_signal * self.coca.G):.1f} width = {widths[2]:.1f}" ) print( f"NIR snr = {snr(nir_signal * self.coca.G):.1f} width = {widths[3]:.1f}" ) print(f"total bandwidth = {np.sum(widths[:4]):.1f}") widths_delta = (1100 - 400) - np.sum(widths[:4]) return np.max([ snr_diff_blu, snr_diff_ora, snr_diff_red, snr_diff_nir ]) + widths_delta**2
def func(widths): blu_width, ora_width, red_width, nir_width = widths # BLU edge = seed - ora_width / 2 i = quad(self.integrand, edge - blu_width, edge, args=(n, self.alpha))[0] blu_signal = self.coca.A_Omega / self.coca.G * self.t_exp * i / ( const.h * const.c * self.coca.r_h**2) * 1e-9 # ORA i = quad(self.integrand, seed - ora_width / 2, seed + ora_width / 2, args=(n, self.alpha))[0] ora_signal = self.coca.A_Omega / self.coca.G * self.t_exp * i / ( const.h * const.c * self.coca.r_h**2) * 1e-9 # RED edge = seed + ora_width / 2 i = quad(self.integrand, edge, edge + red_width, args=(n, self.alpha))[0] red_signal = self.coca.A_Omega / self.coca.G * self.t_exp * i / ( const.h * const.c * self.coca.r_h**2) * 1e-9 # NIR edge = seed + ora_width / 2 + red_width i = quad(self.integrand, edge, edge + nir_width, args=(n, self.alpha))[0] nir_signal = self.coca.A_Omega / self.coca.G * self.t_exp * i / ( const.h * const.c * self.coca.r_h**2) * 1e-9 snr_diff_blu = self.snr_target - snr(blu_signal * self.coca.G) snr_diff_ora = self.snr_target - snr(ora_signal * self.coca.G) snr_diff_red = self.snr_target - snr(red_signal * self.coca.G) snr_diff_nir = self.snr_target - snr(nir_signal * self.coca.G) print( f"BLU snr = {snr(blu_signal * self.coca.G):.1f} width = {widths[0]:.1f}" ) print( f"ORA snr = {snr(ora_signal * self.coca.G):.1f} width = {widths[1]:.1f}" ) print( f"RED snr = {snr(red_signal * self.coca.G):.1f} width = {widths[2]:.1f}" ) print( f"NIR snr = {snr(nir_signal * self.coca.G):.1f} width = {widths[3]:.1f}" ) return snr_diff_blu + snr_diff_ora + snr_diff_red + snr_diff_nir
def plot_snr(r_h=1, mode="A", ice=False, alpha=0): t_exps = np.linspace(0.22, 15, 10) / 1000 relative_velocities = [10, 30, 80] CoCa = Camera() CoCa.r_h = r_h df = pd.read_csv("data/texp.csv") t10 = interp1d(df.alpha, df["texp10"], fill_value="extrapolate") df = pd.read_csv(f"data/filters_{mode}.csv") colors = [BLUE, ORANGE, RED, BLACK] centers = df.centers widths = df.widths for filter_center, filter_width, color in zip(centers, widths, colors): snrs = [] for t_exp in t_exps: i = quad(integrand, filter_center - filter_width / 2, filter_center + filter_width / 2, args=(alpha, ice))[0] signal = CoCa.A_Omega / CoCa.G * t_exp * i / (const.h * const.c * CoCa.r_h ** 2) * 1e-9 snrs.append(snr(signal * CoCa.G)) print(snrs) t_func = interp1d(snrs,t_exps, fill_value="extrapolate", kind="quadratic") snr_cont = np.linspace(0, 180, 100) plt.plot(snr_cont, t_func(snr_cont)*1000, color=color, ls="-") plt.ylabel("t_exp [ms]") plt.xlabel("SNR") plt.savefig(f"plots/snr_vs_t_{r_h}au_{mode}_ice={ice}_{alpha}deg.pdf") plt.show()
def func(width): i = quad(integrand_low, filter_center - width / 2, filter_center + width / 2, args=(N, alpha))[0] signal = coca.A_Omega / coca.G * coca.t_exp * i / ( const.h * const.c * coca.r_h**2) * 1e-9 return snr(signal * coca.G) - 100
def plot_snr(r_h=1, mode="A", ice=False): relative_velocities = [10, 30, 80] CoCa = Camera() CoCa.r_h = r_h phase_angles = np.arange(0, 90, 10) df = pd.read_csv("data/texp.csv") t10 = interp1d(df.alpha, df["texp10"], fill_value="extrapolate") df = pd.read_csv(f"data/filters_{mode}.csv") colors = [BLUE, ORANGE, RED, BLACK] centers = df.centers widths = df.widths for v, ls in zip(relative_velocities, ["-", "-.", "--"]): print(f"calculating for v = {v} km/s") for filter_center, filter_width, color in zip(centers, widths, colors): snrs = [] t_exp = t10(11) / 1000 / (v / 10) i = quad(integrand, filter_center - filter_width / 2, filter_center + filter_width / 2, args=(11, ice))[0] signal = CoCa.A_Omega / CoCa.G * t_exp * i / (const.h * const.c * CoCa.r_h**2) * 1e-9 print( f"v = {v}, center = {filter_center:.2f}, SNR = {snr(signal * CoCa.G):.2f}" ) for alpha in phase_angles: t_exp = t10(alpha) / 1000 / (v / 10) i = quad(integrand, filter_center - filter_width / 2, filter_center + filter_width / 2, args=(alpha, ice))[0] signal = CoCa.A_Omega / CoCa.G * t_exp * i / ( const.h * const.c * CoCa.r_h**2) * 1e-9 snrs.append(snr(signal * CoCa.G)) snrs_func = interp1d(phase_angles, snrs, fill_value="extrapolate", kind="quadratic") phase_angles_cont = np.linspace(0, 90, 200) plt.plot(phase_angles_cont, snrs_func(phase_angles_cont), color=color, ls=ls) l1 = lines.Line2D([], [], color='black', ls="-") l2 = lines.Line2D([], [], color='black', ls="-.") l3 = lines.Line2D([], [], color='black', ls="--") plt.legend(handles=[l1, l2, l3], labels=["v = 10 km/s", "v = 30 km/s", "v = 80 km/s"], fancybox=True, framealpha=1, shadow=True, borderpad=1) plt.xlabel("phase angle [°]") plt.ylabel("SNR") plt.savefig(f"plots/snrs_{r_h}au_{mode}_ice={ice}_new_new.pdf") plt.show()
def func(t_exp): i = quad(integrand, filter_center - filter_width / 2, filter_center + filter_width / 2, args=(N, alpha))[0] signal = CoCa.A_Omega / CoCa.G * t_exp * i / (const.h * const.c * CoCa.r_h ** 2) * 1e-9 return snr(signal * CoCa.G) - 100
def run(self, mode="A"): def func(widths): blu_width, ora_width, red_width, nir_width, seed = widths t_exp = self.t_exp if mode != "C": # BLU blu_center = seed - ora_width / 2 - blu_width / 2 blu_signal = self.signal(blu_center, blu_width, t_exp) # ORA ora_center = seed ora_signal = self.signal(ora_center, ora_width, t_exp) # RED red_center = seed + ora_width / 2 + red_width / 2 red_signal = self.signal(red_center, red_width, t_exp) # NIR nir_center = seed + ora_width / 2 + red_width + nir_width / 2 nir_signal = self.signal(nir_center, nir_width, t_exp) else: # BLU blu_center = seed - red_width / 2 - ora_width - blu_width / 2 blu_signal = self.signal(blu_center, blu_width, t_exp) # ORA ora_center = seed - red_width / 2 - ora_width / 2 ora_signal = self.signal(ora_center, ora_width, t_exp) # RED red_center = seed red_signal = self.signal(red_center, red_width, t_exp) # NIR nir_center = seed + red_width / 2 + nir_width / 2 nir_signal = self.signal(nir_center, nir_width, t_exp) snr_diff_blu = self.snr_target - snr(blu_signal * self.coca.G) snr_diff_ora = self.snr_target - snr(ora_signal * self.coca.G) snr_diff_red = self.snr_target - snr(red_signal * self.coca.G) snr_diff_nir = self.snr_target - snr(nir_signal * self.coca.G) print( f"BLU snr = {snr(blu_signal * self.coca.G):.1f} width = {widths[0]:.1f}" ) print( f"ORA snr = {snr(ora_signal * self.coca.G):.1f} width = {widths[1]:.1f}" ) print( f"RED snr = {snr(red_signal * self.coca.G):.1f} width = {widths[2]:.1f}" ) print( f"NIR snr = {snr(nir_signal * self.coca.G):.1f} width = {widths[3]:.1f}" ) print(f"total bandwidth = {np.sum(widths[:4]):.1f}") widths_delta = (1100 - 400) - np.sum(widths[:4]) return np.max([ snr_diff_blu, snr_diff_ora, snr_diff_red, snr_diff_nir ]) + widths_delta**2 if mode == "A": bounds = ((0, 250), (0, 250), (0, 250), (0, 250), (650, 651)) seed = 650 elif mode == "B": bounds = ((0, 250), (0, 250), (0, 250), (0, 250), (500, 650)) seed = 650 else: bounds = ((0, 250), (0, 250), (0, 250), (0, 250), (650, 650.1)) seed = 650 sol = minimize(func, (150, 100, 100, 150, seed), bounds=bounds) blu_width = sol.x[0] ora_width = sol.x[1] red_width = sol.x[2] nir_width = sol.x[3] seed = sol.x[4] if mode != "C": blu_center = seed - ora_width / 2 - blu_width / 2 ora_center = seed red_center = seed + ora_width / 2 + red_width / 2 nir_center = seed + ora_width / 2 + red_width + nir_width / 2 else: blu_center = seed - red_width / 2 - ora_width - blu_width / 2 ora_center = seed - red_width / 2 - ora_width / 2 red_center = seed nir_center = seed + red_width / 2 + nir_width / 2 print(f"BLUE: center = {blu_center:4.2f}, width = {blu_width:4.2f}") print(f"ORA: center = {ora_center:4.2f}, width = {ora_width:4.2f}") print(f"RED: center = {red_center:4.2f}, width = {red_width:4.2f}") print(f"NIR: center = {nir_center:4.2f}, width = {nir_width:4.2f}") print(f"t_exp = {self.t_exp * 1000:.2f} ms") centers = [blu_center, ora_center, red_center, nir_center] widths = [blu_width, ora_width, red_width, nir_width] d = {"centers": centers, "widths": widths} df = pd.DataFrame(data=d) df.to_csv(f"data/filters_{mode}.csv", index=False) return phase_angles = np.arange(1, 90, 10) snrs = np.zeros((len(phase_angles), 4)) k = 0 df = pd.read_csv("data/texp.csv") t = interp1d(df.alpha, df["texp10"], fill_value="extrapolate") for alpha in phase_angles: t_exp = t(alpha) / (self.v / 10) / 1000 j = 0 for c, w in zip(centers, widths): i = quad(integrand, c - w / 2, c + w / 2, args=(alpha))[0] signal = coca.A_Omega / coca.G * t_exp * i / ( const.h * const.c * coca.r_h**2) * 1e-9 snrs[k, j] = snr(signal * coca.G) j += 1 k += 1 plt.plot(phase_angles, snrs[:, 0], label="BLU", color=BLUE) plt.plot(phase_angles, snrs[:, 1], label="ORA", color=ORANGE) plt.plot(phase_angles, snrs[:, 2], label="RED", color=RED) plt.plot(phase_angles, snrs[:, 3], label="NIR", color=BLACK) plt.legend() plt.title(rf"$v$={self.v} km/s") plt.ylabel("SNR [-]") plt.xlabel(r"$\alpha$ [°]") plt.savefig("plots/snrs.pdf") plt.show()
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)