Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions flarestack/core/llh.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def create_acceptance_function(self):
with open(acc_path, "rb") as f:
[dec_bins, gamma_bins, acc] = pickle.load(f)

f = scipy.interpolate.interp2d(dec_bins, gamma_bins, acc.T, kind="linear")
f = scipy.interpolate.RectBivariateSpline(dec_bins, gamma_bins, acc, kx=1, ky=1)
return f

def new_acceptance(self, source, params=None):
Expand All @@ -845,7 +845,7 @@ def new_acceptance(self, source, params=None):
dec = source["dec_rad"]
gamma = params[-1]

return self.acceptance_f(dec, gamma)
return self.acceptance_f(dec, gamma)[0, :]

def create_kwargs(self, data, pull_corrector, weight_f=None):
kwargs = dict()
Expand Down Expand Up @@ -1480,9 +1480,8 @@ def create_kwargs(self, data, pull_corrector, weight_f=None):
coincident_data = data[coincident_nu_mask]
coincident_sources = self.sources[coincident_source_mask]

season_weight = lambda x: weight_f([1.0, x], self.season)[
coincident_source_mask
]
def season_weight(x):
return weight_f([1.0, x], self.season)[coincident_source_mask]

SoB_energy_cache = self.create_SoB_energy_cache(coincident_data)

Expand Down
33 changes: 20 additions & 13 deletions flarestack/icecube_utils/reference_sensitivity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging
import os

import numpy as np
from scipy.interpolate import interp1d, interp2d
from scipy.interpolate import RectBivariateSpline

from flarestack.data.icecube.ic_season import get_published_sens_ref_dir

Expand Down Expand Up @@ -62,10 +61,12 @@ def reference_7year_sensitivity(sindec=np.array(0.0), gamma=2.0):

sens = np.vstack((sens[0], sens))
sens = np.vstack((sens, sens[-1]))
sens_ref = interp2d(np.array(sindecs), np.array(gammas), np.log(sens.T))
sens_ref = RectBivariateSpline(
np.array(sindecs), np.array(gammas), np.log(sens), kx=1, ky=1
)

if np.array(sindec).ndim > 0:
return np.array([np.exp(sens_ref(x, gamma))[0] for x in sindec])
return np.array([np.exp(sens_ref(x, gamma).squeeze()) for x in sindec])
else:
return np.exp(sens_ref(sindec, gamma))

Expand Down Expand Up @@ -98,12 +99,14 @@ def reference_7year_discovery_potential(sindec=0.0, gamma=2.0):

disc = np.vstack((disc[0], disc))
disc = np.vstack((disc, disc[-1]))
disc_ref = interp2d(np.array(sindecs), np.array(gammas), np.log(disc.T))
disc_ref = RectBivariateSpline(
np.array(sindecs), np.array(gammas), np.log(disc), kx=1, ky=1
)

if np.array(sindec).ndim > 0:
return np.array([np.exp(disc_ref(x, gamma))[0] for x in sindec])
return np.array([np.exp(disc_ref(x, gamma).squeeze()) for x in sindec])
else:
return np.exp(disc_ref(sindec, gamma))
return np.exp(disc_ref(sindec, gamma).squeeze())


def reference_10year_sensitivity(sindec=np.array(0.0), gamma=2.0):
Expand All @@ -130,12 +133,14 @@ def reference_10year_sensitivity(sindec=np.array(0.0), gamma=2.0):
scaling = np.array([10 ** (3 * (i)) for i in range(2)])
sens *= scaling

sens_ref = interp2d(np.array(sindecs), np.array(gammas), np.log(sens.T))
sens_ref = RectBivariateSpline(
np.array(sindecs), np.array(gammas), np.log(sens), kx=1, ky=1
)

if np.array(sindec).ndim > 0:
return np.array([np.exp(sens_ref(x, gamma))[0] for x in sindec])
return np.array([np.exp(sens_ref(x, gamma).squeeze()) for x in sindec])
else:
return np.exp(sens_ref(sindec, gamma))
return np.exp(sens_ref(sindec, gamma).squeeze())


def reference_10year_discovery_potential(sindec=np.array(0.0), gamma=2.0):
Expand All @@ -162,9 +167,11 @@ def reference_10year_discovery_potential(sindec=np.array(0.0), gamma=2.0):
scaling = np.array([10 ** (3 * i) for i in range(2)])
sens *= scaling

sens_ref = interp2d(np.array(sindecs), np.array(gammas), np.log(sens.T))
sens_ref = RectBivariateSpline(
np.array(sindecs), np.array(gammas), np.log(sens), kx=1, ky=1
)

if np.array(sindec).ndim > 0:
return np.array([np.exp(sens_ref(x, gamma))[0] for x in sindec])
return np.array([np.exp(sens_ref(x, gamma).squeeze()) for x in sindec])
else:
return np.exp(sens_ref(sindec, gamma))
return np.exp(sens_ref(sindec, gamma).squeeze())
4 changes: 3 additions & 1 deletion flarestack/utils/percentile_SoB.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def make_plot(hist, savepath, normed=True):

order = 1

spline = scipy.interpolate.interp2d(x, y, np.log(ratio))
spline = scipy.interpolate.RectBivariateSpline(
x, y, np.log(ratio.T), kx=order, ky=order
)

for x_val in [2.0, 3.0, 7.0]:
print(x_val, spline(0.0, x_val), spline(0.5, x_val))
Expand Down
Loading