From 98472c0eb853b3f19d0f204f6a9d946a1a2bac14 Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Wed, 31 Jan 2024 23:16:29 +0100 Subject: [PATCH] replace progress with tqdm --- menu_tools/caching/cache_objects.py | 8 ++---- menu_tools/object_performance/plotter.py | 7 ++---- menu_tools/utils/objects.py | 2 -- poetry.lock | 32 ++++++++++++++++-------- pyproject.toml | 2 +- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/menu_tools/caching/cache_objects.py b/menu_tools/caching/cache_objects.py index fdddf135..ee23a7d3 100755 --- a/menu_tools/caching/cache_objects.py +++ b/menu_tools/caching/cache_objects.py @@ -3,7 +3,7 @@ import os import awkward as ak -from progress.bar import IncrementalBar +from tqdm import tqdm import uproot import vector import yaml @@ -257,13 +257,11 @@ def _ak_array_in_chunk(self, arr, chunk_array, branches): @utils.timer("Loading objects files") def _concat_array_from_ntuples(self): fnames = glob.glob(self._ntuple_path)[:] - bar = IncrementalBar("Progress", max=len(fnames)) branches = [self._object + x for x in self._branches] all_arrays = {x.removeprefix("part"): [] for x in branches} - for fname in fnames: - bar.next() + for fname in tqdm(fnames): new_array = {x.removeprefix("part"): [] for x in branches} # Read files in chunks to avoid issues with large size files @@ -282,8 +280,6 @@ def _concat_array_from_ntuples(self): # Concatenate array from "fname file" to all_arrays all_arrays = self._ak_array_in_chunk(all_arrays, new_array, branches) - bar.finish() - if self._object.startswith("part"): all_arrays = {**all_arrays, **self._ref_part_iso} if len(all_arrays) > 1: diff --git a/menu_tools/object_performance/plotter.py b/menu_tools/object_performance/plotter.py index a7c88e99..169e2dba 100755 --- a/menu_tools/object_performance/plotter.py +++ b/menu_tools/object_performance/plotter.py @@ -7,7 +7,7 @@ import matplotlib.pyplot as plt import mplhep as hep import numpy as np -from progress.bar import IncrementalBar +from tqdm import tqdm from menu_tools.object_performance.turnon_collection import TurnOnCollection from menu_tools.object_performance.config import PerformancePlotConfig @@ -475,9 +475,7 @@ def run(self): for test_obj in plot_config.test_object_instances: scalings[str(test_obj)] = {} thds = self._get_scaling_thresholds(cfg_plot, test_obj) - bar = IncrementalBar("Progress", max=len(thds)) - for threshold in thds: - bar.next() + for threshold in tqdm(thds): turnon_collection = TurnOnCollection(cfg_plot, threshold) turnon_collection.create_hists() scaling_pct = turnon_collection.cfg_plot.scaling_pct @@ -495,7 +493,6 @@ def run(self): scaling_function_params[str(test_obj)] = params # Write scalings for test_obj to file for usage in rate part self._write_scalings_to_file(test_obj, params) - bar.finish() plotter = ScalingPlotter( plot_name, diff --git a/menu_tools/utils/objects.py b/menu_tools/utils/objects.py index cdcf55bf..16d02ad6 100644 --- a/menu_tools/utils/objects.py +++ b/menu_tools/utils/objects.py @@ -153,8 +153,6 @@ def cuts(self) -> Optional[dict[str, list[str]]]: _cuts["inclusive"].append(global_eta_cut) except KeyError: _cuts["inclusive"] = [global_eta_cut] - if not _cuts: - print(f"No cuts will be applied for {self}!") return _cuts diff --git a/poetry.lock b/poetry.lock index a405b5a2..41c933fc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -879,16 +879,6 @@ files = [ dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] -[[package]] -name = "progress" -version = "1.6" -description = "Easy to use progress bars" -optional = false -python-versions = "*" -files = [ - {file = "progress-1.6.tar.gz", hash = "sha256:c9c86e98b5c03fa1fe11e3b67c1feda4788b8d0fe7336c2ff7d5644ccfba34cd"}, -] - [[package]] name = "pyarrow" version = "14.0.2" @@ -1126,6 +1116,26 @@ files = [ {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +[[package]] +name = "tqdm" +version = "4.66.1" +description = "Fast, Extensible Progress Meter" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tqdm-4.66.1-py3-none-any.whl", hash = "sha256:d302b3c5b53d47bce91fea46679d9c3c6508cf6332229aa1e7d8653723793386"}, + {file = "tqdm-4.66.1.tar.gz", hash = "sha256:d88e651f9db8d8551a62556d3cff9e3034274ca5d66e93197cf2490e2dcb69c7"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[package.extras] +dev = ["pytest (>=6)", "pytest-cov", "pytest-timeout", "pytest-xdist"] +notebook = ["ipywidgets (>=6)"] +slack = ["slack-sdk"] +telegram = ["requests"] + [[package]] name = "typing-extensions" version = "4.9.0" @@ -1226,4 +1236,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "~3.11.0" -content-hash = "5ea2af5e1e8b732add60fa9a7df5db6bfc904aed929688a73de25b68fe7bf78f" +content-hash = "f72223b97aac082185750f37fdad2c15f69643014250fb8e9bb04b268fcdd11a" diff --git a/pyproject.toml b/pyproject.toml index 7b86fcbe..8d56b34f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ matplotlib = "3.8.2" mplhep = "0.3.31" numpy = "^1.23.0" pandas = "2.1.4" -progress = "1.6" +tqdm = "4.66.1" pyarrow = "14.0.2" scipy = "1.10.1" uproot = "5.0.4"