LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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
22import pickle
23import numpy as np
24from lsst.afw.typehandling import StorableHelperFactory
25from lsst.meas.algorithms import ImagePsf
26from lsst.afw.image import Image
27from lsst.geom import Box2I, Point2I, Extent2I, Point2D
28
29
31 _factory = StorableHelperFactory(
32 "lsst.meas.extensions.piff.piffPsf",
33 "PiffPsf"
34 )
35
36 def __init__(self, width, height, piffResult):
37 assert width == height
38 ImagePsf.__init__(self)
39 self.widthwidth = width
40 self.heightheight = height
41 self.dimensionsdimensions = Extent2I(width, height)
42 self._piffResult_piffResult = piffResult
43 self._averagePosition_averagePosition = None
44
45 @property
46 def piffResult(self):
47 return self._piffResult_piffResult
48
49 # Storable overrides
50
51 def isPersistable(self):
52 return True
53
54 def _getPersistenceName(self):
55 return "PiffPsf"
56
57 def _getPythonModule(self):
58 return "lsst.meas.extensions.piff.piffPsf"
59
60 def _write(self):
61 return pickle.dumps((self.widthwidth, self.heightheight, self._piffResult_piffResult))
62
63 @staticmethod
64 def _read(pkl):
65 return PiffPsf(*pickle.loads(pkl))
66
67 # ImagePsf overrides
68
69 def __deepcopy__(self, meta=None):
70 return PiffPsf(self.widthwidth, self.heightheight, self._piffResult_piffResult)
71
72 def resized(self, width, height):
73 assert width == height
74 return PiffPsf(width, height, self._piffResult_piffResult)
75
76 def _doComputeImage(self, position, color):
77 return self._doImage_doImage(position, center=None)
78
79 def _doComputeKernelImage(self, position, color):
80 return self._doImage_doImage(position, center=True)
81
82 def _doComputeBBox(self, position, color):
83 return self._doBBox_doBBox(Point2I(0, 0), center=True)
84
86 if self._averagePosition_averagePosition is None:
87 x = np.mean([star.field_pos.x for star in self._piffResult_piffResult.stars])
88 y = np.mean([star.field_pos.y for star in self._piffResult_piffResult.stars])
89 self._averagePosition_averagePosition = Point2D(x, y)
90 return self._averagePosition_averagePosition
91
92 # Internal private methods
93
94 def _doImage(self, position, center):
95 # Follow Piff conventions for center.
96 # None => draw as if star at position
97 # True => draw in center of image
98 gsimg = self._piffResult_piffResult.draw(
99 position.x, position.y, stamp_size=self.widthwidth, center=center
100 )
101 bbox = self._doBBox_doBBox(position, center)
102 img = Image(bbox, dtype=np.float64)
103 img.array[:] = gsimg.array
104 img.array /= np.sum(img.array)
105 return img
106
107 def _doBBox(self, position, center):
108 origin = -(self.dimensionsdimensions//2)
109 if center is None:
110 origin = Point2I(position) + origin
111 return Box2I(Point2I(origin), self.dimensionsdimensions)
virtual lsst::geom::Point2D getAveragePosition() const
Return the average position of the stars used to construct the Psf.
Definition: Psf.cc:221
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.
Definition: Persistable.h:102
An integer coordinate rectangle.
Definition: Box.h:55
An intermediate base class for Psfs that use an image representation.
Definition: ImagePsf.h:40
def __init__(self, width, height, piffResult)
Definition: piffPsf.py:36
def _doImage(self, position, center)
Definition: piffPsf.py:94
def _doBBox(self, position, center)
Definition: piffPsf.py:107
def resized(self, width, height)
Definition: piffPsf.py:72
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Point< double, 2 > Point2D
Definition: Point.h:324
Extent< int, 2 > Extent2I
Definition: Extent.h:397
Point< int, 2 > Point2I
Definition: Point.h:321
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.