From cb2d78774866add8f11fa7afffd4a201c2fd4210 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:05:10 +0000 Subject: [PATCH] style: pre-commit fixes --- docs/source/extensions/numbadoc.py | 1 + src/pygama/cli.py | 1 + src/pygama/evt/modules/legend.py | 1 + src/pygama/evt/modules/spm.py | 1 - src/pygama/flow/file_db.py | 1 + src/pygama/hit/build_hit.py | 1 + src/pygama/logging.py | 1 + src/pygama/pargen/AoE_cal.py | 51 +++++++++++++++++------------- src/pygama/pargen/data_cleaning.py | 1 + src/pygama/pargen/ecal_th.py | 20 +++++------- src/pygama/pargen/energy_cal.py | 1 + src/pygama/pargen/lq_cal.py | 1 - 12 files changed, 45 insertions(+), 36 deletions(-) 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/evt/modules/spm.py b/src/pygama/evt/modules/spm.py index 6e7140d17..843c7935e 100644 --- a/src/pygama/evt/modules/spm.py +++ b/src/pygama/evt/modules/spm.py @@ -13,7 +13,6 @@ additional parameters are free to the user and need to be defined in the JSON """ - import awkward as ak import numpy as np from lgdo import Array, VectorOfVectors 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 2a6d6a066..2fad9c981 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 json 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__(