Coverage for python / lsst / afw / image / _photoCalibContinued.py: 37%
35 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-14 00:45 -0700
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-14 00:45 -0700
1# This file is part of afw.
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/>.
22__all__ = ["PhotoCalib"]
24import enum
25import warnings
27import numpy as np
28from astropy import units
30from lsst.utils import continueClass
32from ._imageLib import PhotoCalib
35class _UnsetEnum(enum.Enum):
36 UNSET = enum.auto()
39@continueClass
40class PhotoCalib: # noqa: F811
41 def getLocalCalibrationArray(self, x, y):
42 """Get the local calibration values (nJy/counts) for numpy arrays (pixels).
44 Parameters
45 ----------
46 x : `np.ndarray` (N,)
47 Array of x values (pixels).
48 y : `np.ndarray` (N,)
49 Array of y values (pixels).
51 Returns
52 -------
53 localCalibration : `np.ndarray` (N,)
54 Array of local calibration values (nJy/counts).
55 """
56 if self._isConstant:
57 return np.full(len(x), self.getCalibrationMean())
58 else:
59 bf = self.computeScaledCalibration()
60 return self.getCalibrationMean()*bf.evaluate(x, y)
62 def instFluxToMagnitudeArray(self, instFluxes, x, y):
63 """Convert instFlux (counts) to magnitudes for numpy arrays (pixels).
65 Parameters
66 ----------
67 instFluxes : `np.ndarray` (N,)
68 Array of instFluxes to convert (counts).
69 x : `np.ndarray` (N,)
70 Array of x values (pixels).
71 y : `np.ndarray` (N,)
72 Array of y values (pixels).
74 Returns
75 -------
76 magnitudes : `astropy.units.Magnitude` (N,)
77 Array of AB magnitudes.
78 """
79 scale = self.getLocalCalibrationArray(x, y)
80 nanoJansky = (instFluxes*scale)*units.nJy
82 return nanoJansky.to(units.ABmag)
84 def magnitudeToInstFluxArray(self, magnitudes, x, y):
85 """Convert magnitudes to instFlux (counts) for numpy arrays (pixels).
87 Parameters
88 ----------
89 magnitudes : `np.ndarray` or `astropy.units.Magnitude` (N,)
90 Array of AB magnitudes.
91 x : `np.ndarray` (N,)
92 Array of x values (pixels).
93 y : `np.ndarray` (N,)
94 Array of y values (pixels).
96 Returns
97 -------
98 instFluxes : `np.ndarray` (N,)
99 Array of instFluxes (counts).
100 """
101 scale = self.getLocalCalibrationArray(x, y)
103 if not isinstance(magnitudes, units.Magnitude):
104 _magnitudes = magnitudes*units.ABmag
105 else:
106 _magnitudes = magnitudes
108 nanoJansky = _magnitudes.to(units.nJy).value
110 return nanoJansky/scale
112 # TODO[DM-49400]: remove this method and rename the pybind11 method to drop
113 # the leading underscore.
114 def calibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET):
115 """Return a flux calibrated image, with pixel values in nJy.
117 Mask pixels are propagated directly from the input image.
119 Parameters
120 ----------
121 maskedImage : `lsst.afw.image.MaskedImage`
122 The masked image to calibrate.
123 includeScaleUncertainty : `bool`, optional
124 Deprecated and ignored; will be removed after v29.
126 Returns
127 ------
128 calibrated : `lsst.afw.image.MaskedImage`
129 The calibrated masked image.
130 """
131 if includeScaleUncertainty is not _UnsetEnum.UNSET:
132 warnings.warn(
133 "The 'includeScaleUncertainty' argument to calibrateImage is deprecated and does "
134 "nothing. It will be removed after v29.",
135 category=FutureWarning
136 )
137 return self._calibrateImage(maskedImage)
139 # TODO[DM-49400]: remove this method and rename the pybind11 method to drop
140 # the leading underscore.
141 def uncalibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET):
142 """Return a un-calibrated image, with pixel values in ADU (or whatever
143 the original input to this photoCalib was).
145 Mask pixels are propagated directly from the input image.
147 Parameters
148 ----------
149 maskedImage : `lsst.afw.image.MaskedImage`
150 The masked image with pixel units of nJy to uncalibrate.
151 includeScaleUncertainty : `bool`, optional
152 Deprecated and ignored; will be removed after v29.
154 Returns
155 uncalibrated : `lsst.afw.image.MaskedImage`
156 The uncalibrated masked image.
157 """
158 if includeScaleUncertainty is not _UnsetEnum.UNSET:
159 warnings.warn(
160 "The 'includeScaleUncertainty' argument to uncalibrateImage is deprecated and does "
161 "nothing. It will be removed after v29.",
162 category=FutureWarning
163 )
164 return self._uncalibrateImage(maskedImage)