LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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 
22 import pickle
23 import numpy as np
24 from lsst.afw.typehandling import StorableHelperFactory
25 from lsst.meas.algorithms import ImagePsf
26 from lsst.afw.image import Image
27 from 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 
85  def getAveragePosition(self):
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:211
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.