Skip to content

Commit

Permalink
Update progress bar to mimic gdal output
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed Jun 9, 2024
1 parent 724e876 commit 30d842c
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions geefcc/misc/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Standard library imports
import os
import sys

# Third party imports
import numpy as np
Expand Down Expand Up @@ -91,25 +90,43 @@ def makeblock(rasterfile, blk_rows=128):
return (nblock, nblock_x, nblock_y, x, y, nx, ny)


# Progress_bar
def progress_bar(niter, i):
"""Draw progress_bar
See results of ``[(100 * i / niter) // 10 * 10 for i in
range(niter + 1)]`` to understand how it works.
:param niter: Total number of iterations.
:param i: Current number of iteration (starts at 1).
"""

step = 1 if niter <= 100 else niter // 100
if i == 1:
sys.stdout.write("0%")
sys.stdout.flush()
elif i % step == 0:
sys.stdout.write("\r{}%".format((100 * i) // niter))
sys.stdout.flush()
if i == niter:
sys.stdout.write("\r100%\n")
sys.stdout.flush()
pkg_name = "geefcc"

if niter >= 40:
perc_10 = 100 * i / niter // 10 * 10
perc_previous_10 = 100 * (i - 1) / niter // 10 * 10
perc_2_5 = 100 * i / niter // 2.5 * 2.5
perc_previous_2_5 = 100 * (i - 1) / niter // 2.5 * 2.5
if i == 1:
print(f"{pkg_name}: 0", end="", flush=True)
elif perc_10 != perc_previous_10:
if i == niter:
print("100 - done", end="\n", flush=True)
else:
print(f"{int(perc_10)}", end="", flush=True)
elif perc_2_5 != perc_previous_2_5:
print(".", end="", flush=True)
else:
perc_10 = 100 * i / niter // 10 * 10
perc_previous_10 = 100 * (i - 1) / niter // 10 * 10
if i == 0:
print(f"{pkg_name}: 0...", end="", flush=True)
elif perc_10 != perc_previous_10:
if i == niter:
print("100 - done", end="\n", flush=True)
else:
print(f"{int(perc_10)}...", end="", flush=True)


# End

0 comments on commit 30d842c

Please sign in to comment.