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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ jobs:
ruff check .
ruff format --check .

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: Install pyright
run: pip install ".[dev,extras]"
- name: Run pyright
run: pyright

pytest:
runs-on: ubuntu-latest
strategy:
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Issues = "https://github.com/icecube/skyllh/issues"
dev = [
"pre-commit",
"pytest>=9.0.0",
"pyright",
"ruff>=0.16",
]
docs = [
Expand Down Expand Up @@ -95,3 +96,13 @@ quote-style = "single"
minversion = "9.0"
addopts = ["-ra"]
testpaths = ["tests"]

[tool.pyright]
pythonVersion = "3.11"
typeCheckingMode = "standard"
reportUnnecessaryTypeIgnoreComment = "warning"

include = [
"skyllh",
"tests",
]
4 changes: 4 additions & 0 deletions skyllh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import logging
import multiprocessing as mp
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from skyllh.datasets import create_datasets

__all__ = [
'create_datasets',
Expand Down
79 changes: 49 additions & 30 deletions skyllh/analyses/i3/publicdata_ps/aeff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from collections.abc import Sequence
from typing import cast

import numpy as np
from scipy import interpolate

Expand All @@ -13,27 +16,29 @@
)


def load_effective_area_array(pathfilenames):
def load_effective_area_array(
pathfilenames: str | Sequence[str],
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""Loads the (nbins_decnu, nbins_log10enu)-shaped 2D effective
area array from the given data file.

Parameters
----------
pathfilename : str | list of str
The file name of the data file.
pathfilenames
The file name(s) of the data file(s).

Returns
-------
aeff_decnu_log10enu : (nbins_decnu, nbins_log10enu)-shaped 2D ndarray
aeff_decnu_log10enu
The ndarray holding the effective area for each
(dec_nu,log10(E_nu/GeV)) bin.
decnu_binedges_lower : (nbins_decnu,)-shaped ndarray
decnu_binedges_lower
The ndarray holding the lower bin edges of the dec_nu axis.
decnu_binedges_upper : (nbins_decnu,)-shaped ndarray
decnu_binedges_upper
The ndarray holding the upper bin edges of the dec_nu axis.
log10_enu_binedges_lower : (nbins_log10enu,)-shaped ndarray
log10_enu_binedges_lower
The ndarray holding the lower bin edges of the log10(E_nu/GeV) axis.
log10_enu_binedges_upper : (nbins_log10enu,)-shaped ndarray
log10_enu_binedges_upper
The ndarray holding the upper bin edges of the log10(E_nu/GeV) axis.
"""
loader = create_FileLoader(pathfilenames=pathfilenames)
Expand Down Expand Up @@ -95,25 +100,32 @@ class PDAeff:
the public data.
"""

def __init__(self, pathfilenames, src_dec=None, min_log10enu=None, max_log10enu=None, **kwargs):
def __init__(
self,
pathfilenames: str | list[str],
src_dec: float | None = None,
min_log10enu: float | None = None,
max_log10enu: float | None = None,
**kwargs,
):
"""Creates an effective area instance by loading the effective area
data from the given file.

Parameters
----------
pathfilenames : str | list of str
The path file names of the effective area data file(s) which should
pathfilenames
The path file name(s) of the effective area data file(s) which should
be used for this public data effective area instance.
src_dec : float | None
src_dec
The source declination in radians for which detection probabilities
should get pre-calculated using the ``get_detection_prob_for_decnu``
method.
min_log10enu : float | None
min_log10enu
The minimum log10(E_nu/GeV) value that should be used for
calculating the detection probability.
If None, the lowest available neutrino energy bin edge of the
effective area is used.
max_log10enu : float | None
max_log10enu
The maximum log10(E_nu/GeV) value that should be used for
calculating the detection probability.
If None, the highest available neutrino energy bin edge of the
Expand Down Expand Up @@ -185,7 +197,7 @@ def decnu_bincenters(self):
return get_bincenters_from_binedges(self._decnu_binedges)

@property
def n_decnu_bins(self):
def n_decnu_bins(self) -> int:
"""(read-only) The number of bins of the neutrino declination axis."""
return len(self._decnu_binedges) - 1

Expand Down Expand Up @@ -218,7 +230,7 @@ def log10_enu_bincenters(self):
return get_bincenters_from_binedges(self._log10_enu_binedges)

@property
def n_log10_enu_bins(self):
def n_log10_enu_bins(self) -> int:
"""(read-only) The number of bins of the log10 neutrino energy axis."""
return len(self._log10_enu_binedges) - 1

Expand All @@ -229,31 +241,31 @@ def aeff_decnu_log10enu(self):
"""
return self._aeff_decnu_log10enu

def create_sin_decnu_log10_enu_spline(self):
def create_sin_decnu_log10_enu_spline(self) -> FctSpline2D:
"""DEPRECATED!
Creates a FctSpline2D object representing a 2D spline of the
effective area in sin(dec_nu)-log10(E_nu/GeV)-space.

Returns
-------
spl : FctSpline2D instance
spl
The FctSpline2D instance representing a spline in the
sin(dec_nu)-log10(E_nu/GeV)-space.
"""
spl = FctSpline2D(self._aeff_decnu_log10enu, self.sin_decnu_binedges, self.log10_enu_binedges)
return spl

def get_aeff_for_decnu(self, decnu):
def get_aeff_for_decnu(self, decnu: float) -> np.ndarray:
"""Retrieves the effective area as function of log10_enu.

Parameters
----------
decnu : float
decnu
The true neutrino declination.

Returns
-------
aeff : (n,)-shaped numpy ndarray
aeff
The effective area in cm^2 for the given true neutrino declination
as a function of log10 true neutrino energy.
"""
Expand All @@ -263,26 +275,33 @@ def get_aeff_for_decnu(self, decnu):

return aeff

def get_detection_prob_for_decnu(self, decnu, enu_min, enu_max, enu_range_min, enu_range_max):
def get_detection_prob_for_decnu(
self,
decnu: float,
enu_min: float | np.ndarray,
enu_max: float | np.ndarray,
enu_range_min: float,
enu_range_max: float,
) -> np.ndarray:
"""Calculates the detection probability for given true neutrino energy
ranges for a given neutrino declination.

Parameters
----------
decnu : float
decnu
The neutrino declination in radians.
enu_min : float | ndarray of float
enu_min
The minimum energy in GeV.
enu_max : float | ndarray of float
enu_max
The maximum energy in GeV.
enu_range_min : float
enu_range_min
The minimum energy in GeV of the entire energy range.
enu_range_max : float
enu_range_max
The maximum energy in GeV of the entire energy range.

Returns
-------
det_prob : ndarray of float
det_prob
The neutrino energy detection probabilities for the given true
enegry ranges.
"""
Expand Down Expand Up @@ -323,13 +342,13 @@ def get_detection_prob_for_decnu(self, decnu, enu_min, enu_max, enu_range_min, e

spl = interpolate.splrep(x, y, k=1, s=0)

norm = interpolate.splint(enu_range_min, enu_range_max, spl)
norm = cast(float, interpolate.splint(enu_range_min, enu_range_max, spl))

enu_min = np.atleast_1d(enu_min)
enu_max = np.atleast_1d(enu_max)

det_prob = np.empty((len(enu_min),), dtype=np.double)
for i in range(len(enu_min)):
det_prob[i] = interpolate.splint(enu_min[i], enu_max[i], spl) / norm
det_prob[i] = cast(float, interpolate.splint(enu_min[i], enu_max[i], spl)) / norm

return det_prob
Loading