-
Notifications
You must be signed in to change notification settings - Fork 116
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
Progress Bar on Zonal_Stats #206
Comments
@mataslauzadis I definitely see the need for better feedback while iterating through input features. I'm not sure the best way to implement it though - consider that However, there are some solutions you can use in your own Python code by using a tqdm context manager as in https://stackoverflow.com/a/51083782/519385 . Since the I would consider adding something like that to the |
Having a built-in progress bar would be great! Maybe there could be a For now, here's a workaround I used in case anyone wants to create their own progress bar. import rasterstats
from tqdm.auto import tqdm
import geopandas as gpd
# Load geometry
geom = gpd.read_file("geom.gpkg").geometry
# Create a zonal stats generator
gen = rasterstats.gen_zonal_stats(vectors=geom, raster="img.tif")
# Display a progress bar while converting the generator into a list of zonal stats
stats = [n for n in tqdm(gen, total=geom.shape[0])] Thanks for building and maintaining |
Hi all, |
We'd need to stay backwards compatible - I have many code bases that call zonal stats non-interactively and if I upgraded and forgot to change my call sites, the resulting log spam would be unacceptably costly. I have a responsibility to avoid situations like that, for myself and all users. So I'd prefer to keep the existing default behavior (no progress bar) and use a Note that only
In terms of libraries, if we take a dependency on @jeronimoluza did you have a different approach in mind? My main concern is backwards compatibility - as long as we keep existing code working exactly the same, I'm ok with adding a progress bar - if it's opt-in. |
Sounds good, @perrygeo! Putting the I could use @aazuspan's example to modify the def zonal_stats(*args, **kwargs):
...
progress = kwargs.get('progress')
if progress:
return [list_comprehension_with_tqdm]
else:
return [list_comprehension_no_tqdm] Regarding the optional dependency, I can add How does it sound? |
Is there any plan or interest to add a progress bar to zonal_stats? When working with large data-sets, the function can take a long time to complete, sometimes hanging part of the way through.
A progress bar would be a good way to see that the function is still running and has not crashed.
tqdm could be a good candidate for this, it would just wrap around the feature iteration in this line of code.
The text was updated successfully, but these errors were encountered: