grale.feedback
This module is used to provide you with feedback during some calculations that can take a while, like rendering the mass density of a gravitational lens in a distributed way using MPI.
When a feedback mechanism is required by one of the functions in grale.plotutil
you’ll normally just specify a name for the feedback mechanism, which can be one of
"none"
: in this case no feedback will be generated
"stdout"
: feedback will be written line per line to standard output
"notebook"
: this mechanism can be used if an IPython notebook is being used, in which case e.g. a progress bar will be shown.
"default"
: selects the feedback mechanism that has been set by thesetDefaultFeedback()
function.
For example, in an IPython notebook you could do something like:
import grale.feedback as feedback
feedback.setDefaultFeedback("notebook")
and various rendering calculations will use a nice progress bar and a status message box.
Instead of specifying a feedback mechanism as a string, you can also specify the feedback
object to be used. This could be helpful if you wanted to create your own feedback mechanism
for example. In that case, you’ll need to define an object that contains onStatus
and
onProgress
member functions, like in the Feedback
base class.
Feedback classes
- class grale.feedback.Feedback
The base class for feedback objects, which doesn’t do anything by itself. It does define the
onStatus()
andonProgress()
member functions that are required for a feedback object.- onProgress(x)
This function will be called if a progress percentage
x
is reported.
- onStatus(s)
This function will be called if a status message
s
needs to be displayed.
Helper functions
- grale.feedback.getFeedbackClass(feedbackName)
- Returns the class that corresponds to
feedbackName
, which can be one of "none"
: in this caseFeedback
will be returned, so no output will be generated"stdout"
: theStdoutFeedback
class will be returned"notebook"
: theNotebookFeedback
class will be returned"default"
: returns the class that was previously set by callingsetDefaultFeedback()
- Returns the class that corresponds to
- grale.feedback.setDefaultFeedback(feedbackNameOrClass)
Sets the feedback mechamism that’s used when specifying
"default"
. ThefeedbackNameOrClass
parameter can either be one of the strings that’s recognized by thegetFeedbackClass()
function, or it can be the name of a class derived fromFeedback
.
- exception grale.feedback.FeedbackException
This exception is thrown in case of an error in this module.