Skip to content

Commit

Permalink
Improve Giese LISA fig 2 script
Browse files Browse the repository at this point in the history
  • Loading branch information
AgenttiX committed Dec 7, 2024
1 parent 5c791aa commit 951b91f
Showing 1 changed file with 57 additions and 39 deletions.
96 changes: 57 additions & 39 deletions examples/giese_lisa_fig2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_kappa(bubble: Bubble) -> float:
def kappa_giese(params: np.ndarray, model: ConstCSModel) -> float:
v_wall, alpha_tbn_giese = params
try:
kappa, _, _, _, _ = kappaNuMuModel(
kappa, v_arr, wow_arr, xi_arr, mode, vp, vm = kappaNuMuModel(
# cs2s=model.cs2(model.w_crit, Phase.SYMMETRIC),
# cs2b=model.cs2(model.w_crit, Phase.BROKEN),
cs2s=model.css2,
Expand All @@ -66,7 +66,7 @@ def kappas_giese(
for i, alpha_n in enumerate(alpha_ns):
try:
wn = model.w_n(alpha_n, theta_bar=theta_bar)
alpha_tbns[i] = model.alpha_n_from_alpha_theta_bar_n(alpha_theta_bar_n=alpha_n, wn=wn)
alpha_tbns[i] = model.alpha_theta_bar_n_from_alpha_n(alpha_n=alpha_n, wn=wn)
except (ValueError, RuntimeError):
alpha_tbns[i] = np.nan

Expand All @@ -89,16 +89,16 @@ def kappas_giese(


def create_figure(
ax: plt.Axes,
axs: tp.Iterable[plt.Axes],
models: tp.List[ConstCSModel],
alpha_ns: np.ndarray,
colors: tp.List[str],
lss: tp.List[str],
v_walls: np.ndarray,
theta_bar: bool = False,
giese: bool = False):
kappas = np.empty((len(models), alpha_ns.size, v_walls.size))
for i_model, model in enumerate(models):
ls = "--" if i_model in [2, 3] else "-"
for i_model, (model, ls) in enumerate(zip(models, lss)):
if giese:
if kappaNuMuModel is None:
kappas[i_model, :, :] = np.nan
Expand All @@ -115,9 +115,10 @@ def create_figure(
logger.error(f"Could not produce bubbles with alpha_n={alpha_n} for {model.label_unicode}")
continue
kwargs = {}
if ls == "-":
kwargs["label"] = rf"$\alpha={alpha_ns[i_alpha_n]}$"
ax.plot(v_walls, kappas[i_model, i_alpha_n, :], ls=ls, color=color, alpha=0.5, **kwargs)
# if ls == "-":
# kwargs["label"] = rf"$\alpha={alpha_ns[i_alpha_n]}$"
for ax in axs:
ax.plot(v_walls, kappas[i_model, i_alpha_n, :], ls=ls, color=color, alpha=0.5, **kwargs)
logger.info(
f"alpha_n={alpha_n}, kappa_max={kappas[i_model, i_alpha_n, i_max]}, i_max={i_max}, "
f"v_wall={v_walls[i_max]}, color={color}, ls={ls}, {model.label_unicode}"
Expand All @@ -127,13 +128,6 @@ def create_figure(
logger.info(
"Failed v_walls: %s",
v_walls[failed_inds].flatten())

ax.set_ylabel(r"$\kappa_{\bar{\theta}_n}$")
ax.set_ylim(bottom=10 ** -2.5, top=1)
ax.set_xlabel(r"$v_\text{wall}$")
ax.set_yscale("log")
ax.set_xlim(v_walls.min(), v_walls.max())

title = ""
if giese:
title += "Giese et al."
Expand All @@ -144,7 +138,15 @@ def create_figure(
title += r"$\alpha_{\bar{\theta}_n}$"
else:
title += r"$\alpha_n$"
ax.set_title(title)

for ax in axs:
ax.set_ylabel(r"$\kappa_{\bar{\theta}_n}$")
ax.set_ylim(bottom=10 ** -2.5, top=1)
ax.set_xlabel(r"$v_\text{wall}$")
ax.set_yscale("log")
ax.set_xlim(v_walls.min(), v_walls.max())
ax.set_title(title)

return kappas


Expand All @@ -155,15 +157,16 @@ def create_diff_figure(
models: tp.List[ConstCSModel],
v_walls: np.ndarray,
colors: tp.List[str],
theta_bar: bool):
lss: tp.List[str],
theta_bar: bool,
title: bool = True):
rel_diffs = np.abs(kappas_pttools - kappas_giese) / kappas_giese
if theta_bar:
title = r"$\alpha_{\bar{\theta}_n}$"
title_str = r"$\alpha_{\bar{\theta}_n}$"
else:
title = r"$\alpha_n$"
print(title)
for i_model, model in enumerate(models):
ls = "--" if i_model in [2, 3] else "-"
title_str = r"$\alpha_n$"
print(title_str)
for i_model, (model, ls) in enumerate(zip(models, lss)):
for i_alpha in range(kappas_pttools.shape[1]):
ax.plot(
v_walls,
Expand All @@ -181,14 +184,16 @@ def create_diff_figure(
ax.set_yscale("log")
ax.set_ylim(10**(-6), 1)
ax.set_xlim(v_walls.min(), v_walls.max())
ax.set_title(title)
if title:
ax.set_title(title_str)


def main():
alpha_thetabar_ns = np.array([0.01, 0.03, 0.1, 0.3, 1, 3])
colors = ["b", "y", "r", "g", "purple", "grey"]
n_v_walls = 20 if GITHUB_ACTIONS else 50
v_walls = np.linspace(0.2, 0.95, n_v_walls)
lss = ["-", "--", ":", "-."]
a_s = 5
a_b = 1
V_s = 1
Expand All @@ -202,55 +207,68 @@ def main():
for model in models:
logger.info("Model parameters: %s", model.params_str())

figsize_x = 10
fig1: plt.Figure = plt.figure(figsize=(figsize_x, 8))
fig2: plt.Figure = plt.figure(figsize=(figsize_x, 6))
figsize_x = 8
fig1: plt.Figure = plt.figure(figsize=(figsize_x, 6))
fig2: plt.Figure = plt.figure(figsize=(figsize_x, 4))
fig3: plt.Figure = plt.figure(figsize=(figsize_x, 4))
fig4: plt.Figure = plt.figure(figsize=(figsize_x, 4))
axs1 = fig1.subplots(2, 2)
axs2 = fig2.subplots(1, 2)
axs3 = fig3.subplots(1, 2)
ax4 = fig4.add_subplot()

start_time = time.perf_counter()
kappas_giese_atbn = create_figure(
ax=axs1[1, 0],
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, v_walls=v_walls,
axs=(axs1[1, 0], ),
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, lss=lss, v_walls=v_walls,
theta_bar=True, giese=True
)
kappas_giese_an = create_figure(
ax=axs1[1, 1],
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, v_walls=v_walls,
axs=(axs1[1, 1], axs3[1]),
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, lss=lss, v_walls=v_walls,
theta_bar=False, giese=True
)
giese_time = time.perf_counter()
logger.info(f"Creating Giese kappa figures took {giese_time - start_time:.2f} s.")
kappas_pttools_atbn = create_figure(
ax=axs1[0, 0],
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, v_walls=v_walls,
axs=(axs1[0, 0], ),
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, lss=lss, v_walls=v_walls,
theta_bar=True
)
kappas_pttools_an = create_figure(
ax=axs1[0, 1],
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, v_walls=v_walls,
axs=(axs1[0, 1], axs3[0]),
models=models, alpha_ns=alpha_thetabar_ns, colors=colors, lss=lss, v_walls=v_walls,
theta_bar=False
)
print("v_walls")
print(v_walls)
create_diff_figure(
ax=axs2[0],
kappas_pttools=kappas_pttools_atbn, kappas_giese=kappas_giese_atbn,
models=models, colors=colors, v_walls=v_walls, theta_bar=True
models=models, colors=colors, lss=lss, v_walls=v_walls, theta_bar=True
)
create_diff_figure(
ax=axs2[1],
kappas_pttools=kappas_pttools_an, kappas_giese=kappas_giese_an,
models=models, colors=colors, v_walls=v_walls, theta_bar=False
models=models, colors=colors, lss=lss, v_walls=v_walls, theta_bar=False
)
create_diff_figure(
ax=ax4,
kappas_pttools=kappas_pttools_an, kappas_giese=kappas_giese_an,
models=models, colors=colors, lss=lss, v_walls=v_walls, theta_bar=False, title=False
)
logger.info(f"Creating PTtools kappa figures took {time.perf_counter() - giese_time:.2f} s.")
fig1.tight_layout()
fig2.tight_layout()
return fig1, fig2
fig3.tight_layout()
fig4.tight_layout()
return fig1, fig2, fig3, fig4


if __name__ == "__main__":
fig, fig2 = main()
fig, fig2, fig3, fig4 = main()
save(fig, "giese_lisa_fig2")
save(fig, "giese_lisa_fig2_diff")
save(fig2, "giese_lisa_fig2_diff")
save(fig3, "giese_lisa_fig2_alpha_n")
save(fig4, "giese_lisa_fig2_alpha_n_diff")
plt.show()

0 comments on commit 951b91f

Please sign in to comment.