In your task code: when you call:
debug = lsstDebug.Info(__name__)
(with __name__
being the name of the current task), you are given a "debug object". By default that will return False
for any attribute you access. Thus, you can do:
>>> debug.foo
False
>>> debug.bar
False
>>> debug.display
False
You can override the behaviour of the display object by using a debug.py
file. In this, you want to define a function that, when called with __name__
, as an argument will provide non-False
values for certain combinations of __name__
and attribute. Thus, you can do things like:
>>> debug = lsstDebug.Info(__name__) # __name__ selects the current task
>>> debug.display
True
Then you can write your task to optionally enable a display (or whatever) by doing something like:
if debug.display:
afwDisplay.getDisplay()....
else:
self.log.debug("I would show you a pretty picture here if you enabled debugging.")
How to make this work? Create a debug.py
in your working directory, and put something like this in it:
import lsstDebug
def DebugInfo(name):
debug = lsstDebug.getInfo(name)
if name == "lsst.meas.astrom.astrometry":
debug.display = True
return debug
lsstDebug.Info = DebugInfo
That should enable debugging when you are running inside lsst.meas.astrom.astrometry
, and disable it elsewhere.
Of coruse, you can also return arbitrarily more complex objects, doing things like specifying the frame to display on etc. And I believe you can use the -d
commmant line argument to pass a path to debug.py
rather than using a working dir.