From 0e90ae48cd7d662ea768d51b282436f0c86bd5d6 Mon Sep 17 00:00:00 2001 From: teutoburg Date: Fri, 18 Oct 2024 21:44:26 +0200 Subject: [PATCH] Use tqdm.auto and don't show single-item progress bars --- scopesim/effects/spectral_trace_list.py | 2 +- scopesim/optics/optical_train.py | 15 ++++++++++----- scopesim/server/download_utils.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scopesim/effects/spectral_trace_list.py b/scopesim/effects/spectral_trace_list.py index 7d8c10cb..a69559ca 100644 --- a/scopesim/effects/spectral_trace_list.py +++ b/scopesim/effects/spectral_trace_list.py @@ -7,7 +7,7 @@ from itertools import cycle -from tqdm import tqdm +from tqdm.auto import tqdm from astropy.io import fits from astropy.table import Table diff --git a/scopesim/optics/optical_train.py b/scopesim/optics/optical_train.py index 153a89c3..ddd871a7 100644 --- a/scopesim/optics/optical_train.py +++ b/scopesim/optics/optical_train.py @@ -9,7 +9,7 @@ from astropy import units as u from astropy.wcs import WCS -from tqdm import tqdm +from tqdm.auto import tqdm from synphot import SourceSpectrum, Empirical1D from synphot.units import PHOTLAM @@ -234,7 +234,8 @@ def observe(self, orig_source, update=True, **kwargs): else: fovs = self.fov_manager.fovs - for fov in tqdm(fovs, desc=" FOVs", position=0): + nobar = len(fovs) <= 1 + for fov in tqdm(fovs, desc=" FOVs", position=0, disable=nobar): # print("FOV", fov_i+1, "of", n_fovs, flush=True) # .. todo: possible bug with bg flux not using plate_scale # see fov_utils.combine_imagehdu_fields @@ -242,8 +243,10 @@ def observe(self, orig_source, update=True, **kwargs): hdu_type = "cube" if self.fov_manager.is_spectroscope else "image" fov.view(hdu_type) - for effect in tqdm(self.optics_manager.fov_effects, - desc=" FOV effects", position=1, leave=False): + foveffs = self.optics_manager.fov_effects + nobar = len(foveffs) <= 1 + for effect in tqdm(foveffs, disable=nobar, + desc=" FOV effects", position=1):#, leave=False): fov = effect.apply_to(fov) fov.flatten() @@ -253,7 +256,9 @@ def observe(self, orig_source, update=True, **kwargs): # END OF MULTIPROCESSING # [2D - Vibration, flat fielding, chopping+nodding] - for effect in tqdm(self.optics_manager.image_plane_effects, + impeffs = self.optics_manager.image_plane_effects + nobar = len(impeffs) <= 1 + for effect in tqdm(impeffs, disable=nobar, desc=" Image Plane effects"): for ii, image_plane in enumerate(self.image_planes): self.image_planes[ii] = effect.apply_to(image_plane) diff --git a/scopesim/server/download_utils.py b/scopesim/server/download_utils.py index e7cf00ed..ada7eced 100644 --- a/scopesim/server/download_utils.py +++ b/scopesim/server/download_utils.py @@ -12,7 +12,7 @@ import httpx import bs4 -from tqdm import tqdm +from tqdm.auto import tqdm # from tqdm.contrib.logging import logging_redirect_tqdm # put with logging_redirect_tqdm(loggers=all_loggers): around tqdm # Note: seems to work without that so far...