lsst.ip.isr
g77367d4607+e2f0a7808d
Toggle main menu visibility
Loading...
Searching...
No Matches
python
lsst
ip
isr
gainCorrection.py
Go to the documentation of this file.
1
# This file is part of ip_isr.
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
Gain correction storage class.
23
"""
24
25
__all__ = [
"GainCorrection"
]
26
27
from
astropy.table
import
Table
28
import
numpy
as
np
29
30
from
lsst.ip.isr
import
IsrCalib
31
32
33
class
GainCorrection
(
IsrCalib
):
34
"""Gain correction parameters.
35
36
Parameters
37
----------
38
ampNames : `list` [`str`]
39
List of amplifier names.
40
gainAdjustments : `list` [`float`]
41
List of gain adjustment parameters.
42
**kwargs :
43
Additional parameters.
44
"""
45
46
_OBSTYPE =
"gainCorrection"
47
_SCHEMA =
"GainCorrection"
48
_VERSION = 1.0
49
50
def
__init__
(self, ampNames=[], gainAdjustments=[], **kwargs):
51
if
len(ampNames) != len(gainAdjustments):
52
raise
ValueError(
"Number of ampNames must be the same as number of gainAdjustments."
)
53
54
self.
ampNames
= ampNames
55
self.
gainAdjustments
= np.asarray(gainAdjustments)
56
57
super().
__init__
(**kwargs)
58
self.
requiredAttributes
.update([
"ampNames"
,
"gainAdjustments"
])
59
60
self.
updateMetadata
(setCalibInfo=
True
, setCalibId=
True
, **kwargs)
61
62
def
setParameters
(
63
self,
64
*,
65
ampNames=[],
66
gainAdjustments=[],
67
):
68
"""Set the parameters for the gain correction model.
69
70
Parameters
71
----------
72
ampNames : `list` [`str`]
73
List of amplifier names.
74
gainAdjustments : `list` [`float`]
75
List of gain adjustment parameters.
76
"""
77
if
len(ampNames) != len(gainAdjustments):
78
raise
ValueError(
"Number of ampNames must be the same as number of gainAdjustments."
)
79
80
self.
ampNames
= ampNames
81
self.
gainAdjustments
= gainAdjustments
82
83
@classmethod
84
def
fromDict
(cls, dictionary):
85
"""Construct a GainCorrection from a dictionary of properties.
86
87
Parameters
88
----------
89
dictionary : `dict`
90
Dictionary of properties.
91
92
Returns
93
-------
94
calib : `lsst.ip.isr.GainCorrection`
95
Constructed calibration.
96
"""
97
calib = cls()
98
99
calib.setMetadata(dictionary[
"metadata"
])
100
101
calib.ampNames = dictionary[
"ampNames"
]
102
calib.gainAdjustments = np.asarray(dictionary[
"gainAdjustments"
])
103
104
calib.updateMetadata()
105
return
calib
106
107
def
toDict
(self):
108
"""Return a dictionary containing the calibration properties.
109
110
Returns
111
-------
112
dictionary : `dict`
113
Dictionary of properties.
114
"""
115
self.
updateMetadata
()
116
117
outDict = dict()
118
metadata = self.
getMetadata
()
119
outDict[
"metadata"
] = metadata
120
121
outDict[
"ampNames"
] = self.
ampNames
122
outDict[
"gainAdjustments"
] = self.
gainAdjustments
.tolist()
123
124
return
outDict
125
126
@classmethod
127
def
fromTable
(cls, tableList):
128
"""Construct a calibration from a list of tables.
129
130
Parameters
131
----------
132
tableList : `list` [`astropy.table.Table`]
133
List of table(s) to use to construct the GainCorrection.
134
135
Returns
136
-------
137
calib : `lsst.ip.isr.GainCorrection`
138
The calibration defined in the table(s).
139
"""
140
gainCorrectionTable = tableList[0]
141
142
inDict = dict()
143
144
inDict[
"metadata"
] = gainCorrectionTable.meta
145
inDict[
"ampNames"
] = list(gainCorrectionTable[
"AMP_NAME"
])
146
inDict[
"gainAdjustments"
] = np.asarray(gainCorrectionTable[
"GAIN_ADJUSTMENT"
], dtype=np.float64)
147
148
return
cls().
fromDict
(inDict)
149
150
def
toTable
(self):
151
"""Construct a list of table(s) containing the GainCorrection data.
152
153
Returns
154
-------
155
tableList : `list` [`astropy.table.Table`]
156
List of tables containing the GainCorrection information.
157
"""
158
tableList = []
159
self.
updateMetadata
()
160
161
catalog = Table()
162
catalog[
"AMP_NAME"
] = self.
ampNames
163
catalog[
"GAIN_ADJUSTMENT"
] = self.
gainAdjustments
164
165
inMeta = self.
getMetadata
().
toDict
()
166
outMeta = {k: v
for
k, v
in
inMeta.items()
if
v
is
not
None
}
167
outMeta.update({k:
""
for
k, v
in
inMeta.items()
if
v
is
None
})
168
catalog.meta = outMeta
169
tableList.append(catalog)
170
171
return
tableList
172
173
def
correctGains
(self, gains, exposure=None):
174
"""Correct a dictionary of gains (in place).
175
176
Parameters
177
----------
178
gains : `dict` [`str`, `float`]
179
Array of gains to correct.
180
exposure : `lsst.afw.image.Exposure`, optional
181
Exposure with additional metadata for correction.
182
"""
183
for
i, ampName
in
enumerate(self.
ampNames
):
184
gains[ampName] *= self.
gainAdjustments
[i]
lsst::ip::isr.calibType.IsrCalib
Definition
calibType.py:41
lsst::ip::isr.calibType.IsrCalib.requiredAttributes
requiredAttributes
Definition
calibType.py:90
lsst::ip::isr.calibType.IsrCalib.updateMetadata
updateMetadata(self, camera=None, detector=None, filterName=None, setCalibId=False, setCalibInfo=False, setDate=False, **kwargs)
Definition
calibType.py:210
lsst::ip::isr.calibType.IsrCalib.getMetadata
getMetadata(self)
Definition
calibType.py:174
lsst::ip::isr.gainCorrection.GainCorrection
Definition
gainCorrection.py:33
lsst::ip::isr.gainCorrection.GainCorrection.toDict
toDict(self)
Definition
gainCorrection.py:107
lsst::ip::isr.gainCorrection.GainCorrection.setParameters
setParameters(self, *, ampNames=[], gainAdjustments=[])
Definition
gainCorrection.py:67
lsst::ip::isr.gainCorrection.GainCorrection.ampNames
ampNames
Definition
gainCorrection.py:54
lsst::ip::isr.gainCorrection.GainCorrection.gainAdjustments
gainAdjustments
Definition
gainCorrection.py:55
lsst::ip::isr.gainCorrection.GainCorrection.__init__
__init__(self, ampNames=[], gainAdjustments=[], **kwargs)
Definition
gainCorrection.py:50
lsst::ip::isr.gainCorrection.GainCorrection.toTable
toTable(self)
Definition
gainCorrection.py:150
lsst::ip::isr.gainCorrection.GainCorrection.fromTable
fromTable(cls, tableList)
Definition
gainCorrection.py:127
lsst::ip::isr.gainCorrection.GainCorrection.fromDict
fromDict(cls, dictionary)
Definition
gainCorrection.py:84
lsst::ip::isr.gainCorrection.GainCorrection.correctGains
correctGains(self, gains, exposure=None)
Definition
gainCorrection.py:173
lsst::ip::isr
Definition
applyLookupTable.h:34
Generated on
for lsst.ip.isr by
1.17.0