diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index cef6363..d8a204e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,6 +8,7 @@ on: branches: - main pull_request: + workflow_dispatch: jobs: Docs: runs-on: ubuntu-22.04 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 65161f7..8fb7385 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,9 @@ on: branches: - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: Tests: runs-on: ${{ matrix.os }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64b82c7..6faab0f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,15 +10,16 @@ repos: rev: v4.0.0-alpha.8 hooks: - id: prettier + files: \.ya?ml$ - repo: https://github.com/fsfe/reuse-tool - rev: v2.1.0 + rev: v3.0.1 hooks: - id: reuse - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: - id: codespell - - repo: https://github.com/asottile/blacken-docs + - repo: https://github.com/adamchainz/blacken-docs rev: "1.16.0" hooks: - id: blacken-docs @@ -38,7 +39,7 @@ repos: exclude: ^contrib/ additional_dependencies: [numpy, pandas] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.1.14 hooks: - id: ruff args: [--fix, --show-fixes] diff --git a/contrib/print_flux.py b/contrib/print_flux.py index cec6d46..71face5 100755 --- a/contrib/print_flux.py +++ b/contrib/print_flux.py @@ -9,6 +9,7 @@ from sys import argv import numpy as np + from simweights import _fluxes E = np.logspace(2, 10, 9) diff --git a/examples/additional_flux_params.py b/examples/additional_flux_params.py index 9387451..a069825 100755 --- a/examples/additional_flux_params.py +++ b/examples/additional_flux_params.py @@ -6,10 +6,10 @@ import pandas as pd import pylab as plt +from numpy.typing import ArrayLike # start-box1 import simweights -from numpy.typing import ArrayLike # load the hdf5 file and make the weigher hdffile = pd.HDFStore("Level2_IC86.2016_NuMu.021217.N100.hdf5", "r") diff --git a/examples/basic_genie.py b/examples/basic_genie.py index d57758f..63b6841 100755 --- a/examples/basic_genie.py +++ b/examples/basic_genie.py @@ -6,6 +6,7 @@ import nuflux import pandas as pd + import simweights simfile = pd.HDFStore("genie_reader_NuE_C_corr.hdf5") diff --git a/examples/combined_plot.py b/examples/combined_plot.py index 3f5cc1f..e9407f3 100755 --- a/examples/combined_plot.py +++ b/examples/combined_plot.py @@ -6,9 +6,10 @@ import numpy as np import pylab as plt -import simweights import tables +import simweights + # start-box1 # load the Medium Energy file ME_file = tables.File("Level2_IC86.2016_corsika.021746.hdf5", "r") diff --git a/examples/effective_area.py b/examples/effective_area.py index a9ad2cc..54cd608 100755 --- a/examples/effective_area.py +++ b/examples/effective_area.py @@ -6,9 +6,10 @@ import numpy as np import pylab as plt -import simweights import tables +import simweights + # start-example1 # load hdf5 file f = tables.open_file("Level2_IC86.2016_NuMu.021217.N100.hdf5", "r") diff --git a/examples/icetop_plot.py b/examples/icetop_plot.py index 174e720..5e3c4b4 100755 --- a/examples/icetop_plot.py +++ b/examples/icetop_plot.py @@ -8,9 +8,10 @@ import numpy as np import pylab as plt -import simweights import tables +import simweights + # —- Define which files you want to be part of the dataset —— # (This particular example is all low-energy protons) FILE_DIR = Path("/data/ana/CosmicRay/IceTop_level3/sim/IC86.2012/SIBYLL2.1/p/12360_v1s/h5files/") diff --git a/examples/livetime.py b/examples/livetime.py index 2acde19..1c53755 100755 --- a/examples/livetime.py +++ b/examples/livetime.py @@ -6,9 +6,10 @@ import numpy as np import pylab as plt -import simweights import tables +import simweights + # load hdf5 table f = tables.open_file("Level2_IC86.2016_corsika.021682.N100.hdf5", "r") wobj = simweights.CorsikaWeighter(f) diff --git a/examples/nugen_nuflux.py b/examples/nugen_nuflux.py index 69a055c..3b0ffb8 100755 --- a/examples/nugen_nuflux.py +++ b/examples/nugen_nuflux.py @@ -7,10 +7,10 @@ import nuflux import pandas as pd import pylab as plt +from numpy.typing import ArrayLike # start-box1 import simweights -from numpy.typing import ArrayLike # load the hdf5 file and make the weigher hdffile = pd.HDFStore("Level2_IC86.2016_NuMu.021217.hdf5", "r") diff --git a/examples/nugen_plot.py b/examples/nugen_plot.py index 027362e..98ad844 100755 --- a/examples/nugen_plot.py +++ b/examples/nugen_plot.py @@ -6,9 +6,10 @@ import pandas as pd import pylab as plt -import simweights from numpy.typing import ArrayLike +import simweights + # load the hdf5 file that we just created using pandas hdffile = pd.HDFStore("Level2_IC86.2016_NuMu.021217.hdf5", "r") diff --git a/examples/triggered_corsika_plot.py b/examples/triggered_corsika_plot.py index f832320..17c358c 100755 --- a/examples/triggered_corsika_plot.py +++ b/examples/triggered_corsika_plot.py @@ -6,6 +6,7 @@ import pandas as pd import pylab as plt + import simweights # load the hdf5 file that we just created using pandas diff --git a/examples/tutorial_corsika.py b/examples/tutorial_corsika.py index 56ba0f5..c067da6 100755 --- a/examples/tutorial_corsika.py +++ b/examples/tutorial_corsika.py @@ -8,9 +8,10 @@ import matplotlib.pyplot as plt import numpy as np -import simweights from icecube import dataio +import simweights + CORSIKA_DATASET_DIR = Path("/data/sim/IceCube/2016/filtered/level2/CORSIKA-in-ice/20789/") corsika_filelist = sorted( str(f) for f in CORSIKA_DATASET_DIR.glob("0000000-0000999/Level2_IC86.2016_corsika.020789.00000*.i3.zst") diff --git a/examples/tutorial_nugen.py b/examples/tutorial_nugen.py index 8183459..7a448ca 100755 --- a/examples/tutorial_nugen.py +++ b/examples/tutorial_nugen.py @@ -9,9 +9,10 @@ import matplotlib.pyplot as plt import nuflux import numpy as np -import simweights from icecube import dataclasses, dataio, simclasses +import simweights + def get_most_energetic_muon(mmclist: simclasses.I3MMCTrackList) -> float: "Loop through the MMC track list and return the muon with the most energy." diff --git a/examples/without_tableio.py b/examples/without_tableio.py index 52d47b2..4f23506 100755 --- a/examples/without_tableio.py +++ b/examples/without_tableio.py @@ -7,9 +7,10 @@ from pathlib import Path import pylab as plt -import simweights from icecube import dataio, simclasses +import simweights + FILE_DIR = Path("/data/sim/IceCube/2016/filtered/level2/CORSIKA-in-ice/21889/0000000-0000999") filelist = sorted(str(f) for f in FILE_DIR.glob("Level2_IC86.2016_corsika.021889.00000*.i3.zst")) diff --git a/pyproject.toml b/pyproject.toml index 0176bbb..def0616 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,8 +66,9 @@ ignore-words-list = 'livetime' [tool.mypy] plugins = "numpy.typing.mypy_plugin" -show_error_codes = true +# show_error_codes = true warn_unreachable = true +strict = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [tool.pylint.format] @@ -77,6 +78,12 @@ max-line-length = "128" disable = "C0114,R0902,R0913" [tool.ruff] +src = ["src"] +line-length = 128 +target-version = "py38" +namespace-packages = ["examples", "contrib", "docs"] + +[tool.ruff.lint] select = ["ALL"] fixable = ["I"] ignore = [ @@ -87,14 +94,11 @@ ignore = [ "ISC001", # confilcts with ruff formatter "PLR0913",# Too many arguments in function definition ] -line-length = 128 -target-version = "py38" -namespace-packages = ["examples", "contrib", "docs"] -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "contrib/*" = ["T201"] "tests/*" = [ "D", # pydocstyle diff --git a/src/simweights/_generation_surface.py b/src/simweights/_generation_surface.py index 6eb4e90..58dd694 100644 --- a/src/simweights/_generation_surface.py +++ b/src/simweights/_generation_surface.py @@ -5,7 +5,7 @@ from __future__ import annotations from copy import deepcopy -from typing import TYPE_CHECKING, NamedTuple, Sequence +from typing import TYPE_CHECKING, Any, NamedTuple, Sequence import numpy as np @@ -26,7 +26,7 @@ class SurfaceTuple(NamedTuple): pdgid: int | PDGCode nevents: float - dists: Sequence + dists: Sequence[Any] class GenerationSurface: diff --git a/src/simweights/_utils.py b/src/simweights/_utils.py index 320fac9..6759951 100644 --- a/src/simweights/_utils.py +++ b/src/simweights/_utils.py @@ -4,7 +4,6 @@ from __future__ import annotations -import numbers from typing import TYPE_CHECKING, Any, Union import numpy as np @@ -15,10 +14,8 @@ if TYPE_CHECKING: # pragma: no cover from numpy.typing import ArrayLike, NDArray - -IntNumber = Union[int, np.integer] GeneratorType = Union[Generator, RandomState] -SeedType = Union[GeneratorType, IntNumber, None] +SeedType = Union[GeneratorType, int, None] class Column: @@ -167,9 +164,9 @@ def check_random_state(seed: SeedType = None) -> GeneratorType: seed : {`numpy.random.Generator`, `numpy.random.RandomState`} Random number generator. """ - if seed is None or isinstance(seed, (numbers.Integral, np.integer)): + if seed is None or isinstance(seed, (int, np.integer)): return np.random.default_rng(seed) if isinstance(seed, (RandomState, Generator)): return seed - mesg = f"{seed!r} cannot be used to seed a numpy.random.Generator instance" + mesg = f"{seed!r} cannot be used to seed a numpy.random.Generator instance" # type: ignore[unreachable] raise ValueError(mesg) diff --git a/tests/test_corsika_datasets.py b/tests/test_corsika_datasets.py index 820b813..f949de2 100755 --- a/tests/test_corsika_datasets.py +++ b/tests/test_corsika_datasets.py @@ -12,6 +12,7 @@ import pandas as pd import tables import uproot + from simweights import CorsikaWeighter, GaisserH4a from simweights._utils import constcol diff --git a/tests/test_corsika_weighter.py b/tests/test_corsika_weighter.py index eb57d46..39e92c2 100755 --- a/tests/test_corsika_weighter.py +++ b/tests/test_corsika_weighter.py @@ -7,8 +7,9 @@ import unittest import numpy as np -import simweights from scipy.interpolate import interp1d + +import simweights from simweights import CorsikaWeighter info_dtype = [ diff --git a/tests/test_fluxes.py b/tests/test_fluxes.py index de91aad..bd345b5 100755 --- a/tests/test_fluxes.py +++ b/tests/test_fluxes.py @@ -9,6 +9,7 @@ from pathlib import Path import numpy as np + from simweights import _fluxes E = np.logspace(2, 10, 9) diff --git a/tests/test_generation_surface.py b/tests/test_generation_surface.py index e531adc..cc70a7f 100755 --- a/tests/test_generation_surface.py +++ b/tests/test_generation_surface.py @@ -9,6 +9,7 @@ import numpy as np from numpy.testing import assert_allclose + from simweights import GenerationSurface, NaturalRateCylinder, PDGCode, PowerLaw, generation_surface from simweights._generation_surface import SurfaceTuple # noqa: F401 diff --git a/tests/test_genie_datasets.py b/tests/test_genie_datasets.py index 41ba68b..56f51b5 100755 --- a/tests/test_genie_datasets.py +++ b/tests/test_genie_datasets.py @@ -13,6 +13,7 @@ import pandas as pd import tables import uproot + from simweights import GenieWeighter from simweights._utils import get_column, get_table diff --git a/tests/test_genie_weighter.py b/tests/test_genie_weighter.py index 1c71c6b..3b0fb0b 100755 --- a/tests/test_genie_weighter.py +++ b/tests/test_genie_weighter.py @@ -7,6 +7,7 @@ import unittest import numpy as np + import simweights info_dtype = [ diff --git a/tests/test_icetop_datasets.py b/tests/test_icetop_datasets.py index 0b5b782..3248e5a 100755 --- a/tests/test_icetop_datasets.py +++ b/tests/test_icetop_datasets.py @@ -13,6 +13,7 @@ import pandas as pd import tables import uproot + from simweights import IceTopWeighter diff --git a/tests/test_icetop_weighter.py b/tests/test_icetop_weighter.py index 4b610bb..55f61c0 100755 --- a/tests/test_icetop_weighter.py +++ b/tests/test_icetop_weighter.py @@ -7,6 +7,7 @@ import unittest import numpy as np + import simweights info_dtype = [ diff --git a/tests/test_nugen_datasets.py b/tests/test_nugen_datasets.py index d5622fc..f65737b 100755 --- a/tests/test_nugen_datasets.py +++ b/tests/test_nugen_datasets.py @@ -13,6 +13,7 @@ import pandas as pd import tables import uproot + from simweights import NuGenWeighter diff --git a/tests/test_nugen_weighter.py b/tests/test_nugen_weighter.py index 3497d9d..6124e60 100755 --- a/tests/test_nugen_weighter.py +++ b/tests/test_nugen_weighter.py @@ -8,6 +8,7 @@ import numpy as np import pandas as pd + from simweights import CircleInjector, NaturalRateCylinder, NuGenWeighter, PowerLaw base_keys = [ diff --git a/tests/test_powerlaw.py b/tests/test_powerlaw.py index c298511..8f7e9a6 100755 --- a/tests/test_powerlaw.py +++ b/tests/test_powerlaw.py @@ -9,6 +9,7 @@ import numpy as np from scipy import stats from scipy.integrate import quad + from simweights import PowerLaw diff --git a/tests/test_spatial.py b/tests/test_spatial.py index cdf6736..22e04e5 100755 --- a/tests/test_spatial.py +++ b/tests/test_spatial.py @@ -7,6 +7,7 @@ import unittest import numpy as np + from simweights import ( CircleInjector, NaturalRateCylinder, diff --git a/tests/test_util.py b/tests/test_util.py index 1240e83..de7ff3e 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -11,6 +11,7 @@ import numpy as np import uproot from numpy.testing import assert_array_equal + from simweights import Hoerandel from simweights._utils import ( Column, diff --git a/tests/test_weighter.py b/tests/test_weighter.py index 27f9651..4433188 100755 --- a/tests/test_weighter.py +++ b/tests/test_weighter.py @@ -8,6 +8,7 @@ from copy import copy import numpy as np + from simweights import TIG1996, NaturalRateCylinder, PowerLaw, Weighter, generation_surface