LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
ds9Regions.py
Go to the documentation of this file.
1 from __future__ import division
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010, 2015 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 ##
25 ## \file
26 ## \brief Convert the display primitives into lists of ds9 region commands
27 ##
28 ## See e.g. http://ds9.si.edu/doc/ref/region.html
29 
30 import math
31 import re
32 import lsst.afw.geom as afwGeom
33 
34 def dot(symb, c, r, size, ctype=None, fontFamily="helvetica", textAngle=None):
35  """Draw a symbol onto the specified DS9 frame at (col,row) = (c,r) [0-based coordinates]
36 Possible values are:
37  + Draw a +
38  x Draw an x
39  * Draw a *
40  o Draw a circle
41  @:Mxx,Mxy,Myy Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored)
42  An object derived from afwGeom.ellipses.BaseCore Draw the ellipse (argument size is ignored)
43 Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be extended
44 with other characteristics, e.g. "times bold italic". Text will be drawn rotated by textAngle (textAngle is
45 ignored otherwise).
46 
47 N.b. objects derived from BaseCore include Axes and Quadrupole.
48 """
49  if ctype is None:
50  color = "" # the default
51  else:
52  color = ' # color=%s' % ctype
53 
54  regions = []
55 
56  r += 1
57  c += 1 # ds9 uses 1-based coordinates
58  if isinstance(symb, afwGeom.ellipses.Axes):
59  regions.append('ellipse %g %g %gi %gi %g%s' % (c, r, symb.getA(), symb.getB(),
60  math.degrees(symb.getTheta()), color))
61  elif symb == '+':
62  regions.append('line %g %g %g %g%s' % (c, r+size, c, r-size, color))
63  regions.append('line %g %g %g %g%s' % (c-size, r, c+size, r, color))
64  elif symb == 'x':
65  size = size/math.sqrt(2)
66  regions.append('line %g %g %g %g%s' % (c+size, r+size, c-size, r-size, color))
67  regions.append('line %g %g %g %g%s' % (c-size, r+size, c+size, r-size, color))
68  elif symb == '*':
69  size30 = 0.5*size
70  size60 = 0.5*math.sqrt(3)*size
71  regions.append('line %g %g %g %g%s' % (c+size, r, c-size, r, color))
72  regions.append('line %g %g %g %g%s' % (c-size30, r+size60, c+size30, r-size60, color))
73  regions.append('line %g %g %g %g%s' % (c+size30, r+size60, c-size30, r-size60, color))
74  elif symb == 'o':
75  regions.append('circle %g %g %gi%s' % (c, r, size, color))
76  else:
77  color = re.sub("^ # ", "", color) # skip the leading " # "
78 
79  angle = ""
80  if textAngle is not None:
81  angle += " textangle=%.1f"%(textAngle)
82 
83  font = ""
84  if size != 2 or fontFamily != "helvetica":
85  fontFamily = fontFamily.split()
86  font += ' font="%s %d' % (fontFamily.pop(0), int(10*size/2.0 + 0.5))
87  if not fontFamily:
88  fontFamily = ["normal"] # appears to be needed at least for 7.4b1
89  font += " %s" % " ".join(fontFamily)
90  font += '"'
91  extra = ""
92  if color or angle or font:
93  extra = " # "
94  extra += color
95  extra += angle
96  extra += font
97 
98  regions.append('text %g %g \"%s\"%s' % (c, r, symb, extra))
99 
100  return regions
101 
102 def drawLines(points, ctype=None):
103  """!Draw a line by connecting the points
104  \param points a list of (col,row)
105  \param ctype the name of the desired colour (e.g. 'red', 'orchid')
106  """
107 
108  if ctype == None: # default
109  color = ""
110  else:
111  color = "# color=%s" % ctype
112 
113  regions = []
114  if len(points) > 0:
115  c0, r0 = points[0]
116  r0 += 1
117  c0 += 1 # ds9 uses 1-based coordinates
118  for (c, r) in points[1:]:
119  r += 1
120  c += 1 # ds9 uses 1-based coordinates
121  regions.append('line %g %g %g %g %s' % (c0, r0, c, r, color))
122  c0, r0 = c, r
123 
124  return regions
125 
def drawLines
Draw a line by connecting the points.
Definition: ds9Regions.py:102