-
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.
Merge pull request #7 from StFroese/ulfactory
add ULFactory
- Loading branch information
Showing
7 changed files
with
530 additions
and
174 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = titrate | ||
version = 0.3.0 | ||
version = 0.4.0 | ||
author = Stefan Fröse | ||
author_email = [email protected] | ||
description = asympTotic lIkelihood Tests for daRk mAtTer sEarch | ||
|
@@ -27,6 +27,8 @@ install_requires = | |
matplotlib | ||
gammapy | ||
joblib | ||
astropy | ||
h5py | ||
|
||
[options.extras_require] | ||
tests = | ||
|
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,91 @@ | ||
import h5py | ||
import matplotlib.pyplot as plt | ||
from astropy import visualization as viz | ||
from astropy.table import QTable, unique | ||
|
||
|
||
class UpperLimitPlotter: | ||
def __init__(self, path, channel, axes=None): | ||
self.path = path | ||
self.axes = axes if axes is not None else plt.gca() | ||
|
||
try: | ||
table = QTable.read(self.path, path=channel) | ||
except OSError: | ||
channels = list(h5py.File("/Users/stefan/Downloads/test.hdf5").keys()) | ||
channels = [ch for ch in channels if "meta" not in ch] | ||
raise KeyError( | ||
f"Channel {channel} not in dataframe. " f"Choose from {channels}" | ||
) | ||
|
||
self.channel = channel | ||
|
||
masses = table["mass"] | ||
uls = table["ul"] | ||
median = table["median_ul"] | ||
one_sigma_minus = table["1sigma_minus_ul"] | ||
one_sigma_plus = table["1sigma_plus_ul"] | ||
two_sigma_minus = table["2sigma_minus_ul"] | ||
two_sigma_plus = table["2sigma_plus_ul"] | ||
|
||
with viz.quantity_support(): | ||
self.plot_channel( | ||
masses, | ||
uls, | ||
median, | ||
one_sigma_minus, | ||
one_sigma_plus, | ||
two_sigma_minus, | ||
two_sigma_plus, | ||
) | ||
|
||
self.axes.set_xscale("log") | ||
self.axes.set_yscale("log") | ||
|
||
cl_type = unique(table[table["channel"] == self.channel], keys="cl_type")[ | ||
"cl_type" | ||
][0] | ||
cl = unique(table[table["channel"] == self.channel], keys="cl")["cl"][0] | ||
self.axes.set_xlabel(f"m / {masses.unit:latex}") | ||
self.axes.set_ylabel( | ||
rf"$CL_{cl_type}^{{{cl}}}$ upper limit on $< \sigma v>$ / {uls.unit:latex}" | ||
) | ||
|
||
self.axes.set_title(f"Annihilation Upper Limits for channel {self.channel}") | ||
|
||
self.axes.legend() | ||
|
||
def plot_channel( | ||
self, | ||
masses, | ||
uls, | ||
median, | ||
one_sigma_minus, | ||
one_sigma_plus, | ||
two_sigma_minus, | ||
two_sigma_plus, | ||
): | ||
self.axes.plot(masses, uls, color="tab:orange", label="Upper Limits") | ||
self.axes.plot(masses, median, color="tab:blue", label="Expected Upper Limits") | ||
self.axes.fill_between( | ||
masses, | ||
median, | ||
one_sigma_plus, | ||
color="tab:blue", | ||
alpha=0.75, | ||
label=r"$1\sigma$-region", | ||
) | ||
self.axes.fill_between( | ||
masses, median, one_sigma_minus, color="tab:blue", alpha=0.75 | ||
) | ||
self.axes.fill_between( | ||
masses, | ||
one_sigma_plus, | ||
two_sigma_plus, | ||
color="tab:blue", | ||
alpha=0.5, | ||
label=r"$2\sigma$-region", | ||
) | ||
self.axes.fill_between( | ||
masses, one_sigma_minus, two_sigma_minus, color="tab:blue", alpha=0.5 | ||
) |
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