I don't really understand your unhappiness. You can configure the display system by putting something like
import lsst.afw.display as afwDisplay
|
afwDisplay.setDefaultBackend("ds9")
|
in your pythonstartup file, then
display = afwDisplay.getDisplay()
|
this seems essentially the same as the matplotlib approach, except that the verb is "get" not "add".
I deliberately did not invent a configuration system using config files and environment variables (but see my query on hipchat).
I don't think it would be appropriate to include a "real" device in afw – what would you use? Surely not ds9. I suppose we could write a matplotlib backend; but that would be a separate issue.
Testing for "loaded" in globals() might be a bit clearer than using try/except, e.g.:
if not globals().get("loaded", False):
|
if getDefaultBackend() == "virtualDevice":
|
try:
|
setDefaultBackend("lsst.display.ds9")
|
except ImportError as e:
|
raise ImportError("Unable to import lsst.display.ds9: %s" % e)
|
|
loaded = True
|
|
I think it's clearer and more pythonic to use try/except here
Instead of using one technique to import Buffering from afwDisplay and a different technique to import colors, it would be less confusing to import both the same way, e.g.: |
from lsst.afw.display import Buffering, BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE |
This won't work, as I'm importing Buffering from the class Display
I am a bit unhappy about all those globals (_defaultBackend, _defaultFrame, _defaultMaskTransparency and _displays). You have a Display object. Wouldn't it be clearer and less messy to turn those globals into class variables? |
I agree; done
utils.getDisplay API is very confusing to me. The name matches an existing function afwDisplay.getDisplay but the API is totally different. What is the point of the utils version? |
I changed the name to make it clearer that this is a utility function to handle being given both frame and
display arguments.
Does it make sense to import Mosaic into the lsst.afw.display namespace? |
I needed to avoid a circular import to make this work, but done.
Pushed to github. There's a test script, tests/display.py, that uses the virtual device by default. If you clone and setup git@github.com:lsst/display_ds9 you can say
tests/display.py ds9
to run the tests on ds9.