LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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
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 
44  @property
45  def piffResult(self):
46  return self._piffResult_piffResult
47 
48  # Storable overrides
49 
50  def isPersistable(self):
51  return True
52 
53  def _getPersistenceName(self):
54  return "PiffPsf"
55 
56  def _getPythonModule(self):
57  return "lsst.meas.extensions.piff.piffPsf"
58 
59  def _write(self):
60  return pickle.dumps((self.widthwidth, self.heightheight, self._piffResult_piffResult))
61 
62  @staticmethod
63  def _read(pkl):
64  return PiffPsf(*pickle.loads(pkl))
65 
66  # ImagePsf overrides
67 
68  def __deepcopy__(self, meta=None):
69  return PiffPsf(self.widthwidth, self.heightheight, self._piffResult_piffResult)
70 
71  def resized(self, width, height):
72  assert width == height
73  return PiffPsf(width, height, self._piffResult_piffResult)
74 
75  def _doComputeImage(self, position, color):
76  return self._doImage_doImage(position, center=None)
77 
78  def _doComputeKernelImage(self, position, color):
79  return self._doImage_doImage(position, center=True)
80 
81  def _doComputeBBox(self, position, color):
82  return self._doBBox_doBBox(Point2I(0, 0), center=True)
83 
84  # Internal private methods
85 
86  def _doImage(self, position, center):
87  # Follow Piff conventions for center.
88  # None => draw as if star at position
89  # True => draw in center of image
90  gsimg = self._piffResult_piffResult.draw(
91  position.x, position.y, stamp_size=self.widthwidth, center=center
92  )
93  bbox = self._doBBox_doBBox(position, center)
94  img = Image(bbox, dtype=np.float64)
95  img.array[:] = gsimg.array
96  img.array /= np.sum(img.array)
97  return img
98 
99  def _doBBox(self, position, center):
100  origin = -(self.dimensionsdimensions//2)
101  if center is None:
102  origin = Point2I(position) + origin
103  return Box2I(Point2I(origin), self.dimensionsdimensions)
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:86
def _doBBox(self, position, center)
Definition: piffPsf.py:99
def resized(self, width, height)
Definition: piffPsf.py:71
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
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.