Use tqdm for progress bar
tqdm
is a very solid option for progress bars, also for multiprocessing. One nice thing is that it shows an expected time as well. Should work cross-platform, single core or multicore.
from tqdm.auto import tqdm
# run co-registration for whole grid
if self.CPUs is None or self.CPUs > 1:
if not self.q:
cpus = self.CPUs if self.CPUs is not None else multiprocessing.cpu_count()
print("Calculating tie point grid (%s points) using %s CPU cores..." % (len(GDF), cpus))
with multiprocessing.Pool(self.CPUs, initializer=mp_initializer, initargs=(self.ref, self.shift)) as pool:
if self.q or not self.progress:
results = pool.map(self._get_spatial_shifts, list_coreg_kwargs)
else:
results = list(tqdm(pool.imap_unordered(self._get_spatial_shifts, list_coreg_kwargs, chunksize=1), total=len(GDF)))
Or even
from tqdm.auto import tqdm
# run co-registration for whole grid
disable_progress = self.q or not self.progress
cpus = self.CPUs if self.CPUs is not None else multiprocessing.cpu_count()
if not self.q:
print(f"Calculating tie point grid ({len(GDF)} points) on {cpus} CPU")
if self.CPUs != 1:
with multiprocessing.Pool(cpus,
initializer=mp_initializer,
initargs=(self.ref, self.shift)) as pool:
results = list(tqdm(pool.imap_unordered(self._get_spatial_shifts, list_coreg_kwargs, chunksize=1),
total=len(GDF),
disable=disable_progress))
else:
# declare global variables needed for self._get_spatial_shifts()
global global_shared_imref, global_shared_im2shift
global_shared_imref = self.ref
global_shared_im2shift = self.shift
results = np.empty((len(geomPoints), 14), object)
for i, coreg_kwargs in tqdm(enumerate(list_coreg_kwargs), disable=disable_progress, total=len(GDF)):
results[i, :] = self._get_spatial_shifts(coreg_kwargs)