lsst.afw  16.0-9-gdf7162dbc+1
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 
28 
29 import math
30 import re
31 import lsst.afw.geom as afwGeom
32 
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' %
67  (c+size, r+size, c-size, r-size, color))
68  regions.append('line %g %g %g %g%s' %
69  (c-size, r+size, c+size, r-size, color))
70  elif symb == '*':
71  size30 = 0.5*size
72  size60 = 0.5*math.sqrt(3)*size
73  regions.append('line %g %g %g %g%s' % (c+size, r, c-size, r, color))
74  regions.append('line %g %g %g %g%s' %
75  (c-size30, r+size60, c+size30, r-size60, color))
76  regions.append('line %g %g %g %g%s' %
77  (c+size30, r+size60, c-size30, r-size60, color))
78  elif symb == 'o':
79  regions.append('circle %g %g %gi%s' % (c, r, size, color))
80  else:
81  color = re.sub("^ # ", "", color) # skip the leading " # "
82 
83  angle = ""
84  if textAngle is not None:
85  angle += " textangle=%.1f"%(textAngle)
86 
87  font = ""
88  if size != 2 or fontFamily != "helvetica":
89  fontFamily = fontFamily.split()
90  font += ' font="%s %d' % (fontFamily.pop(0),
91  int(10*size/2.0 + 0.5))
92  if not fontFamily:
93  # appears to be needed at least for 7.4b1
94  fontFamily = ["normal"]
95  font += " %s" % " ".join(fontFamily)
96  font += '"'
97  extra = ""
98  if color or angle or font:
99  extra = " # "
100  extra += color
101  extra += angle
102  extra += font
103 
104  regions.append('text %g %g \"%s\"%s' % (c, r, symb, extra))
105 
106  return regions
107 
108 
109 def drawLines(points, ctype=None):
110  """!Draw a line by connecting the points
111  @param points a list of (col,row)
112  @param ctype the name of the desired colour (e.g. 'red', 'orchid')
113  """
114 
115  if ctype is None: # default
116  color = ""
117  else:
118  color = "# color=%s" % ctype
119 
120  regions = []
121  if len(points) > 0:
122  c0, r0 = points[0]
123  r0 += 1
124  c0 += 1 # ds9 uses 1-based coordinates
125  for (c, r) in points[1:]:
126  r += 1
127  c += 1 # ds9 uses 1-based coordinates
128  regions.append('line %g %g %g %g %s' % (c0, r0, c, r, color))
129  c0, r0 = c, r
130 
131  return regions
def drawLines(points, ctype=None)
Draw a line by connecting the points.
Definition: ds9Regions.py:109
def dot(symb, c, r, size, ctype=None, fontFamily="helvetica", textAngle=None)
Definition: ds9Regions.py:34