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