LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Classes | Functions | Variables
lsst.display.ds9.ds9 Namespace Reference

Classes

class  Buffer
 
class  DisplayImpl
 
class  Ds9Error
 
class  Ds9Event
 

Functions

def getXpaAccessPoint ()
 
def ds9Version ()
 
def selectFrame (frame)
 
def ds9Cmd (cmd=None, trap=True, flush=False, silent=True, frame=None, get=False)
 
def initDS9 (execDs9=True)
 

Variables

 file
 
bool needShow = True
 
int XPA_SZ_LINE = 4096 - 100
 
 cmdBuffer
 
 haveGzip = not os.system("gzip < /dev/null > /dev/null 2>&1")
 
bool definedCallbacks = True
 

Function Documentation

◆ ds9Cmd()

def lsst.display.ds9.ds9.ds9Cmd (   cmd = None,
  trap = True,
  flush = False,
  silent = True,
  frame = None,
  get = False 
)
Issue a DS9 command, raising errors as appropriate.

Parameters
----------
cmd : `str`, optional
    Command to execute.
trap : `bool`, optional
    Trap errors.
flush : `bool`, optional
    Flush the output.
silent : `bool`, optional
    Do not print trapped error messages.
frame : `int`, optional
    Frame number on which to execute command.
get : `bool`, optional
    Return xpa response.

Definition at line 225 of file ds9.py.

225def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False):
226 """Issue a DS9 command, raising errors as appropriate.
227
228 Parameters
229 ----------
230 cmd : `str`, optional
231 Command to execute.
232 trap : `bool`, optional
233 Trap errors.
234 flush : `bool`, optional
235 Flush the output.
236 silent : `bool`, optional
237 Do not print trapped error messages.
238 frame : `int`, optional
239 Frame number on which to execute command.
240 get : `bool`, optional
241 Return xpa response.
242 """
243
244 global cmdBuffer
245 if cmd:
246 if frame is not None:
247 cmd = "%s;" % selectFrame(frame) + cmd
248
249 if get:
250 return xpa.get(None, getXpaAccessPoint(), cmd, "").strip()
251
252 # Work around xpa's habit of silently truncating long lines; the value
253 # ``5`` provides some margin to handle new lines and the like.
254 if cmdBuffer._lenCommands + len(cmd) > XPA_SZ_LINE - 5:
255 ds9Cmd(flush=True, silent=silent)
256
257 cmdBuffer._commands += ";" + cmd
258 cmdBuffer._lenCommands += 1 + len(cmd)
259
260 if flush or cmdBuffer._lenCommands >= cmdBuffer._getSize():
261 cmd = (cmdBuffer._commands + "\n")
262 cmdBuffer._commands = ""
263 cmdBuffer._lenCommands = 0
264 else:
265 return
266
267 cmd = cmd.rstrip()
268 if not cmd:
269 return
270
271 try:
272 ret = xpa.set(None, getXpaAccessPoint(), cmd, "", "", 0)
273 if ret:
274 raise IOError(ret)
275 except IOError as e:
276 if not trap:
277 raise Ds9Error("XPA: %s, (%s)" % (e, cmd))
278 elif not silent:
279 print("Caught ds9 exception processing command \"%s\": %s" % (cmd, e), file=sys.stderr)
280
281
bool strip
Definition: fits.cc:911
def selectFrame(frame)
Definition: ds9.py:210
def getXpaAccessPoint()
Definition: ds9.py:61
def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False)
Definition: ds9.py:225

◆ ds9Version()

def lsst.display.ds9.ds9.ds9Version ( )
Get the version of DS9 in use.

Returns
-------
version : `str`
    Version of DS9 in use.

Definition at line 89 of file ds9.py.

89def ds9Version():
90 """Get the version of DS9 in use.
91
92 Returns
93 -------
94 version : `str`
95 Version of DS9 in use.
96 """
97 try:
98 v = ds9Cmd("about", get=True)
99 return v.splitlines()[1].split()[1]
100 except Exception as e:
101 print("Error reading version: %s" % e, file=sys.stderr)
102 return "0.0.0"
103
104
105try:
106 cmdBuffer
def ds9Version()
Definition: ds9.py:89

◆ getXpaAccessPoint()

def lsst.display.ds9.ds9.getXpaAccessPoint ( )
Parse XPA_PORT if set and return an identifier to send DS9 commands.

Returns
-------

xpaAccessPoint : `str`
    Either a reference to the local host with the configured port, or the
    string ``"ds9"``.

