Loading [MathJax]/extensions/tex2jax.js
LSST Applications g04a91732dc+7fec47d7bc,g07dc498a13+5ab4d22ec3,g0fba68d861+565de8e5d5,g1409bbee79+5ab4d22ec3,g1a7e361dbc+5ab4d22ec3,g1fd858c14a+11200c7927,g20f46db602+25d63fd678,g35bb328faa+fcb1d3bbc8,g4d2262a081+61302e889d,g4d39ba7253+d05e267ece,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g60b5630c4e+d05e267ece,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8048e755c2+a1301e4c20,g8852436030+163ceb82d8,g89139ef638+5ab4d22ec3,g89e1512fd8+fbb808ebce,g8d6b6b353c+d05e267ece,g9125e01d80+fcb1d3bbc8,g989de1cb63+5ab4d22ec3,g9f33ca652e+8abe617c77,ga9baa6287d+d05e267ece,gaaedd4e678+5ab4d22ec3,gabe3b4be73+1e0a283bba,gb1101e3267+fefe9ce5b1,gb58c049af0+f03b321e39,gb90eeb9370+824c420ec4,gc741bbaa4f+77ddc33078,gcf25f946ba+163ceb82d8,gd315a588df+0f88d5218e,gd6cbbdb0b4+c8606af20c,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+e6bd566e97,ge278dab8ac+932305ba37,ge82c20c137+76d20ab76d,w.2025.10
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
_photoCalibContinued.py
Go to the documentation of this file.
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/>.
21
22__all__ = ["PhotoCalib"]
23
24import enum
25import warnings
26
27import numpy as np
28from astropy import units
29
30from lsst.utils import continueClass
31
32from ._imageLib import PhotoCalib
33
34
35class _UnsetEnum(enum.Enum):
36 UNSET = enum.auto()
37
38
39@continueClass
40class PhotoCalib: # noqa: F811
41 def getLocalCalibrationArray(self, x, y):
42 """Get the local calibration values (nJy/counts) for numpy arrays (pixels).
43
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).
50
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)
61
62 def instFluxToMagnitudeArray(self, instFluxes, x, y):
63 """Convert instFlux (counts) to magnitudes for numpy arrays (pixels).
64
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).
73
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
81
82 return nanoJansky.to(units.ABmag)
83
84 def magnitudeToInstFluxArray(self, magnitudes, x, y):
85 """Convert magnitudes to instFlux (counts) for numpy arrays (pixels).
86
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).
95
96 Returns
97 -------
98 instFluxes : `np.ndarray` (N,)
99 Array of instFluxes (counts).
100 """
101 scale = self.getLocalCalibrationArray(x, y)
102
103 if not isinstance(magnitudes, units.Magnitude):
104 _magnitudes = magnitudes*units.ABmag
105 else:
106 _magnitudes = magnitudes
107
108 nanoJansky = _magnitudes.to(units.nJy).value
109
110 return nanoJansky/scale
111
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.
116
117 Mask pixels are propagated directly from the input image.
118
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 v30.
125
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 v30.",
135 category=FutureWarning
136 )
137 return self._calibrateImage(maskedImage)
138
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).
144
145 Mask pixels are propagated directly from the input image.
146
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 v30.
153
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 v30.",
162 category=FutureWarning
163 )
164 return self._uncalibrateImage(maskedImage)
uncalibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET)
calibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET)