Skip to content
Merged
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: 1 addition & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ repos:
hooks:
- id: blacken-docs
args: [-l 100]
- repo: https://github.com/pycqa/pylint
rev: v4.0.5
hooks:
- id: pylint
files: simweights
exclude: ^contrib/
additional_dependencies: [numpy, pandas]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.9
rev: v0.15.12
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ To run pre-commit on all files without making a commit you can just run::

in the base of the simweights directory.

The checks include isort, flake8, pylint, and mypy.
The checks include isort, and mypy.
Be sure that all checks pass before submitting a pull request.

Tests
Expand Down
4 changes: 2 additions & 2 deletions examples/without_tableio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
# get the info from the frame
info = frame["I3PrimaryInjectorInfo"]

for k in I3PrimaryInjectorInfo:
I3PrimaryInjectorInfo[k].append(getattr(info, k))
for k, v in I3PrimaryInjectorInfo.items():
v.append(getattr(info, k))

# if this is a physics event in the right sub-event stream
elif frame.Stop == frame.Physics and frame["I3EventHeader"].sub_event_stream == "InIceSplit":
Expand Down
19 changes: 4 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ classifiers = [
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
Expand All @@ -31,10 +29,10 @@ keywords = ["python", "science", "astronomy", "astrophysics", "IceCube", "neutri
license = {file = "LICENSES/BSD-2-Clause.txt"}
name = "simweights"
readme = "README.rst"
requires-python = "~=3.8"
requires-python = "~=3.10"

[project.optional-dependencies]
dev = ["pytest", "pre-commit", "reuse", "ruff", "pylint"]
dev = ["pytest", "pre-commit", "reuse", "ruff"]
docs = ["sphinx", "sphinx-rtd-theme", "pandas"]
examples = ['matplotlib']
test = [
Expand Down Expand Up @@ -69,12 +67,6 @@ source = ["simweights"]
[tool.doc8]
max-line-length = 128

[tool.pylint.format]
max-line-length = "128"

[tool.pylint.messages_control]
disable = "C0114,R0902,R0913,R0917,R0914,R0911"

[tool.pytest.ini_options]
addopts = ["-ra", "--strict-config", "--strict-markers", "--cov=simweights", "-W ignore"]
filterwarnings = ["error"]
Expand All @@ -94,27 +86,24 @@ ignore = [
"S101", # assert-used
"COM812", # conflicts with ruff formatter
"ISC001", # conflicts with ruff formatter
"PLR0913", # Too many arguments in function definition
"PLR0911", # Too many return statement
"PLW1641" # object does not implement `__hash__` method
]
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"contrib/*" = ["T201"]
"contrib/*" = ["T201"] # flake8-print
"examples/*" = [
"D", # pydocstyle
"F401", # unused-import
"T201", # flake8-print
"PLC0206", # Extracting value from dictionary without calling `.items()`
"N802" # Function name should be lowercase
]
"tests/*" = [
"D", # pydocstyle
"N", # pep8-naming
"ANN", # flake8-annotations
"PT", # flake8-pytest-style
"PGH001", # eval
"SLF001", # private-member-access
"PLR2004", # magic-value-comparison
"PLR0915", # too-many-statements
Expand All @@ -128,7 +117,7 @@ convention = "google"
[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py3{10,11,12,13}
envlist = py3{10,11,12,13,14}
isolated_build = True

[testenv]
Expand Down
5 changes: 3 additions & 2 deletions src/simweights/_corsika_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numbers
import warnings
from typing import TYPE_CHECKING, Any, Mapping
from typing import TYPE_CHECKING, Any

import numpy as np

Expand All @@ -17,6 +17,8 @@
from ._weighter import Weighter

if TYPE_CHECKING:
from collections.abc import Mapping

from numpy.typing import NDArray


Expand Down Expand Up @@ -94,7 +96,6 @@ def weight_map_corsika_surface(table: Any) -> CompositeSurface:


def CorsikaWeighter(file_obj: Any, nfiles: float | None = None) -> Weighter: # noqa: N802
# pylint: disable=invalid-name
"""Weighter for CORSIKA-in-ice simulation made with I3CORSIKAReader.

I3CORSIKAReader not use S-Frames and stores the surface information in an I3MapStringDouble so that
Expand Down
16 changes: 7 additions & 9 deletions src/simweights/_fluxes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# SPDX-FileCopyrightText: © 2022 the SimWeights contributors
#
# SPDX-License-Identifier: BSD-2-Clause
# pylint: disable=too-few-public-methods
# flake8: noqa: N801 N803
# ruff: noqa: N801 N803

"""A collection of cosmic ray flux parametrizations.

Expand All @@ -19,15 +18,17 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Callable, Mapping, Sequence
from typing import TYPE_CHECKING

from numpy import asarray, bool_, broadcast_arrays, exp, float64, genfromtxt, int32, piecewise, sqrt
from numpy import sum as nsum
from scipy.interpolate import PchipInterpolator # pylint: disable=import-error
from scipy.interpolate import PchipInterpolator

from ._pdgcode import PDGCode

if TYPE_CHECKING:
from collections.abc import Callable, Mapping, Sequence

from numpy.typing import ArrayLike, NDArray

PDGID_4COMP = (PDGCode.PPlus, PDGCode.He4Nucleus, PDGCode.O16Nucleus, PDGCode.Fe56Nucleus)
Expand Down Expand Up @@ -81,7 +82,6 @@ def _condition(
energy: NDArray[float64], # noqa: ARG002
pdgid: NDArray[int32],
) -> list[NDArray[bool_]]:
# pylint: disable=unused-argument
return [pdgid == p for p in self.pdgids]

def __call__(self: CosmicRayFlux, energy: ArrayLike, pdgid: ArrayLike) -> NDArray[float64]:
Expand Down Expand Up @@ -144,7 +144,6 @@ class Hoerandel5(CosmicRayFlux):
class Hoerandel_IT(CosmicRayFlux):
"""Modified 5-component Hoerandel spectrum with N and Al replaced by O."""

# pylint: disable=invalid-name
pdgids = PDGID_4COMP
_funcs = (
lambda E: 1.1776445965025136 * E**-2.71 * (1 + (E / (4.49e6 * 1)) ** 1.9) ** (-2.1 / 1.9),
Expand Down Expand Up @@ -240,7 +239,6 @@ class GaisserH4a_IT(CosmicRayFlux):
flux\ [#Aartsen]_.
"""

# pylint: disable=invalid-name
pdgids = PDGID_4COMP
_funcs = (
lambda E: (
Expand Down Expand Up @@ -324,7 +322,7 @@ class GlobalFitGST(CosmicRayFlux):
)


class GlobalFitGST_IT(CosmicRayFlux): # pylint: disable=invalid-name
class GlobalFitGST_IT(CosmicRayFlux):
r"""GlobalFitGST for four components [p, He, O, Fe].

The Oxygen group is the sum of Nitrogen and Aluminum groups of GlobalFitGST.
Expand Down Expand Up @@ -390,7 +388,7 @@ def __init__(self: GlobalSplineFit5Comp) -> None:
super().__init__()


class GlobalSplineFit_IT(GlobalSplineFitBase): # pylint: disable=invalid-name
class GlobalSplineFit_IT(GlobalSplineFitBase):
r"""Sum of the flux of the GSF model for the standard 4 components injected by IceCube.

[(H), (He), (Li, Be, B, C, N, O, F, Ne), (Na, Mg, Al, Si, P, S, Cl, Ar, K, Ca, Sc, Ti, V, Cr, Mn, Fe, Co, Ni)]
Expand Down
5 changes: 3 additions & 2 deletions src/simweights/_genie_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import TYPE_CHECKING, Any

import numpy as np

Expand All @@ -17,6 +17,8 @@
from ._weighter import Weighter

if TYPE_CHECKING: # pragma: no cover
from collections.abc import Iterable, Mapping

from np.typing import ArrayLike, NDArray

from simweights._pdgcode import PDGCode
Expand Down Expand Up @@ -129,7 +131,6 @@ def genie_reader_surface(table: Iterable[Mapping[str, float]]) -> CompositeSurfa


def GenieWeighter(file_obj: Any, nfiles: float | None = None) -> Weighter: # noqa: N802
# pylint: disable=invalid-name
"""Weighter for GENIE simulation.

Reads ``I3GenieInfo`` from S-Frames and ``I3GenieResult`` from Q-Frames for genie-reader files
Expand Down
6 changes: 3 additions & 3 deletions src/simweights/_icetop_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# SPDX-License-Identifier: BSD-2-Clause


from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any

import numpy as np

Expand Down Expand Up @@ -40,7 +41,7 @@ def sframe_icetop_surface(table: Any) -> CompositeSurface:

for i, nevents in enumerate(n_events):
assert power_law_index[i] <= 0
spectrum = PowerLaw( # pylint: disable=duplicate-code
spectrum = PowerLaw(
power_law_index[i],
min_energy[i],
max_energy[i],
Expand All @@ -58,7 +59,6 @@ def sframe_icetop_surface(table: Any) -> CompositeSurface:


def IceTopWeighter(file_obj: Any) -> Weighter: # noqa: N802
# pylint: disable=invalid-name
"""Weighter for IceTop CORSIKA simulation made with I3TopSimulator.cxx."""
surface = sframe_icetop_surface(get_table(file_obj, "I3TopInjectorInfo"))
weighter = Weighter([file_obj], surface)
Expand Down
4 changes: 2 additions & 2 deletions src/simweights/_nugen_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#
# SPDX-License-Identifier: BSD-2-Clause

from typing import Any, Mapping
from collections.abc import Mapping
from typing import Any

import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -90,7 +91,6 @@ def nugen_surface(table: Any) -> CompositeSurface:


def NuGenWeighter(file_obj: Any, nfiles: float) -> Weighter: # noqa: N802
# pylint: disable=invalid-name
"""Weighter for neutrino-generator (NuGen) simulation.

Does not use S-Frames and stores the surface information in an I3MapStringDouble so that the user
Expand Down
2 changes: 0 additions & 2 deletions src/simweights/_pdgcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class PDGCode(IntEnum):
only used for cosmic-ray flux models and is limited to particle types in these models.
"""

# pylint: disable=invalid-name

MuMinus = 13
MuPlus = -13
NuE = 12
Expand Down
2 changes: 0 additions & 2 deletions src/simweights/_powerlaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class PowerLaw:
b (float): Upper bound of the support of the distribution.
"""

# pylint: disable=invalid-name

def __init__(self: PowerLaw, g: float, a: float, b: float) -> None:
assert b > a
self.g = float(g)
Expand Down
5 changes: 2 additions & 3 deletions src/simweights/_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-2-Clause
from __future__ import annotations

from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING

import numpy as np

Expand Down Expand Up @@ -150,7 +150,6 @@ def __init__(self: CircleInjector, radius: float, cos_zen_min: float, cos_zen_ma

def projected_area(self: CircleInjector, cos_zen: float) -> float: # noqa: ARG002
"""Returns the cross sectional area of the injection area in cm^2."""
# pylint: disable=unused-argument
return self._cap

def pdf(self: CircleInjector, cos_zen: ArrayLike) -> NDArray[np.float64]:
Expand All @@ -174,4 +173,4 @@ def __eq__(self: CircleInjector, other: object) -> bool:
)


SpatialDist = Union[CylinderBase, CircleInjector]
SpatialDist = CylinderBase | CircleInjector
8 changes: 4 additions & 4 deletions src/simweights/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Union
from typing import TYPE_CHECKING, Any

import numpy as np
from numpy.random import Generator, RandomState # pylint: disable=no-name-in-module
from numpy.random import Generator, RandomState

from ._pdgcode import PDGCode

if TYPE_CHECKING: # pragma: no cover
from numpy.typing import ArrayLike, NDArray

GeneratorType = Union[Generator, RandomState]
SeedType = Union[GeneratorType, int, None]
GeneratorType = Generator | RandomState
SeedType = GeneratorType | int | None


class Column:
Expand Down
6 changes: 4 additions & 2 deletions src/simweights/_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

import inspect
import warnings
from typing import TYPE_CHECKING, Any, Callable, Iterable
from typing import TYPE_CHECKING, Any

import numpy as np
from scipy.integrate import quad # pylint: disable=import-error
from scipy.integrate import quad

from ._generation_surface import CompositeSurface
from ._utils import get_column, get_table

if TYPE_CHECKING:
from collections.abc import Callable, Iterable

from numpy.typing import ArrayLike, NDArray


Expand Down
Loading