LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
LSST Data Management Base Package
Loading...
Searching...
No Matches
makeDiscreteSkyMap.py
Go to the documentation of this file.
1# This file is part of pipe_tasks.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
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 GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = ["MakeDiscreteSkyMapConfig", "MakeDiscreteSkyMapTask"]
23
24import lsst.sphgeom
25
26import lsst.geom as geom
27import lsst.pex.config as pexConfig
28import lsst.pipe.base as pipeBase
29from lsst.skymap import DiscreteSkyMap, BaseSkyMap
30from lsst.utils.timer import timeMethod
31
32
33class MakeDiscreteSkyMapConfig(pexConfig.Config):
34 """Config for MakeDiscreteSkyMapTask.
35 """
36
37 coaddName = pexConfig.Field(
38 doc="coadd name, e.g. deep, goodSeeing, chiSquared",
39 dtype=str,
40 default="deep",
41 )
42 skyMap = pexConfig.ConfigField(
43 dtype=BaseSkyMap.ConfigClass,
44 doc="SkyMap configuration parameters, excluding position and radius"
45 )
46 borderSize = pexConfig.Field(
47 doc="additional border added to the bounding box of the calexps, in degrees",
48 dtype=float,
49 default=0.0
50 )
51 doAppend = pexConfig.Field(
52 doc="append another tract to an existing DiscreteSkyMap on disk, if present?",
53 dtype=bool,
54 default=False
55 )
56 doWrite = pexConfig.Field(
57 doc="persist the skyMap?",
58 dtype=bool,
59 default=True,
60 )
61
62 def setDefaults(self):
63 self.skyMap.tractOverlap = 0.0
64
65
66class MakeDiscreteSkyMapTask(pipeBase.Task):
67 """Make a DiscreteSkyMap in a repository, using the bounding box of a set of calexps.
68
69 The command-line and run signatures and config are sufficiently different from MakeSkyMapTask
70 that we don't inherit from it, but it is a replacement, so we use the same config/metadata names.
71 """
72
73 ConfigClass = MakeDiscreteSkyMapConfig
74 _DefaultName = "makeDiscreteSkyMap"
75
76 @timeMethod
77 def run(self, wcs_bbox_tuple_list, oldSkyMap=None):
78 """Make a SkyMap from the bounds of the given set of calexp metadata.
79
80 Parameters
81 ----------
82 wcs_bbox_tuple_list : `iterable`
83 A list of tuples with each element expected to be a (Wcs, Box2I) pair.
84 oldSkyMap : `lsst.skymap.DiscreteSkyMap`, optional
85 The SkyMap to extend if appending.
86
87 Returns
88 -------
89 skyMap : `lsst.pipe.base.Struct`
90 Sky map returned as a struct with attributes:
91
92 ``skyMap``
93 The returned SkyMap (`lsst.skyMap.SkyMap`).
94 """
95 self.log.info("Extracting bounding boxes of %d images", len(wcs_bbox_tuple_list))
96 points = []
97 for wcs, boxI in wcs_bbox_tuple_list:
98 boxD = geom.Box2D(boxI)
99 points.extend(wcs.pixelToSky(corner).getVector() for corner in boxD.getCorners())
100 if len(points) == 0:
101 raise RuntimeError("No data found from which to compute convex hull")
102 self.log.info("Computing spherical convex hull")
104 if polygon is None:
105 raise RuntimeError(
106 "Failed to compute convex hull of the vertices of all calexp bounding boxes; "
107 "they may not be hemispherical."
108 )
109 circle = polygon.getBoundingCircle()
110
111 skyMapConfig = DiscreteSkyMap.ConfigClass()
112 if oldSkyMap:
113 skyMapConfig.raList.extend(oldSkyMap.config.raList)
114 skyMapConfig.decList.extend(oldSkyMap.config.decList)
115 skyMapConfig.radiusList.extend(oldSkyMap.config.radiusList)
116 configIntersection = {k: getattr(self.config.skyMap, k)
117 for k in self.config.skyMap.toDict()
118 if k in skyMapConfig}
119 skyMapConfig.update(**configIntersection)
120 circleCenter = lsst.sphgeom.LonLat(circle.getCenter())
121 skyMapConfig.raList.append(circleCenter[0].asDegrees())
122 skyMapConfig.decList.append(circleCenter[1].asDegrees())
123 circleRadiusDeg = circle.getOpeningAngle().asDegrees()
124 skyMapConfig.radiusList.append(circleRadiusDeg + self.config.borderSize)
125 skyMap = DiscreteSkyMap(skyMapConfig)
126
127 for tractInfo in skyMap:
128 wcs = tractInfo.getWcs()
129 posBox = geom.Box2D(tractInfo.getBBox())
130 pixelPosList = (
131 posBox.getMin(),
132 geom.Point2D(posBox.getMaxX(), posBox.getMinY()),
133 posBox.getMax(),
134 geom.Point2D(posBox.getMinX(), posBox.getMaxY()),
135 )
136 skyPosList = [wcs.pixelToSky(pos).getPosition(geom.degrees) for pos in pixelPosList]
137 posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
138 self.log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches",
139 tractInfo.getId(), ", ".join(posStrList),
140 tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1])
141 return pipeBase.Struct(
142 skyMap=skyMap
143 )
A floating-point coordinate rectangle geometry.
Definition Box.h:413
run(self, wcs_bbox_tuple_list, oldSkyMap=None)
static ConvexPolygon convexHull(std::vector< UnitVector3d > const &points)
convexHull returns the convex hull of the given set of points if it exists and throws an exception ot...
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition LonLat.h:55