Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

# This file is part of afw. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

__all__ = ["MultibandExposure"] 

 

import numpy as np 

 

from lsst.geom import Point2D 

from . import Exposure, ExposureF 

from ..image.multiband import MultibandImage, MultibandTripleBase 

from ..image.multiband import tripleFromSingles, tripleFromArrays, makeTripleFromKwargs 

from ..maskedImage import MaskedImage 

 

 

class MultibandExposure(MultibandTripleBase): 

"""MultibandExposure class 

 

This class acts as a container for multiple `afw.Exposure` objects. 

All exposures must have the same bounding box, and the associated 

images must all have the same data type. 

 

See `MultibandTripleBase` for parameter definitions. 

""" 

def __init__(self, filters, image, mask, variance, psfs=None): 

super().__init__(filters, image, mask, variance) 

if psfs is not None: 

for psf, exposure in zip(psfs, self.singles): 

exposure.setPsf(psf) 

 

@staticmethod 

def fromExposures(filters, singles): 

"""Construct a MultibandImage from a collection of single band images 

 

see `tripleFromExposures` for a description of parameters 

""" 

psfs = [s.getPsf() for s in singles] 

return tripleFromSingles(MultibandExposure, filters, singles, psfs=psfs) 

 

@staticmethod 

def fromArrays(filters, image, mask, variance, bbox=None): 

"""Construct a MultibandExposure from a collection of arrays 

 

see `tripleFromArrays` for a description of parameters 

""" 

return tripleFromArrays(MultibandExposure, filters, image, mask, variance, bbox) 

 

@staticmethod 

def fromKwargs(filters, filterKwargs, singleType=ExposureF, **kwargs): 

"""Build a MultibandImage from a set of keyword arguments 

 

see `makeTripleFromKwargs` for a description of parameters 

""" 

return makeTripleFromKwargs(MultibandExposure, filters, filterKwargs, singleType, **kwargs) 

 

def _buildSingles(self, image=None, mask=None, variance=None): 

"""Make a new list of single band objects 

 

Parameters 

---------- 

image: `list` 

List of `Image` objects that represent the image in each band. 

mask: `list` 

List of `Mask` objects that represent the mask in each band. 

variance: `list` 

List of `Image` objects that represent the variance in each band. 

 

Returns 

------- 

singles: tuple 

Tuple of `MaskedImage` objects for each band, 

where the `image`, `mask`, and `variance` of each `single` 

point to the multiband objects. 

""" 

singles = [] 

if image is None: 

image = self.image 

if mask is None: 

mask = self.mask 

if variance is None: 

variance = self.variance 

 

dtype = image.array.dtype 

for f in self.filters: 

maskedImage = MaskedImage(image=image[f], mask=mask[f], variance=variance[f], dtype=dtype) 

single = Exposure(maskedImage, dtype=dtype) 

singles.append(single) 

return tuple(singles) 

 

@staticmethod 

def fromButler(butler, filters, filterKwargs, *args, **kwargs): 

"""Load a multiband exposure from a butler 

 

Because each band is stored in a separate exposure file, 

this method can be used to load all of the exposures for 

a given set of bands 

 

Parameters 

---------- 

butler: `Butler` 

Butler connection to use to load the single band 

calibrated images 

filters: `list` or `str` 

List of filter names for each band 

filterKwargs: `dict` 

Keyword arguments to pass to the Butler 

that are different for each filter. 

The keys are the names of the arguments and the values 

should also be dictionaries, with filter names as keys 

and the value of the argument for the given filter as values. 

args: `list` 

Arguments to the Butler. 

kwargs: `dict` 

Keyword arguments to pass to the Butler 

that are the same in all bands. 

 

Returns 

------- 

result: `MultibandExposure` 

The new `MultibandExposure` created by combining all of the 

single band exposures. 

""" 

# Load the Exposure in each band 

exposures = [] 

for f in filters: 

if filterKwargs is not None: 

for key, value in filterKwargs: 

kwargs[key] = value[f] 

exposures.append(butler.get(*args, filter=f, **kwargs)) 

return MultibandExposure.fromExposures(filters, exposures) 

 

def computePsfKernelImage(self, position=None): 

"""Get a multiband PSF image 

 

The PSF Kernel Image is computed for each band 

and combined into a (filter, y, x) array and stored 

as `self._psfImage`. 

The result is not cached, so if the same PSF is expected 

to be used multiple times it is a good idea to store the 

result in another variable. 

 

Parameters 

---------- 

position: `Point2D` or `tuple` 

Coordinates to evaluate the PSF. If `position` is `None` 

then `Psf.getAveragePosition()` is used. 

 

Returns 

------- 

self._psfImage: array 

The multiband PSF image. 

""" 

psfs = [] 

# Make the coordinates into a Point2D (if necessary) 

if not isinstance(position, Point2D) and position is not None: 

position = Point2D(position[0], position[1]) 

for single in self.singles: 

if position is None: 

psfs.append(single.getPsf().computeKernelImage().array) 

else: 

psfs.append(single.getPsf().computeKernelImage(position).array) 

psfs = np.array(psfs) 

psfImage = MultibandImage(self.filters, array=psfs) 

return psfImage 

 

def computePsfImage(self, position=None): 

"""Get a multiband PSF image 

 

The PSF Kernel Image is computed for each band 

and combined into a (filter, y, x) array and stored 

as `self._psfImage`. 

The result is not cached, so if the same PSF is expected 

to be used multiple times it is a good idea to store the 

result in another variable. 

 

Parameters 

---------- 

position: `Point2D` or `tuple` 

Coordinates to evaluate the PSF. If `position` is `None` 

then `Psf.getAveragePosition()` is used. 

 

Returns 

------- 

self._psfImage: array 

The multiband PSF image. 

""" 

psfs = [] 

# Make the coordinates into a Point2D (if necessary) 

if not isinstance(position, Point2D) and position is not None: 

position = Point2D(position[0], position[1]) 

for single in self.singles: 

if position is None: 

psfs.append(single.getPsf().computeImage().array) 

else: 

psfs.append(single.getPsf().computeImage(position).array) 

psfs = np.array(psfs) 

psfImage = MultibandImage(self.filters, array=psfs) 

return psfImage