LSST Applications g042eb84c57+b3bbdc4f1a,g04e9c324dd+8c5ae1fdc5,g121cf07809+de4bf23b53,g134cb467dc+0cbace0124,g199a45376c+0ba108daf9,g1fd858c14a+1dc7511062,g210f2d0738+9c061127b9,g262e1987ae+2d37dc3994,g29ae962dfc+d9a9135c6e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+f525e742cf,g47891489e3+a82ffe86f0,g4d44eb3520+3036bb6e09,g4d7b6aa1c5+9c061127b9,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+f4bcfd44dd,g64539dfbff+9c061127b9,g67b6fd64d1+a82ffe86f0,g67fd3c3899+9c061127b9,g6985122a63+a82ffe86f0,g6eac29cc47+0486cfe5cd,g74acd417e5+b6fc5cdc3f,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+a82ffe86f0,g8d7436a09f+f523aa4ebd,g8ea07a8fe4+f5f58b89a4,g90f42f885a+b932d389a5,g97be763408+ef481f73f1,g99822b682c+47dc04c1e3,ga41d0fce20+fba9b6fb88,gbf99507273+8c5ae1fdc5,gd7ef33dd92+a82ffe86f0,gdab6d2f7ff+b6fc5cdc3f,ge410e46f29+a82ffe86f0,geaed405ab2+af3bcf2cab,gf9a733ac38+8c5ae1fdc5,w.2025.37
LSST Data Management Base Package
Loading...
Searching...
No Matches
utils.py
Go to the documentation of this file.
1# This file is part of afw.
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__ = ["writeFootprintAsDefects", "footprintsToNumpy"]
23
24import numpy as np
25
26import lsst.geom as geom
27from lsst.afw.table import SourceCatalog
28
29from . import footprintToBBoxList
30
31
33 """
34 Write foot as a set of Defects to fd
35
36 Given a detection footprint, convert it to a BBoxList and write the output to the file object fd.
37
38 Parameters
39 ----------
40 fd : `typing.TextIO`
41 foot : `lsst.afw.detection.Footprint`
42
43 See Also
44 --------
45 lsst.afw.detection.footprintToBBoxList
46 """
47
48 bboxes = footprintToBBoxList(foot)
49 for bbox in bboxes:
50 print("""\
51Defects: {
52 x0: %4d # Starting column
53 width: %4d # number of columns
54 y0: %4d # Starting row
55 height: %4d # number of rows
56}""" % (bbox.getMinX(), bbox.getWidth(), bbox.getMinY(), bbox.getHeight()), file=fd)
57
58
60 catalog: SourceCatalog,
61 bbox: geom.Box2I | None = None,
62 shape: tuple[int, int] | None = None,
63 xy0: tuple[int, int] | None = None,
64 asBool: bool = True,
65) -> np.ndarray:
66 """Convert all of the footprints in a catalog into a boolean array.
67
68 Parameters
69 ----------
70 catalog:
71 The source catalog containing the footprints.
72 This is typically a mergeDet catalog, or a full source catalog
73 with the parents removed.
74 shape:
75 The final shape of the output array.
76 xy0:
77 The lower-left corner of the array that will contain the spans.
78
79 Returns
80 -------
81 result:
82 The array with pixels contained in `spans` marked as `True`.
83 """
84 if bbox is None and shape is None:
85 raise RuntimeError("Must provide either bbox or shape")
86
87 if bbox is not None:
88 width, height = bbox.getDimensions()
89 shape = (height, width)
90 xy0 = (bbox.getMinX(), bbox.getMinY())
91
92 if xy0 is None:
93 offset = (0, 0)
94 else:
95 offset = (-xy0[0], -xy0[1])
96
97 result = np.zeros(shape, dtype=int)
98 for src in catalog:
99 spans = src.getFootprint().spans
100 yidx, xidx = spans.shiftedBy(*offset).indices()
101 result[yidx, xidx] = src.getId()
102 if asBool:
103 result = result != 0
104 return result
An integer coordinate rectangle.
Definition Box.h:55
writeFootprintAsDefects(fd, foot)
Definition utils.py:32
np.ndarray footprintsToNumpy(SourceCatalog catalog, geom.Box2I|None bbox=None, tuple[int, int]|None shape=None, tuple[int, int]|None xy0=None, bool asBool=True)
Definition utils.py:65
std::vector< lsst::geom::Box2I > footprintToBBoxList(Footprint const &footprint)
Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor le...
Definition Footprint.cc:366