diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d34bc9618..9abb00b60 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,107 +5,106 @@ ci: exclude: ^(attic|tutorials|src/pygama/math|src/pygama/flow/datagroup.py) repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.5.0" - hooks: - - id: check-added-large-files - - id: check-case-conflict - - id: check-executables-have-shebangs - - id: check-merge-conflict - - id: check-symlinks - - id: check-yaml - - id: check-json - - id: check-toml - - id: check-docstring-first - exclude: ^src/pygama/raw/(fc/fc_event_decoder.py|compass/compass_event_decoder.py)$ - - id: debug-statements - - id: end-of-file-fixer - - id: forbid-new-submodules - - id: mixed-line-ending - - id: requirements-txt-fixer - - id: trailing-whitespace +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.5.0" + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: check-json + - id: check-toml + - id: check-docstring-first + exclude: ^src/pygama/raw/(fc/fc_event_decoder.py|compass/compass_event_decoder.py)$ + - id: debug-statements + - id: end-of-file-fixer + - id: forbid-new-submodules + - id: mixed-line-ending + - id: requirements-txt-fixer + - id: trailing-whitespace - - repo: https://github.com/asottile/setup-cfg-fmt - rev: "v2.5.0" - hooks: - - id: setup-cfg-fmt +- repo: https://github.com/asottile/setup-cfg-fmt + rev: "v2.5.0" + hooks: + - id: setup-cfg-fmt - - repo: https://github.com/PyCQA/isort - rev: "5.13.2" - hooks: - - id: isort +- repo: https://github.com/PyCQA/isort + rev: "5.13.2" + hooks: + - id: isort - - repo: https://github.com/asottile/pyupgrade - rev: "v3.15.0" - hooks: - - id: pyupgrade - args: ["--py38-plus"] +- repo: https://github.com/asottile/pyupgrade + rev: "v3.15.2" + hooks: + - id: pyupgrade + args: ["--py38-plus"] - - repo: https://github.com/psf/black - rev: "23.12.1" - hooks: - - id: black-jupyter +- repo: https://github.com/psf/black + rev: "24.3.0" + hooks: + - id: black-jupyter - - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.8.0" - hooks: - - id: mypy - files: src - stages: [manual] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: "v1.9.0" + hooks: + - id: mypy + files: src + stages: [manual] - - repo: https://github.com/hadialqattan/pycln - rev: "v2.4.0" - hooks: - - id: pycln - exclude: ^src/pygama/pargen - args: [--all] +- repo: https://github.com/hadialqattan/pycln + rev: "v2.4.0" + hooks: + - id: pycln + exclude: ^src/pygama/pargen + args: [--all] - - repo: https://github.com/PyCQA/flake8 - rev: "6.1.0" - hooks: - - id: flake8 - exclude: ^src/pygama/pargen - additional_dependencies: - [flake8-bugbear>=23.1.17, flake8-print, pep8-naming] - args: ["--extend-ignore", "E203,E501"] +- repo: https://github.com/PyCQA/flake8 + rev: "7.0.0" + hooks: + - id: flake8 + exclude: ^src/pygama/pargen + additional_dependencies: [ + flake8-bugbear>=23.1.17, + flake8-print, + pep8-naming + ] + args: ["--extend-ignore", "E203,E501"] - - repo: https://github.com/kynan/nbstripout - rev: "0.6.1" - hooks: - - id: nbstripout - args: - [ - "--drop-empty-cells", - "--extra-keys", - "metadata.kernelspec metadata.language_info", - ] +- repo: https://github.com/kynan/nbstripout + rev: "0.7.1" + hooks: + - id: nbstripout + args: ["--drop-empty-cells", + "--extra-keys", "metadata.kernelspec metadata.language_info"] - - repo: https://github.com/mgedmin/check-manifest - rev: "0.49" - hooks: - - id: check-manifest - stages: [manual] +- repo: https://github.com/mgedmin/check-manifest + rev: "0.49" + hooks: + - id: check-manifest + stages: [manual] - - repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" - hooks: - - id: codespell +- repo: https://github.com/codespell-project/codespell + rev: "v2.2.6" + hooks: + - id: codespell - - repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.9.0.6" - hooks: - - id: shellcheck +- repo: https://github.com/shellcheck-py/shellcheck-py + rev: "v0.10.0.1" + hooks: + - id: shellcheck - - repo: https://github.com/pre-commit/pygrep-hooks - rev: "v1.10.0" - hooks: - - id: python-no-log-warn - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal +- repo: https://github.com/pre-commit/pygrep-hooks + rev: "v1.10.0" + hooks: + - id: python-no-log-warn + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal - - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v4.0.0-alpha.8" - hooks: - - id: prettier - types_or: [json, yaml] +- repo: https://github.com/pre-commit/mirrors-prettier + rev: "v4.0.0-alpha.8" + hooks: + - id: prettier + types_or: [json] diff --git a/docs/source/extensions/numbadoc.py b/docs/source/extensions/numbadoc.py index 5b4202a10..f2f1a5dad 100644 --- a/docs/source/extensions/numbadoc.py +++ b/docs/source/extensions/numbadoc.py @@ -5,6 +5,7 @@ Adapted from https://github.com/numba/numba/issues/5755#issuecomment-646587651 """ + from copy import copy from typing import Iterator, List diff --git a/src/pygama/cli.py b/src/pygama/cli.py index fb05ef658..20ad5c76d 100644 --- a/src/pygama/cli.py +++ b/src/pygama/cli.py @@ -1,6 +1,7 @@ """ pygama's command line interface utilities. """ + import argparse import logging import os diff --git a/src/pygama/evt/modules/legend.py b/src/pygama/evt/modules/legend.py index 2ee2d7e8e..5ad620bda 100644 --- a/src/pygama/evt/modules/legend.py +++ b/src/pygama/evt/modules/legend.py @@ -1,6 +1,7 @@ """ Module provides LEGEND internal functions """ + from importlib import import_module from lgdo.lh5 import utils diff --git a/src/pygama/flow/file_db.py b/src/pygama/flow/file_db.py index fdca65b2d..954c07f50 100644 --- a/src/pygama/flow/file_db.py +++ b/src/pygama/flow/file_db.py @@ -1,4 +1,5 @@ """Utilities for LH5 file inventory.""" + from __future__ import annotations import json diff --git a/src/pygama/hit/build_hit.py b/src/pygama/hit/build_hit.py index 36bce1834..7a8c6a241 100644 --- a/src/pygama/hit/build_hit.py +++ b/src/pygama/hit/build_hit.py @@ -1,6 +1,7 @@ """ This module implements routines to evaluate expressions to columnar data. """ + from __future__ import annotations import logging diff --git a/src/pygama/logging.py b/src/pygama/logging.py index 8271dc08e..7c494bafe 100644 --- a/src/pygama/logging.py +++ b/src/pygama/logging.py @@ -1,4 +1,5 @@ """This module implements some helpers for setting up logging.""" + import logging import colorlog diff --git a/src/pygama/pargen/AoE_cal.py b/src/pygama/pargen/AoE_cal.py index 227aec4e2..a145a0c40 100644 --- a/src/pygama/pargen/AoE_cal.py +++ b/src/pygama/pargen/AoE_cal.py @@ -37,7 +37,6 @@ class PDF: - """ Base class for A/E pdfs. """ @@ -1518,9 +1517,9 @@ def drift_time_correction( np.nanpercentile(dep_events[self.dt_param], 99), ] - self.dt_res_dict[ - "final_selection" - ] = f"{aoe_param}>{aoe_range[0]}&{aoe_param}<{aoe_range[1]}&{self.dt_param}>{dt_range[0]}&{self.dt_param}<{dt_range[1]}&{self.dt_param}=={self.dt_param}" + self.dt_res_dict["final_selection"] = ( + f"{aoe_param}>{aoe_range[0]}&{aoe_param}<{aoe_range[1]}&{self.dt_param}>{dt_range[0]}&{self.dt_param}<{dt_range[1]}&{self.dt_param}=={self.dt_param}" + ) final_df = dep_events.query(self.dt_res_dict["final_selection"]) @@ -1550,12 +1549,12 @@ def drift_time_correction( "errs": m.errors, "object": m, } - aoe_grp1 = self.dt_res_dict[ - "aoe_grp1" - ] = f'{self.dt_param}>{m.values["mu1"] - 2 * m.values["sigma1"]} & {self.dt_param}<{m.values["mu1"] + 2 * m.values["sigma1"]}' - aoe_grp2 = self.dt_res_dict[ - "aoe_grp2" - ] = f'{self.dt_param}>{m.values["mu2"] - 2 * m.values["sigma2"]} & {self.dt_param}<{m.values["mu2"] + 2 * m.values["sigma2"]}' + aoe_grp1 = self.dt_res_dict["aoe_grp1"] = ( + f'{self.dt_param}>{m.values["mu1"] - 2 * m.values["sigma1"]} & {self.dt_param}<{m.values["mu1"] + 2 * m.values["sigma1"]}' + ) + aoe_grp2 = self.dt_res_dict["aoe_grp2"] = ( + f'{self.dt_param}>{m.values["mu2"] - 2 * m.values["sigma2"]} & {self.dt_param}<{m.values["mu2"] + 2 * m.values["sigma2"]}' + ) aoe_pars, aoe_errs, _ = unbinned_aoe_fit( final_df.query(aoe_grp1)[aoe_param], pdf=self.pdf, display=display @@ -2021,9 +2020,11 @@ def calibrate(self, df, initial_aoe_param): self.low_cut_val, peak, fwhm, - dt_mask=peak_df[self.dt_cut_param].to_numpy() - if self.dt_cut_param is not None - else None, + dt_mask=( + peak_df[self.dt_cut_param].to_numpy() + if self.dt_cut_param is not None + else None + ), ) self.low_side_sf = pd.concat( [ @@ -2043,9 +2044,11 @@ def calibrate(self, df, initial_aoe_param): self.low_cut_val, peak, fwhm, - dt_mask=peak_df[self.dt_cut_param].to_numpy() - if self.dt_cut_param is not None - else None, + dt_mask=( + peak_df[self.dt_cut_param].to_numpy() + if self.dt_cut_param is not None + else None + ), ) self.low_side_sf = pd.concat( [ @@ -2083,9 +2086,11 @@ def calibrate(self, df, initial_aoe_param): peak_df[aoe_param].to_numpy(), self.low_cut_val, self.high_cut_val, - dt_mask=peak_df[self.dt_cut_param].to_numpy() - if self.dt_cut_param is not None - else None, + dt_mask=( + peak_df[self.dt_cut_param].to_numpy() + if self.dt_cut_param is not None + else None + ), ) sf = sf_dict["sf"] sf_err = sf_dict["sf_err"] @@ -2107,9 +2112,11 @@ def calibrate(self, df, initial_aoe_param): peak, fwhm, high_cut=self.high_cut_val, - dt_mask=peak_df[self.dt_cut_param].to_numpy() - if self.dt_cut_param is not None - else None, + dt_mask=( + peak_df[self.dt_cut_param].to_numpy() + if self.dt_cut_param is not None + else None + ), ) self.two_side_sf = pd.concat( [ diff --git a/src/pygama/pargen/data_cleaning.py b/src/pygama/pargen/data_cleaning.py index 4a1ceb93e..f1911011c 100644 --- a/src/pygama/pargen/data_cleaning.py +++ b/src/pygama/pargen/data_cleaning.py @@ -5,6 +5,7 @@ - find_pulser_properties (find pulser by looking for which peak has a constant time between events) - tag_pulsers """ + import matplotlib.gridspec as gs import matplotlib.pyplot as plt import numpy as np diff --git a/src/pygama/pargen/ecal_th.py b/src/pygama/pargen/ecal_th.py index e3526c63a..ef9418fca 100644 --- a/src/pygama/pargen/ecal_th.py +++ b/src/pygama/pargen/ecal_th.py @@ -1183,13 +1183,11 @@ def bin_pulser_stability(ecal_class, data, pulser_field="is_pulser", time_slice= "spread": np.full_like(times_average, np.nan), } - nanmedian = ( - lambda x: np.nanpercentile(x, 50) if len(x[~np.isnan(x)]) >= 10 else np.nan + nanmedian = lambda x: ( + np.nanpercentile(x, 50) if len(x[~np.isnan(x)]) >= 10 else np.nan ) - error = ( - lambda x: np.nanvar(x) / np.sqrt(len(x)) - if len(x[~np.isnan(x)]) >= 10 - else np.nan + error = lambda x: ( + np.nanvar(x) / np.sqrt(len(x)) if len(x[~np.isnan(x)]) >= 10 else np.nan ) par_average, _, _ = binned_statistic( @@ -1225,13 +1223,11 @@ def bin_stability(ecal_class, data, time_slice=180, energy_range=[2585, 2660]): "spread": np.full_like(times_average, np.nan), } - nanmedian = ( - lambda x: np.nanpercentile(x, 50) if len(x[~np.isnan(x)]) >= 10 else np.nan + nanmedian = lambda x: ( + np.nanpercentile(x, 50) if len(x[~np.isnan(x)]) >= 10 else np.nan ) - error = ( - lambda x: np.nanvar(x) / np.sqrt(len(x)) - if len(x[~np.isnan(x)]) >= 10 - else np.nan + error = lambda x: ( + np.nanvar(x) / np.sqrt(len(x)) if len(x[~np.isnan(x)]) >= 10 else np.nan ) par_average, _, _ = binned_statistic( diff --git a/src/pygama/pargen/energy_cal.py b/src/pygama/pargen/energy_cal.py index a9de8e6d3..d592f0eff 100644 --- a/src/pygama/pargen/energy_cal.py +++ b/src/pygama/pargen/energy_cal.py @@ -5,6 +5,7 @@ - hpge_fit_E_peaks (fits the energy peals) - hpge_E_calibration (main routine -- finds and fits peaks specified) """ + import logging import sys diff --git a/src/pygama/pargen/lq_cal.py b/src/pygama/pargen/lq_cal.py index aa3c15806..35f192e99 100644 --- a/src/pygama/pargen/lq_cal.py +++ b/src/pygama/pargen/lq_cal.py @@ -221,7 +221,6 @@ def fit_time_means(tstamps, means, reses): class cal_lq: - """A class for calibrating the LQ parameter and determining the LQ cut value""" def __init__(