lsst.meas.algorithms
g4a7591d645+fa9daf83c6
Toggle main menu visibility
Loading...
Searching...
No Matches
python
lsst
meas
algorithms
makePsfCandidates.py
Go to the documentation of this file.
1
#
2
# LSST Data Management System
3
#
4
# Copyright 2008-2017 AURA/LSST.
5
#
6
# This product includes software developed by the
7
# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20
# the GNU General Public License along with this program. If not,
21
# see <https://www.lsstcorp.org/LegalNotices/>.
22
#
23
__all__ = [
"MakePsfCandidatesConfig"
,
"MakePsfCandidatesTask"
]
24
25
import
numpy
as
np
26
27
from
lsst.afw.table
import
SourceCatalog
28
import
lsst.afw.math
as
afwMath
29
import
lsst.pex.config
as
pexConfig
30
import
lsst.pex.exceptions
31
import
lsst.pipe.base
as
pipeBase
32
from
.
import
makePsfCandidate
33
34
35
class
MakePsfCandidatesConfig
(pexConfig.Config):
36
kernelSize = pexConfig.Field[int](
37
doc=
"Size of the postage stamp in pixels (excluding the border) around each star that is extracted "
38
"for fitting. Should be odd and preferably at least 25."
,
39
default=27,
40
)
41
borderWidth = pexConfig.Field[int](
42
doc=
"Number of pixels to ignore around the edge of PSF candidate postage stamps"
,
43
default=0,
44
)
45
46
47
class
MakePsfCandidatesTask
(pipeBase.Task):
48
"""Create PSF candidates given an input catalog."""
49
50
ConfigClass = MakePsfCandidatesConfig
51
_DefaultName =
"makePsfCandidates"
52
53
def
run
(self, starCat, exposure, psfCandidateField=None):
54
"""Make a list of PSF candidates from a star catalog.
55
56
Parameters
57
----------
58
starCat : `lsst.afw.table.SourceCatalog`
59
Catalog of stars, as returned by
60
``lsst.meas.algorithms.starSelector.run()``.
61
exposure : `lsst.afw.image.Exposure`
62
The exposure containing the sources.
63
psfCandidateField : `str`, optional
64
Name of flag field to set True for PSF candidates, or None to not
65
set a field; the field is left unchanged for non-candidates.
66
67
Returns
68
-------
69
struct : `lsst.pipe.base.Struct`
70
Results struct containing:
71
72
- ``psfCandidates`` : List of PSF candidates
73
(`list` of `lsst.meas.algorithms.PsfCandidate`).
74
- ``goodStarCat`` : Subset of ``starCat`` that was successfully made
75
into PSF candidates (`lsst.afw.table.SourceCatalog`).
76
77
"""
78
psfResult = self.
makePsfCandidates
(starCat, exposure)
79
80
if
psfCandidateField
is
not
None
:
81
isStarKey = starCat.schema[psfCandidateField].asKey()
82
for
star
in
psfResult.goodStarCat:
83
star.set(isStarKey,
True
)
84
85
return
psfResult
86
87
def
makePsfCandidates(self, starCat, exposure):
88
"""Make a list of PSF candidates from a star catalog.
89
90
Parameters
91
----------
92
starCat : `lsst.afw.table.SourceCatalog`
93
Catalog of stars, as returned by
94
``lsst.meas.algorithms.starSelector.run()``.
95
exposure : `lsst.afw.image.Exposure`
96
The exposure containing the sources.
97
98
Returns
99
-------
100
struct : `lsst.pipe.base.Struct`
101
Results struct containing:
102
103
- ``psfCandidates`` : List of PSF candidates
104
(`list` of `lsst.meas.algorithms.PsfCandidate`).
105
- ``goodStarCat`` : Subset of ``starCat`` that was successfully made
106
into PSF candidates (`lsst.afw.table.SourceCatalog`).
107
"""
108
goodStarCat =
SourceCatalog
(starCat.schema)
109
110
psfCandidateList = []
111
didSetSize =
False
112
for
star
in
starCat:
113
psfCandidate =
makePsfCandidate
(star, exposure)
114
try
:
115
psfCandidate.setPsfColorValue(star[
"psf_color_value"
])
116
psfCandidate.setPsfColorType(star[
"psf_color_type"
])
117
except
Exception:
118
psfCandidate.setPsfColorValue(np.nan)
119
psfCandidate.setPsfColorType(
""
)
120
try
:
121
# The setXXX methods are class static, but it's convenient to call them on
122
# an instance as we don't know exposures's pixel type
123
# (and hence psfCandidate's exact type)
124
if
not
didSetSize:
125
psfCandidate.setBorderWidth(self.config.borderWidth)
126
psfCandidate.setWidth(self.config.kernelSize + 2 * self.config.borderWidth)
127
psfCandidate.setHeight(self.config.kernelSize + 2 * self.config.borderWidth)
128
didSetSize =
True
129
130
im = psfCandidate.getMaskedImage().getImage()
131
except
lsst.pex.exceptions.LengthError
:
132
self.log.warning(
133
"Could not get stamp for psfCandidate with source id=%s: %s"
, star.getId(), psfCandidate
134
)
135
continue
136
except
lsst.pex.exceptions.Exception
as
e:
137
self.log.error(
138
"%s raised making psfCandidate from source id=%s: %s"
,
139
e.__class__.__name__,
140
star.getId(),
141
psfCandidate,
142
)
143
self.log.error(
"psfCandidate exception: %s"
, e)
144
continue
145
146
vmax = afwMath.makeStatistics(im, afwMath.MAX).getValue()
147
if
not
np.isfinite(vmax):
148
continue
149
if
"psf_max_value"
in
star.schema:
150
star[
"psf_max_value"
] = vmax
151
psfCandidateList.append(psfCandidate)
152
goodStarCat.append(star)
153
154
return
pipeBase.Struct(
155
psfCandidates=psfCandidateList,
156
goodStarCat=goodStarCat,
157
)
lsst::afw::table::SortedCatalogT< SourceRecord >
lsst::meas::algorithms.makePsfCandidates.MakePsfCandidatesConfig
Definition
makePsfCandidates.py:35
lsst::meas::algorithms.makePsfCandidates.MakePsfCandidatesTask
Definition
makePsfCandidates.py:47
lsst::meas::algorithms.makePsfCandidates.MakePsfCandidatesTask.run
run(self, starCat, exposure, psfCandidateField=None)
Definition
makePsfCandidates.py:53
lsst::meas::algorithms.makePsfCandidates.MakePsfCandidatesTask.makePsfCandidates
makePsfCandidates(self, starCat, exposure)
Definition
makePsfCandidates.py:87
lsst::pex::exceptions::Exception
lsst::pex::exceptions::LengthError
lsst::afw::math
lsst::afw::table
lsst::meas::algorithms::makePsfCandidate
std::shared_ptr< PsfCandidate< PixelT > > makePsfCandidate(std::shared_ptr< afw::table::SourceRecord > const &source, std::shared_ptr< afw::image::Exposure< PixelT > > image)
Return a PsfCandidate of the right sort.
Definition
PsfCandidate.h:196
lsst::pex::config
lsst::pex::exceptions
lsst.pipe.base
Generated on
for lsst.meas.algorithms by
1.17.0