Notes
-----
If you don't have XPA_PORT set, the usual xpans tricks will be played
when we return ``"ds9"``.

Definition at line 61 of file ds9.py.

62 """Parse XPA_PORT if set and return an identifier to send DS9 commands.
63
64 Returns
65 -------
66
67 xpaAccessPoint : `str`
68 Either a reference to the local host with the configured port, or the
69 string ``"ds9"``.
70
71 Notes
72 -----
73 If you don't have XPA_PORT set, the usual xpans tricks will be played
74 when we return ``"ds9"``.
75 """
76 xpa_port = os.environ.get("XPA_PORT")
77 if xpa_port:
78 mat = re.search(r"^DS9:ds9\s+(\d+)\s+(\d+)", xpa_port)
79 if mat:
80 port1, port2 = mat.groups()
81
82 return "127.0.0.1:%s" % (port1)
83 else:
84 print("Failed to parse XPA_PORT=%s" % xpa_port, file=sys.stderr)
85
86 return "ds9"
87
88

◆ initDS9()

def lsst.display.ds9.ds9.initDS9 (   execDs9 = True)
Initialize DS9.

Parameters
----------
execDs9 : `bool`, optional
    If DS9 is not running, attempt to execute it.

Definition at line 282 of file ds9.py.

282def initDS9(execDs9=True):
283 """Initialize DS9.
284
285 Parameters
286 ----------
287 execDs9 : `bool`, optional
288 If DS9 is not running, attempt to execute it.
289 """
290 try:
291 xpa.reset()
292 ds9Cmd("iconify no; raise", False)
293 ds9Cmd("wcs wcsa", False) # include the pixel coordinates WCS (WCSA)
294
295 v0, v1 = ds9Version().split('.')[0:2]
296 global needShow
297 needShow = False
298 try:
299 if int(v0) == 5:
300 needShow = (int(v1) <= 4)
301 except Exception:
302 pass
303 except Ds9Error as e:
304 if not re.search('xpa', os.environ['PATH']):
305 raise Ds9Error('You need the xpa binaries in your path to use ds9 with python')
306
307 if not execDs9:
308 raise Ds9Error
309
310 import distutils.spawn
311 if not distutils.spawn.find_executable("ds9"):
312 raise NameError("ds9 doesn't appear to be on your path")
313 if "DISPLAY" not in os.environ:
314 raise RuntimeError("$DISPLAY isn't set, so I won't be able to start ds9 for you")
315
316 print("ds9 doesn't appear to be running (%s), I'll try to exec it for you" % e)
317
318 os.system('ds9 &')
319 for i in range(10):
320 try:
321 ds9Cmd(selectFrame(1), False)
322 break
323 except Ds9Error:
324 print("waiting for ds9...\r", end="")
325 sys.stdout.flush()
326 time.sleep(0.5)
327 else:
328 print(" \r", end="")
329 break
330
331 sys.stdout.flush()
332
333 raise Ds9Error
334
335
def initDS9(execDs9=True)
Definition: ds9.py:282

◆ selectFrame()

def lsst.display.ds9.ds9.selectFrame (   frame)
Convert integer frame number to DS9 command syntax.

Parameters
----------
frame : `int`
    Frame number

Returns
-------
frameString : `str`

Definition at line 210 of file ds9.py.

210def selectFrame(frame):
211 """Convert integer frame number to DS9 command syntax.
212
213 Parameters
214 ----------
215 frame : `int`
216 Frame number
217
218 Returns
219 -------
220 frameString : `str`
221 """
222 return "frame %d" % (frame)
223
224

Variable Documentation

◆ cmdBuffer

lsst.display.ds9.ds9.cmdBuffer

Definition at line 207 of file ds9.py.

◆ definedCallbacks

bool lsst.display.ds9.ds9.definedCallbacks = True

Definition at line 697 of file ds9.py.

◆ file

lsst.display.ds9.ds9.file

Definition at line 39 of file ds9.py.

◆ haveGzip

lsst.display.ds9.ds9.haveGzip = not os.system("gzip < /dev/null > /dev/null 2>&1")

Definition at line 638 of file ds9.py.

◆ needShow

bool lsst.display.ds9.ds9.needShow = True

Definition at line 47 of file ds9.py.

◆ XPA_SZ_LINE

int lsst.display.ds9.ds9.XPA_SZ_LINE = 4096 - 100

Definition at line 109 of file ds9.py.