sherpa.plot.backend_utils.translate_args(func)[source] [edit on github]

A decorator to translate function arguments.

When a method decorated with this decorator is called, the decorator inspects the arguments that are passed into the function. For each argument that is found as a key in the object’s translate_args dictionary, the value of that argument is translated. The items in that dictionary can be functions or dictionaries.

The purpose of this decorator is to support backends that use different syntax for the same option, e.g. one backend might call a color “red”, while another uses the tuple (1, 0, 0) to describe the same color.


In this example, the input ‘r’ or ‘b’ will be translated into an rgb tuple before the plot function is called. Other values (e.g. color=(0, 0, 0)) will be passed through unchanged so that the user can also make use of any other color specification that the backend allows.

>>> from sherpa.plot import backend_utils
>>> class Plotter:
...     translate_args = {'color': {'r': (1,0,0), 'b': (0,0,1)}}
...     @backend_utils.translate_args
...     def plot(color=None):
...         print('RGB color tuple is: ', color)