Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+83433b07ee,g16d25e1f1b+23bc9e47ac,g1ec0fe41b4+3ea9d11450,g1fd858c14a+9be2b0f3b9,g2440f9efcc+8c5ae1fdc5,g35bb328faa+8c5ae1fdc5,g4a4af6cd76+d25431c27e,g4d2262a081+c74e83464e,g53246c7159+8c5ae1fdc5,g55585698de+1e04e59700,g56a49b3a55+92a7603e7a,g60b5630c4e+1e04e59700,g67b6fd64d1+3fc8cb0b9e,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g8352419a5c+8c5ae1fdc5,g8852436030+60e38ee5ff,g89139ef638+3fc8cb0b9e,g94187f82dc+1e04e59700,g989de1cb63+3fc8cb0b9e,g9d31334357+1e04e59700,g9f33ca652e+0a83e03614,gabe3b4be73+8856018cbb,gabf8522325+977d9fabaf,gb1101e3267+8b4b9c8ed7,gb89ab40317+3fc8cb0b9e,gc0af124501+57ccba3ad1,gcf25f946ba+60e38ee5ff,gd6cbbdb0b4+1cc2750d2e,gd794735e4e+7be992507c,gdb1c4ca869+be65c9c1d7,gde0f65d7ad+c7f52e58fe,ge278dab8ac+6b863515ed,ge410e46f29+3fc8cb0b9e,gf35d7ec915+97dd712d81,gf5e32f922b+8c5ae1fdc5,gf618743f1b+747388abfa,gf67bdafdda+3fc8cb0b9e,w.2025.18
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
piffPsf.py
Go to the documentation of this file.
1# This file is part of meas_extensions_piff.
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__ = ["PiffPsf"]
23
24import pickle
25import piff
26from packaging.version import Version
27import numpy as np
28from lsst.afw.typehandling import StorableHelperFactory
29from lsst.meas.algorithms import ImagePsf
30from lsst.afw.image import Image
31from lsst.geom import Box2I, Point2I, Extent2I, Point2D
32
33
35 _factory = StorableHelperFactory(
36 "lsst.meas.extensions.piff.piffPsf",
37 "PiffPsf"
38 )
39
40 def __init__(self, width, height, piffResult):
41 assert width == height
42 ImagePsf.__init__(self)
43 self.width = width
44 self.height = height
45 self.dimensions = Extent2I(width, height)
46 self._piffResult = piffResult
47 self._averagePosition = None
48
49 @property
50 def piffResult(self):
51 return self._piffResult
52
53 # Storable overrides
54
55 def isPersistable(self):
56 return True
57
59 return "PiffPsf"
60
62 return "lsst.meas.extensions.piff.piffPsf"
63
64 def _write(self):
65 return pickle.dumps((self.width, self.height, self._piffResult))
66
67 @staticmethod
68 def _read(pkl):
69 width, height, piffResult = pickle.loads(pkl)
70 # We need to do surgery on pickles created with earlier versions of
71 # piff when using piff version 1.4 or later.
72 if Version(piff.version) >= Version("1.4"):
73 if not hasattr(piffResult, "_num"):
74 piffResult._num = None
75 piffResult.model._num = None
76 piffResult.model._fit_flux = None
77 piffResult.interp._num = None
78 return PiffPsf(width, height, piffResult)
79
80 # ImagePsf overrides
81
82 def __deepcopy__(self, meta=None):
83 return PiffPsf(self.width, self.height, self._piffResult)
84
85 def resized(self, width, height):
86 assert width == height
87 return PiffPsf(width, height, self._piffResult)
88
89 def _doComputeImage(self, position, color):
90 return self._doImage(position, center=None)
91
92 def _doComputeKernelImage(self, position, color):
93 return self._doImage(position, center=True)
94
95 def _doComputeBBox(self, position, color):
96 return self._doBBox(Point2I(0, 0), center=True)
97
99 if self._averagePosition is None:
100 x = np.mean([s.image_pos.x for s in self._piffResult.stars
101 if not s.is_flagged and not s.is_reserve])
102 y = np.mean([s.image_pos.y for s in self._piffResult.stars
103 if not s.is_flagged and not s.is_reserve])
104 self._averagePosition = Point2D(x, y)
105 return self._averagePosition
106
107 # Internal private methods
108
109 def _doImage(self, position, center):
110 # Follow Piff conventions for center.
111 # None => draw as if star at position
112 # True => draw in center of image
113 gsimg = self._piffResult.draw(
114 position.x, position.y, stamp_size=self.width, center=center
115 )
116 bbox = self._doBBox(position, center)
117 img = Image(bbox, dtype=np.float64)
118 img.array[:] = gsimg.array
119 img.array /= np.sum(img.array)
120 return img
121
122 def _doBBox(self, position, center):
123 origin = -(self.dimensions//2)
124 if center is None:
125 origin = Point2I(position) + origin
126 return Box2I(Point2I(origin), self.dimensions)
virtual lsst::geom::Point2D getAveragePosition() const
Return the average position of the stars used to construct the Psf.
Definition Psf.cc:189
A class to represent a 2-dimensional array of pixels.
Definition Image.h:51
virtual bool isPersistable() const noexcept
Return true if this particular object can be persisted using afw::table::io.
An integer coordinate rectangle.
Definition Box.h:55
An intermediate base class for Psfs that use an image representation.
Definition ImagePsf.h:40
_doComputeKernelImage(self, position, color)
Definition piffPsf.py:92
__init__(self, width, height, piffResult)
Definition piffPsf.py:40
_doComputeBBox(self, position, color)
Definition piffPsf.py:95
_doComputeImage(self, position, color)
Definition piffPsf.py:89