lsst.afw  14.0-42-g99f9a3040+1
ds9Regions.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
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 
29 
30 import math
31 import re
32 import lsst.afw.geom as afwGeom
33 
34 
35 def dot(symb, c, r, size, ctype=None, fontFamily="helvetica", textAngle=None):
36  """Draw a symbol onto the specified DS9 frame at (col,row) = (c,r) [0-based coordinates]
37 Possible values are:
38  + Draw a +
39  x Draw an x
40  * Draw a *
41  o Draw a circle
42  @:Mxx,Mxy,Myy Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored)
43  An object derived from afwGeom.ellipses.BaseCore Draw the ellipse (argument size is ignored)
44 Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be extended
45 with other characteristics, e.g. "times bold italic". Text will be drawn rotated by textAngle (textAngle is
46 ignored otherwise).
47 
48 N.b. objects derived from BaseCore include Axes and Quadrupole.
49 """
50  if ctype is None:
51  color = "" # the default
52  else:
53  color = ' # color=%s' % ctype
54 
55  regions = []
56 
57  r += 1
58  c += 1 # ds9 uses 1-based coordinates
59  if isinstance(symb, afwGeom.ellipses.Axes):
60  regions.append('ellipse %g %g %gi %gi %g%s' % (c, r, symb.getA(), symb.getB(),
61  math.degrees(symb.getTheta()), color))
62  elif symb == '+':
63  regions.append('line %g %g %g %g%s' % (c, r+size, c, r-size, color))
64  regions.append('line %g %g %g %g%s' % (c-size, r, c+size, r, color))
65  elif symb == 'x':
66  size = size/math.sqrt(2)
67  regions.append('line %g %g %g %g%s' %
68  (c+size, r+size, c-size, r-size, color))
69  regions.append('line %g %g %g %g%s' %
70  (c-size, r+size, c+size, r-size, color))
71  elif symb == '*':
72  size30 = 0.5*size
73  size60 = 0.5*math.sqrt(3)*size
74  regions.append('line %g %g %g %g%s' % (c+size, r, c-size, r, color))
75  regions.append('line %g %g %g %g%s' %
76  (c-size30, r+size60, c+size30, r-size60, color))
77  regions.append('line %g %g %g %g%s' %
78  (c+size30, r+size60, c-size30, r-size60, color))
79  elif symb == 'o':
80  regions.append('circle %g %g %gi%s' % (c, r, size, color))
81  else:
82  color = re.sub("^ # ", "", color) # skip the leading " # "
83 
84  angle = ""
85  if textAngle is not None:
86  angle += " textangle=%.1f"%(textAngle)
87 
88  font = ""
89  if size != 2 or fontFamily != "helvetica":
90  fontFamily = fontFamily.split()
91  font += ' font="%s %d' % (fontFamily.pop(0),
92  int(10*size/2.0 + 0.5))
93  if not fontFamily:
94  # appears to be needed at least for 7.4b1
95  fontFamily = ["normal"]
96  font += " %s" % " ".join(fontFamily)
97  font += '"'
98  extra = ""
99  if color or angle or font:
100  extra = " # "
101  extra += color
102  extra += angle
103  extra += font
104 
105  regions.append('text %g %g \"%s\"%s' % (c, r, symb, extra))
106 
107  return regions
108 
109 
110 def drawLines(points, ctype=None):
111  """!Draw a line by connecting the points
112  \param points a list of (col,row)
113  \param ctype the name of the desired colour (e.g. 'red', 'orchid')
114  """
115 
116  if ctype is None: # default
117  color = ""
118  else:
119  color = "# color=%s" % ctype
120 
121  regions = []
122  if len(points) > 0:
123  c0, r0 = points[0]
124  r0 += 1
125  c0 += 1 # ds9 uses 1-based coordinates
126  for (c, r) in points[1:]:
127  r += 1
128  c += 1 # ds9 uses 1-based coordinates
129  regions.append('line %g %g %g %g %s' % (c0, r0, c, r, color))
130  c0, r0 = c, r
131 
132  return regions
def drawLines(points, ctype=None)
Draw a line by connecting the points.
Definition: ds9Regions.py:110
def dot(symb, c, r, size, ctype=None, fontFamily="helvetica", textAngle=None)
Definition: ds9Regions.py:35