lsst.afw
g3a5ebb7d8a+28b83bf6a5
Toggle main menu visibility
Loading...
Searching...
No Matches
python
lsst
afw
image
_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
24
import
enum
25
import
warnings
26
27
import
numpy
as
np
28
from
astropy
import
units
29
30
from
lsst.utils
import
continueClass
31
32
from
._imageLib
import
PhotoCalib
33
34
35
class
_UnsetEnum
(enum.Enum):
36
UNSET = enum.auto()
37
38
39
@continueClass
40
class
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 v29.
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 v29."
,
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 v29.
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 v29."
,
162
category=FutureWarning
163
)
164
return
self._uncalibrateImage(maskedImage)
lsst::afw::image._photoCalibContinued._UnsetEnum
Definition
_photoCalibContinued.py:35
lsst::afw::image._photoCalibContinued.PhotoCalib
Definition
_photoCalibContinued.py:40
lsst::afw::image._photoCalibContinued.PhotoCalib.uncalibrateImage
uncalibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET)
Definition
_photoCalibContinued.py:141
lsst::afw::image._photoCalibContinued.PhotoCalib._isConstant
_isConstant
Definition
_photoCalibContinued.py:56
lsst::afw::image._photoCalibContinued.PhotoCalib.instFluxToMagnitudeArray
instFluxToMagnitudeArray(self, instFluxes, x, y)
Definition
_photoCalibContinued.py:62
lsst::afw::image._photoCalibContinued.PhotoCalib.getLocalCalibrationArray
getLocalCalibrationArray(self, x, y)
Definition
_photoCalibContinued.py:41
lsst::afw::image._photoCalibContinued.PhotoCalib.magnitudeToInstFluxArray
magnitudeToInstFluxArray(self, magnitudes, x, y)
Definition
_photoCalibContinued.py:84
lsst::afw::image._photoCalibContinued.PhotoCalib.calibrateImage
calibrateImage(self, maskedImage, includeScaleUncertainty=_UnsetEnum.UNSET)
Definition
_photoCalibContinued.py:114
lsst.utils
Generated on
for lsst.afw by
1.17.0