-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some changes for the run settings of pyblastafterglow.
- Loading branch information
haukekoehn
committed
Dec 10, 2024
1 parent
8e6f126
commit a09e86c
Showing
9 changed files
with
170 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
flux_models/pyblastafterglow_tophat/benchmark_pyblastafterglow_tophat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from fiesta.train.BenchmarkerFluxes import Benchmarker | ||
from fiesta.inference.lightcurve_model import AfterglowpyPCA | ||
from fiesta.utils import Filter | ||
|
||
|
||
name = "tophat" | ||
model_dir = f"./model/" | ||
FILTERS = ["radio-3GHz", "radio-6GHz", "bessellv"] | ||
|
||
for metric_name in ["$\\mathcal{L}_2$", "$\\mathcal{L}_\infty$"]: | ||
if metric_name == "$\\mathcal{L}_2$": | ||
file_ending = "L2" | ||
else: | ||
file_ending = "Linf" | ||
|
||
B = Benchmarker(name = name, | ||
model_dir = model_dir, | ||
MODEL = AfterglowpyPCA, | ||
filters = FILTERS, | ||
metric_name = metric_name, | ||
) | ||
|
||
|
||
for filt in FILTERS: | ||
|
||
fig, ax = B.plot_lightcurves_mismatch(filter =filt, parameter_labels = ["$\\iota$", "$\log_{10}(E_0)$", "$\\theta_{\\mathrm{c}}$", "$\log_{10}(n_{\mathrm{ism}})$", "$p$", "$\\epsilon_E$", "$\\epsilon_B$", "$\\Gamma_0$"]) | ||
fig.savefig(f"./benchmarks/benchmark_{filt}_{file_ending}.pdf", dpi = 200) | ||
|
||
B.print_correlations(filter = filt) | ||
|
||
fig, ax = B.plot_worst_lightcurves() | ||
fig.savefig(f"./benchmarks/worst_lightcurves_{file_ending}.pdf", dpi = 200) | ||
|
||
|
||
fig, ax = B.plot_error_distribution() | ||
fig.savefig(f"./benchmarks/error_distribution.pdf", dpi = 200) | ||
|
||
fig, ax = B.plot_error_over_time() | ||
fig.savefig(f"./benchmarks/error_over_time.pdf", dpi = 200) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import h5py | ||
import numpy as np | ||
import shutil | ||
import tqdm | ||
|
||
##### | ||
|
||
directory = "./model" | ||
|
||
##### | ||
|
||
outfile = os.path.join(directory, "pyblastafterglow_raw_data.h5") | ||
file_list = [f for f in os.listdir(directory) if f.endswith(".h5")] | ||
shutil.copy(os.path.join(directory, file_list[0]), outfile) | ||
|
||
with h5py.File(outfile, "a") as f: | ||
|
||
for file in tqdm.tqdm(file_list[1:]): | ||
file = h5py.File(os.path.join(directory, file)) | ||
for group in ["train", "val", "test"]: | ||
X = file[group]["X"] | ||
Xset = f[group]["X"] | ||
Xset.resize(Xset.shape[0]+X.shape[0], axis = 0) | ||
Xset[-X.shape[0]:] = X | ||
|
||
y = file[group]["y"] | ||
yset = f[group]["y"] | ||
yset.resize(yset.shape[0]+y.shape[0], axis = 0) | ||
yset[-y.shape[0]:] = y | ||
file.close() | ||
|
||
print("train: ", f["train"]["y"].shape[0]) | ||
print("val: ", f["val"]["y"].shape[0]) | ||
print("test: ", f["test"]["y"].shape[0]) | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
flux_models/pyblastafterglow_tophat/plot_training_data_distribution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import numpy as np | ||
import corner | ||
import matplotlib.pyplot as plt | ||
import h5py | ||
|
||
default_corner_kwargs = dict(bins=40, | ||
smooth=1., | ||
label_kwargs=dict(fontsize=16), | ||
title_kwargs=dict(fontsize=16), | ||
#color = "blue" | ||
# quantiles=[], | ||
# levels=[0.9], | ||
plot_density=False, | ||
plot_datapoints=True, | ||
plot_contours = False, | ||
fill_contours=False, | ||
max_n_ticks=4, | ||
min_n_ticks=3, | ||
save=False, | ||
truth_color="red") | ||
|
||
####### | ||
|
||
file = "./model/pyblastafterglow_raw_data.h5" | ||
|
||
####### | ||
|
||
|
||
with h5py.File(file, "r") as f: | ||
X = f["train"]["X"][:] | ||
parameter_names = f["parameter_names"][()] | ||
|
||
|
||
corner.corner(X, **default_corner_kwargs, labels = parameter_names) | ||
plt.show() | ||
breakpoint() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters