r-barnes / richdem

High-performance Terrain and Hydrology Analysis
GNU General Public License v3.0
259 stars 66 forks source link

Allow disabling verbosity #15

Open joshclimacell opened 6 years ago

joshclimacell commented 6 years ago

Hello,

The progress bar that gets emitted seems super useful for interactive analysis, but it is quite obtrusive when using richdem in non-interactive code, where the output gets jumbled all together. It'd be great if it could be disabled somehow, e.g. passing verbose=False.

joshburkart commented 6 years ago

Example output:

\n\nA
 Slope calculation (radians)\x1b[39m\nC Horn, B.K.P., 1981. Hill shading and the reflectance map. Proceedings of the IEEE 69, 14\u201347. doi:10.1109/PROC.1981.11918\x1b[39m\n\n\
r\x1b[2K\r\x1b[2K[==                                                ] (4% - 0.0s - 1 threads)\r\x1b[2K[====                                              ] (9% - 0.0s - 1 threads)
\r\x1b[2K[=======                                           ] (14% - 0.0s - 1 threads)\r\x1b[2K[=========                                         ] (19% - 0.0s - 1 threads)\r\x1b
[2K[===========                                       ] (23% - 0.0s - 1 threads)\r\x1b[2K[==============                                    ] (28% - 0.0s - 1 threads)\r\x1b[2K[==
==============                                  ] (33% - 0.0s - 1 threads)\r\x1b[2K[===================                               ] (38% - 0.0s - 1 threads)\r\x1b[2K[========
=============                             ] (42% - 0.0s - 1 threads)\r\x1b[2K[=======================                           ] (47% - 0.0s - 1 threads)\r\x1b[2K[==============
============                        ] (52% - 0.0s - 1 threads)\r\x1b[2K[============================                      ] (57% - 0.0s - 1 threads)\r\x1b[2K[====================
==========                    ] (61% - 0.0s - 1 threads)\r\x1b[2K[=================================                 ] (66% - 0.0s - 1 threads)\r\x1b[2K[==========================
=========               ] (71% - 0.0s - 1 threads)\r\x1b[2K[======================================            ] (76% - 0.0s - 1 threads)\r\x1b[2K[================================
========          ] (80% - 0.0s - 1 threads)\r\x1b[2K[==========================================        ] (85% - 0.0s - 1 threads)\r\x1b[2K[======================================
=======     ] (90% - 0.0s - 1 threads)\r\x1b[2K[===============================================   ] (95% - 0.0s - 1 threads)\r\x1b[2Kt Wall-time = 0.000431681\x1b[39m\n\nA Curvat
ure attribute calculation\x1b[39m\nC Zevenbergen, L.W., Thorne, C.R., 1987. Quantitative analysis of land surface topography. Earth surface processes and landforms 12, 47\u201356
.\x1b[39m\n\n\r\x1b[2K\r\x1b[2K[==                                                ] (4% - 0.0s - 1 threads)\r\x1b[2K[====                                              ] (9% - 0.0
s - 1 threads)\r\x1b[2K[=======                                           ] (14% - 0.0s - 1 threads)\r\x1b[2K[=========                                         ] (19% - 0.0s - 1
threads)\r\x1b[2K[===========                                       ] (23% - 0.0s - 1 threads)\r\x1b[2K[==============                                    ] (28% - 0.0s - 1 thread
s)\r\x1b[2K[================                                  ] (33% - 0.0s - 1 threads)\r\x1b[2K[===================                               ] (38% - 0.0s - 1 threads)\r\x
1b[2K[=====================                             ] (42% - 0.0s - 1 threads)\r\x1b[2K[=======================                           ] (47% - 0.0s - 1 threads)\r\x1b[2K[
==========================                        ] (52% - 0.0s - 1 threads)\r\x1b[2K[============================                      ] (57% - 0.0s - 1 threads)\r\x1b[2K[======
========================                    ] (61% - 0.0s - 1 threads)\r\x1b[2K[=================================                 ] (66% - 0.0s - 1 threads)\r\x1b[2K[============
=======================               ] (71% - 0.0s - 1 threads)\r\x1b[2K[======================================            ] (76% - 0.0s - 1 threads)\r\x1b[2K[==================
======================          ] (80% - 0.0s - 1 threads)\r\x1b[2K[==========================================        ] (85% - 0.0s - 1 threads)\r\x1b[2K[========================
=====================     ] (90% - 0.0s - 1 threads)\r\x1b[2K[===============================================   ] (95% - 0.0s - 1 threads)\r\x1b[2Kt Wall-time = 0.000370996\x1b[3
9m\n\nA Aspect attribute calculation\x1b[39m\nC Horn, B.K.P., 1981. Hill shading and the reflectance map. Proceedings of the IEEE 69, 14\u201347. doi:10.1109/PROC.1981.11918\x1b[
39m\n\n\r\x1b[2K\r\x1b[2K[==                                                ] (4% - 0.0s - 1 threads)\r\x1b[2K[====                                              ] (9% - 0.0s - 1
threads)\r\x1b[2K[=======                                           ] (14% - 0.0s - 1 threads)\r\x1b[2K[=========                                         ] (19% - 0.0s - 1 thread
s)\r\x1b[2K[===========                                       ] (23% - 0.0s - 1 threads)\r\x1b[2K[==============                                    ] (28% - 0.0s - 1 threads)\r\x
1b[2K[================                                  ] (33% - 0.0s - 1 threads)\r\x1b[2K[===================                               ] (38% - 0.0s - 1 threads)\r\x1b[2K[
=====================                             ] (42% - 0.0s - 1 threads)\r\x1b[2K[=======================                           ] (47% - 0.0s - 1 threads)\r\x1b[2K[======
====================                        ] (52% - 0.0s - 1 threads)\r\x1b[2K[============================                      ] (57% - 0.0s - 1 threads)\r\x1b[2K[============
==================                    ] (61% - 0.0s - 1 threads)\r\x1b[2K[=================================                 ] (66% - 0.0s - 1 threads)\r\x1b[2K[==================
=================               ] (71% - 0.0s - 1 threads)\r\x1b[2K[======================================            ] (76% - 0.0s - 1 threads)\r\x1b[2K[========================
================          ] (80% - 0.0s - 1 threads)\r\x1b[2K[==========================================        ] (85% - 0.0s - 1 threads)\r\x1b[2K[==============================
===============     ] (90% - 0.0s - 1 threads)\r\x1b[2K[===============================================   ] (95% - 0.0s - 1 threads)\r\x1b[2Kt Wall-time = 0.00044846\x1b[39m
r-barnes commented 5 years ago

This is a good idea. As a workaround until I have time to fix this, you could consider temporarily redirecting output:

https://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr

Does this help?

joshburkart commented 5 years ago

Ah, I tried that but it unfortunately didn't seem to work... I'm guessing contextlib.redirect_stdout only operates within Python and doesn't affect C++ stuff that writes directly to /dev/stdout? Anyways I can totally just eat the messages for now! 😁