LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+34d9b7f18a,g199a45376c+0ba108daf9,g1fd858c14a+65eb7a42b2,g210f2d0738+433bb88fac,g262e1987ae+25affdb0d7,g29ae962dfc+5a80ce4088,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+539dd5938e,g40765c0b17+3897dae354,g47891489e3+9fb4c380a7,g4d44eb3520+36a09736a7,g4d7b6aa1c5+433bb88fac,g53246c7159+8c5ae1fdc5,g67b6fd64d1+9fb4c380a7,g67fd3c3899+433bb88fac,g6f56aede96+7a96d8be89,g74acd417e5+80fe3eed8d,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+9fb4c380a7,g8d7436a09f+5493bef79b,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+ad1a85a838,gabf8522325+735880ea63,gac2eed3f23+9fb4c380a7,gb89ab40317+9fb4c380a7,gbf99507273+8c5ae1fdc5,gc37df8378d+e63d58df72,gd8ff7fe66e+433bb88fac,gdab6d2f7ff+80fe3eed8d,ge410e46f29+9fb4c380a7,geaed405ab2+562b3308c0,gf28766cb3b+4432f2d694,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