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 the setDefaultFeedback() 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() and onProgress() 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.

class grale.feedback.StdoutFeedback

Derives from Feedback and writes the status messages and percentages to the standard output.

class grale.feedback.NotebookFeedback

Derives from Feedback and writes the status messages and percentages to widgets that can be displayed in an IPython notebook.

Helper functions

grale.feedback.getFeedbackClass(feedbackName)
Returns the class that corresponds to feedbackName, which can be one of
grale.feedback.setDefaultFeedback(feedbackNameOrClass)

Sets the feedback mechamism that’s used when specifying "default". The feedbackNameOrClass parameter can either be one of the strings that’s recognized by the getFeedbackClass() function, or it can be the name of a class derived from Feedback.

exception grale.feedback.FeedbackException

This exception is thrown in case of an error in this module.