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