Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressbar: switch to tqdm, add description #913

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install_requires =
joblib
casa-formats-io
packaging
tqdm

[options.extras_require]
test =
Expand Down
5 changes: 2 additions & 3 deletions spectral_cube/analysis_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from astropy import units as u
from six.moves import zip, range
from astropy.wcs import WCS
from astropy.utils.console import ProgressBar
from astropy import log
import warnings

from .utils import BadVelocitiesWarning
from .utils import BadVelocitiesWarning, ProgressBar
from .cube_utils import _map_context
from .lower_dimensional_structures import VaryingResolutionOneDSpectrum, OneDSpectrum
from .spectral_cube import VaryingResolutionSpectralCube, SpectralCube
Expand Down Expand Up @@ -284,7 +283,7 @@ def stack_spectra(cube, velocity_surface, v0=None,
# Create chunks of spectra for read-out.
chunks = get_chunks(len(xy_posns[0]), chunk_size)
if progressbar:
iterat = ProgressBar(chunks)
iterat = ProgressBar(chunks, desc='Stack Spectra: ')
else:
iterat = chunks

Expand Down
16 changes: 8 additions & 8 deletions spectral_cube/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import astropy.wcs
from astropy import units as u
from astropy.io.fits import PrimaryHDU, BinTableHDU, Header, Card, HDUList
from astropy.utils.console import ProgressBar
from astropy import log
from astropy import wcs
from astropy import convolution
Expand All @@ -35,6 +34,7 @@
from . import cube_utils
from . import wcs_utils
from . import spectral_axis
from .utils import ProgressBar
from .masks import (LazyMask, LazyComparisonMask, BooleanArrayMask, MaskBase,
is_broadcastable_and_smaller)
from .ytcube import ytCube
Expand Down Expand Up @@ -515,7 +515,7 @@ def _reduce_slicewise(self, function, fill, check_endian,
result = next(planes)

if progressbar:
progressbar = ProgressBar(self.shape[iterax])
progressbar = ProgressBar(self.shape[iterax], desc='Slicewise: ')
pbu = progressbar.update
else:
pbu = lambda: True
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def apply_function(self, function, axis=None, weights=None, unit=None,
out = np.empty([nz, nx, ny]) * np.nan

if progressbar:
progressbar = ProgressBar(nx*ny)
progressbar = ProgressBar(nx*ny, desc='Apply: ')
pbu = progressbar.update
elif update_function is not None:
pbu = update_function
Expand Down Expand Up @@ -2993,7 +2993,7 @@ def apply_async(self, func, callback=None):
if update_function is not None:
pbu = update_function
elif verbose > 0:
progressbar = ProgressBar(self.shape[1]*self.shape[2])
progressbar = ProgressBar(self.shape[1]*self.shape[2], desc='Apply parallel: ')
pbu = progressbar.update
else:
pbu = object
Expand Down Expand Up @@ -3256,7 +3256,7 @@ def spectral_interpolate(self, spectral_grid,

yy,xx = np.indices(self.shape[1:])
if update_function is None:
pb = ProgressBar(xx.size)
pb = ProgressBar(xx.size, desc='Spectral Interpolate: ')
update_function = pb.update

for ix, iy in (zip(xx.flat, yy.flat)):
Expand Down Expand Up @@ -3480,7 +3480,7 @@ def makeslice_local(startpoint, axis=axis, nsteps=factor):
if progressbar:
progressbar = ProgressBar
else:
progressbar = lambda x: x
progressbar = lambda x, desc: x

# Create a view that will add a blank newaxis at the right spot
view_newaxis = [slice(None) for ii in range(self.ndim)]
Expand All @@ -3491,7 +3491,7 @@ def makeslice_local(startpoint, axis=axis, nsteps=factor):
dsarr = np.memmap(ntf, mode='w+', shape=newshape, dtype=float)
ntf2 = tempfile.NamedTemporaryFile()
mask = np.memmap(ntf2, mode='w+', shape=newshape, dtype=bool)
for ii in progressbar(range(newshape[axis])):
for ii in progressbar(range(newshape[axis]), desc='Downsample: '):
view_fulldata = makeslice_local(ii*factor)
view_newdata = makeslice_local(ii, nsteps=1)

Expand Down Expand Up @@ -4171,7 +4171,7 @@ def convolve_to(self, beam, allow_smaller=False,
beam_ratio_factors = [1.] * len(convolution_kernels)

if update_function is None:
pb = ProgressBar(self.shape[0])
pb = ProgressBar(self.shape[0], desc='Convolve: ')
update_function = pb.update

newdata = np.empty(self.shape)
Expand Down
6 changes: 6 additions & 0 deletions spectral_cube/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

bigdataurl = "https://spectral-cube.readthedocs.io/en/latest/big_data.html"

from tqdm.auto import tqdm

def ProgressBar(niter, **kwargs):
return tqdm(total=niter, **kwargs)


def cached(func):
"""
Decorator to cache function calls
Expand Down
6 changes: 3 additions & 3 deletions spectral_cube/visualization-tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import numpy as np
from astropy.utils.console import ProgressBar
from .utils import ProgressBar

def check_ffmpeg(ffmpeg_cmd):
returncode = os.system(f'{ffmpeg_cmd} > /dev/null 2&> /dev/null')
Expand Down Expand Up @@ -46,7 +46,7 @@ def make_rgb_movie(cube, prefix, v1, v2, vmin, vmax, ffmpeg_cmd='ffmpeg'):
p1 = cube.closest_spectral_channel(v1)
p2 = cube.closest_spectral_channel(v2)

for jj, ii in enumerate(ProgressBar(range(p1, p2-1))):
for jj, ii in enumerate(ProgressBar(range(p1, p2-1), desc='RGB: ')):
rgb = np.array([cube[ii+2], cube[ii+1], cube[ii]]).T.swapaxes(0, 1)

# in case you manually set min/max
Expand Down Expand Up @@ -114,7 +114,7 @@ def make_multispecies_rgb(cube_r, cube_g, cube_b, prefix, v1, v2, vmin, vmax,
p1 = cube_r.closest_spectral_channel(v1)
p2 = cube_r.closest_spectral_channel(v2)

for jj, ii in enumerate(ProgressBar(range(p1, p2+1))):
for jj, ii in enumerate(ProgressBar(range(p1, p2+1), desc='RGB multi: ')):
rgb = np.array([cube_r[ii].value,
cube_g[ii].value,
cube_b[ii].value
Expand Down
2 changes: 1 addition & 1 deletion spectral_cube/ytcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import numpy as np
import time
from astropy.utils.console import ProgressBar
from .utils import ProgressBar
from astropy import log
import warnings

Expand Down
Loading