lsst.afw  15.0-29-ga12a2b06e
coordinatesContinued.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008-2017 LSST/AURA.
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 __all__ = ["CoordinateExpr", "Extent", "ExtentI", "ExtentD",
24  "Point", "PointI", "PointD"]
25 
26 from lsst.utils import TemplateMeta
27 
28 from . import coordinates
29 
30 
31 def _coordinateStr(self):
32  return "({})".format(", ".join("%0.5g" % v for v in self))
33 
34 
35 def _coordinateRepr(self):
36  return "{}({})".format(type(self).__name__,
37  ", ".join("%0.10g" % v for v in self))
38 
39 
40 def _coordinateReduce(self):
41  return (type(self), tuple(self))
42 
43 
44 class CoordinateExpr(metaclass=TemplateMeta):
45  """Abstract base class and factory for CoordinateExpr objects.
46  """
47  TEMPLATE_PARAMS = ("dimensions", )
48 
49  __str__ = _coordinateStr
50  __repr__ = _coordinateRepr
51  __reduce__ = _coordinateReduce
52 
53 
54 CoordinateExpr.register(2, coordinates.CoordinateExpr2)
55 CoordinateExpr.register(3, coordinates.CoordinateExpr3)
56 
57 
58 class Extent(metaclass=TemplateMeta):
59  """Abstract base class and factory for Extent objects.
60  """
61  TEMPLATE_PARAMS = ("dtype", "dimensions")
62  TEMPLATE_DEFAULTS = (None, 2)
63 
64  __str__ = _coordinateStr
65  __repr__ = _coordinateRepr
66  __reduce__ = _coordinateReduce
67 
68 
69 Extent.register((int, 2), coordinates.Extent2I)
70 Extent.register((float, 2), coordinates.Extent2D)
71 Extent.register((int, 3), coordinates.Extent3I)
72 Extent.register((float, 3), coordinates.Extent3D)
73 ExtentI = coordinates.Extent2I
74 ExtentD = coordinates.Extent2D
75 
76 
77 class Point(metaclass=TemplateMeta):
78  """Abstract base class and factory for Point objects.
79  """
80  TEMPLATE_PARAMS = ("dtype", "dimensions")
81  TEMPLATE_DEFAULTS = (None, 2)
82 
83  __str__ = _coordinateStr
84  __repr__ = _coordinateRepr
85  __reduce__ = _coordinateReduce
86 
87 
88 Point.register((int, 2), coordinates.Point2I)
89 Point.register((float, 2), coordinates.Point2D)
90 Point.register((int, 3), coordinates.Point3I)
91 Point.register((float, 3), coordinates.Point3D)
92 PointI = coordinates.Point2I
93 PointD = coordinates.Point2D