Skip to content

Commit

Permalink
Merge branch 'main' into build-evt-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gipert committed Apr 18, 2024
2 parents 68fb91e + 408fd78 commit becbfc3
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 126 deletions.
181 changes: 90 additions & 91 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions docs/source/extensions/numbadoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Adapted from https://github.com/numba/numba/issues/5755#issuecomment-646587651
"""

from copy import copy
from typing import Iterator, List

Expand Down
1 change: 1 addition & 0 deletions src/pygama/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
pygama's command line interface utilities.
"""

import argparse
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions src/pygama/evt/modules/legend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module provides LEGEND internal functions
"""

from importlib import import_module

from lgdo.lh5 import utils
Expand Down
1 change: 1 addition & 0 deletions src/pygama/flow/file_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for LH5 file inventory."""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions src/pygama/hit/build_hit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module implements routines to evaluate expressions to columnar data.
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/pygama/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module implements some helpers for setting up logging."""

import logging

import colorlog
Expand Down
51 changes: 29 additions & 22 deletions src/pygama/pargen/AoE_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@


class PDF:

"""
Base class for A/E pdfs.
"""
Expand Down Expand Up @@ -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"])

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
[
Expand All @@ -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(
[
Expand Down Expand Up @@ -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"]
Expand All @@ -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(
[
Expand Down
1 change: 1 addition & 0 deletions src/pygama/pargen/data_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions src/pygama/pargen/ecal_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/pygama/pargen/energy_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit becbfc3

Please sign in to comment.