Skip to content

Commit a2bc5ad

Browse files
authored
Merge pull request #773 from lsst/tickets/DM-36099
Change 'filters' to 'bands' for multiband images and exposures
2 parents 8ec4aff + c52281b commit a2bc5ad

File tree

5 files changed

+307
-296
lines changed

5 files changed

+307
-296
lines changed

python/lsst/afw/detection/multiband.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ class MultibandFootprint(MultibandBase):
8888
8989
Parameters
9090
----------
91-
filters : `list`
92-
List of filter names.
91+
bands : `list`
92+
List of band names.
9393
singles : `list`
9494
A list of single band `HeavyFootprint` objects.
9595
Each `HeavyFootprint` should have the same `PeakCatalog`
9696
and the same `SpanSet`, however to save CPU cycles there
9797
is no internal check for consistency of the peak catalog.
9898
"""
99-
def __init__(self, filters, singles):
100-
super().__init__(filters, singles)
99+
def __init__(self, bands, singles):
100+
super().__init__(bands, singles)
101101
# Ensure that all HeavyFootprints have the same SpanSet
102102
spans = singles[0].getSpans()
103103
if not all([heavy.getSpans() == spans for heavy in singles]):
@@ -109,13 +109,13 @@ def __init__(self, filters, singles):
109109
self._footprint = footprint
110110

111111
@staticmethod
112-
def fromArrays(filters, image, mask=None, variance=None, footprint=None, xy0=None, thresh=0, peaks=None):
112+
def fromArrays(bands, image, mask=None, variance=None, footprint=None, xy0=None, thresh=0, peaks=None):
113113
"""Create a `MultibandFootprint` from an `image`, `mask`, `variance`
114114
115115
Parameters
116116
----------
117-
filters : `list`
118-
List of filter names.
117+
bands : `list`
118+
List of band names.
119119
image: array
120120
An array to convert into `lsst.afw.detection.HeavyFootprint` objects.
121121
Only pixels above the `thresh` value for at least one band
@@ -155,18 +155,18 @@ def fromArrays(filters, image, mask=None, variance=None, footprint=None, xy0=Non
155155

156156
if peaks is not None:
157157
footprint.setPeakCatalog(peaks)
158-
mMaskedImage = MultibandMaskedImage.fromArrays(filters, image, mask, variance, imageBBox)
158+
mMaskedImage = MultibandMaskedImage.fromArrays(bands, image, mask, variance, imageBBox)
159159
singles = [makeHeavyFootprint(footprint, maskedImage) for maskedImage in mMaskedImage]
160-
return MultibandFootprint(filters, singles)
160+
return MultibandFootprint(bands, singles)
161161

162162
@staticmethod
163-
def fromImages(filters, image, mask=None, variance=None, footprint=None, thresh=0, peaks=None):
163+
def fromImages(bands, image, mask=None, variance=None, footprint=None, thresh=0, peaks=None):
164164
"""Create a `MultibandFootprint` from an `image`, `mask`, `variance`
165165
166166
Parameters
167167
----------
168-
filters : `list`
169-
List of filter names.
168+
bands : `list`
169+
List of band names.
170170
image : `lsst.afw.image.MultibandImage`, or list of `lsst.afw.image.Image`
171171
A `lsst.afw.image.MultibandImage` (or collection of images in each band)
172172
to convert into `HeavyFootprint` objects.
@@ -196,12 +196,12 @@ def fromImages(filters, image, mask=None, variance=None, footprint=None, thresh=
196196

197197
if peaks is not None:
198198
footprint.setPeakCatalog(peaks)
199-
mMaskedImage = MultibandMaskedImage(filters, image, mask, variance)
199+
mMaskedImage = MultibandMaskedImage(bands, image, mask, variance)
200200
singles = [makeHeavyFootprint(footprint, maskedImage) for maskedImage in mMaskedImage]
201-
return MultibandFootprint(filters, singles)
201+
return MultibandFootprint(bands, singles)
202202

203203
@staticmethod
204-
def fromMaskedImages(filters, maskedImages, footprint=None, thresh=0, peaks=None):
204+
def fromMaskedImages(bands, maskedImages, footprint=None, thresh=0, peaks=None):
205205
"""Create a `MultibandFootprint` from a list of `MaskedImage`
206206
207207
See `fromImages` for a description of the parameters not listed below
@@ -222,7 +222,7 @@ def fromMaskedImages(filters, maskedImages, footprint=None, thresh=0, peaks=None
222222
image = [maskedImage.image for maskedImage in maskedImages]
223223
mask = [maskedImage.mask for maskedImage in maskedImages]
224224
variance = [maskedImage.variance for maskedImage in maskedImages]
225-
return MultibandFootprint.fromImages(filters, image, mask, variance, footprint, thresh, peaks)
225+
return MultibandFootprint.fromImages(bands, image, mask, variance, footprint, thresh, peaks)
226226

227227
def getSpans(self):
228228
"""Get the full `SpanSet`"""
@@ -252,7 +252,7 @@ def peaks(self):
252252
"""`PeakCatalog` of the `MultibandFootprint`"""
253253
return self._footprint.getPeaks()
254254

255-
def _slice(self, filters, filterIndex, indices):
255+
def _slice(self, bands, bandIndex, indices):
256256
"""Slice the current object and return the result
257257
258258
`MultibandFootprint` objects cannot be sliced along the image
@@ -261,14 +261,14 @@ def _slice(self, filters, filterIndex, indices):
261261
See `Multiband._slice` for a list of the parameters.
262262
"""
263263
if len(indices) > 0:
264-
raise IndexError("MultibandFootprints can only be sliced in the filter dimension")
264+
raise IndexError("MultibandFootprints can only be sliced in the band dimension")
265265

266-
if isinstance(filterIndex, slice):
267-
singles = self.singles[filterIndex]
266+
if isinstance(bandIndex, slice):
267+
singles = self.singles[bandIndex]
268268
else:
269-
singles = [self.singles[idx] for idx in filterIndex]
269+
singles = [self.singles[idx] for idx in bandIndex]
270270

271-
return MultibandFootprint(filters, singles)
271+
return MultibandFootprint(bands, singles)
272272

273273
def getImage(self, bbox=None, fill=np.nan, imageType=MultibandMaskedImage):
274274
"""Convert a `MultibandFootprint` to a `MultibandImage`
@@ -306,7 +306,7 @@ def getImage(self, bbox=None, fill=np.nan, imageType=MultibandMaskedImage):
306306
else:
307307
raise TypeError("Expected imageType to be either MultibandImage or MultibandMaskedImage")
308308
maskedImages = [heavy.extractImage(fill, bbox, singleType) for heavy in self.singles]
309-
mMaskedImage = imageType.fromImages(self.filters, maskedImages)
309+
mMaskedImage = imageType.fromImages(self.bands, maskedImages)
310310
return mMaskedImage
311311

312312
def clone(self, deep=True):
@@ -327,8 +327,8 @@ def clone(self, deep=True):
327327
for peak in self.footprint.getPeaks():
328328
footprint.addPeak(peak.getX(), peak.getY(), peak.getValue())
329329
mMaskedImage = self.getImage()
330-
filters = tuple([f for f in self.filters])
331-
result = MultibandFootprint.fromMaskedImages(filters, mMaskedImage, footprint)
330+
bands = tuple([f for f in self.bands])
331+
result = MultibandFootprint.fromMaskedImages(bands, mMaskedImage, footprint)
332332
else:
333-
result = MultibandFootprint(self.filters, self.singles)
333+
result = MultibandFootprint(self.bands, self.singles)
334334
return result

python/lsst/afw/image/_exposure/_multiband.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class IncompleteDataError(Exception):
5353
the PSF.
5454
"""
5555
def __init__(self, bands, position, partialPsf):
56-
missingBands = [band for band in bands if band not in partialPsf.filters]
56+
missingBands = [band for band in bands if band not in partialPsf.bands]
5757

5858
self.missingBands = missingBands
5959
self.position = position
@@ -66,7 +66,7 @@ def computePsfImage(psfModels, position, useKernelImage=True):
6666
"""Get a multiband PSF image
6767
6868
The PSF Image or PSF Kernel Image is computed for each band
69-
and combined into a (filter, y, x) array.
69+
and combined into a (band, y, x) array.
7070
7171
Parameters
7272
----------
@@ -125,36 +125,36 @@ class MultibandExposure(MultibandTripleBase):
125125
126126
See `MultibandTripleBase` for parameter definitions.
127127
"""
128-
def __init__(self, filters, image, mask, variance, psfs=None):
129-
super().__init__(filters, image, mask, variance)
128+
def __init__(self, bands, image, mask, variance, psfs=None):
129+
super().__init__(bands, image, mask, variance)
130130
if psfs is not None:
131131
for psf, exposure in zip(psfs, self.singles):
132132
exposure.setPsf(psf)
133133

134134
@staticmethod
135-
def fromExposures(filters, singles):
135+
def fromExposures(bands, singles):
136136
"""Construct a MultibandImage from a collection of single band images
137137
138138
see `tripleFromExposures` for a description of parameters
139139
"""
140140
psfs = [s.getPsf() for s in singles]
141-
return tripleFromSingles(MultibandExposure, filters, singles, psfs=psfs)
141+
return tripleFromSingles(MultibandExposure, bands, singles, psfs=psfs)
142142

143143
@staticmethod
144-
def fromArrays(filters, image, mask, variance, bbox=None):
144+
def fromArrays(bands, image, mask, variance, bbox=None):
145145
"""Construct a MultibandExposure from a collection of arrays
146146
147147
see `tripleFromArrays` for a description of parameters
148148
"""
149-
return tripleFromArrays(MultibandExposure, filters, image, mask, variance, bbox)
149+
return tripleFromArrays(MultibandExposure, bands, image, mask, variance, bbox)
150150

151151
@staticmethod
152-
def fromKwargs(filters, filterKwargs, singleType=ExposureF, **kwargs):
152+
def fromKwargs(bands, bandKwargs, singleType=ExposureF, **kwargs):
153153
"""Build a MultibandImage from a set of keyword arguments
154154
155155
see `makeTripleFromKwargs` for a description of parameters
156156
"""
157-
return makeTripleFromKwargs(MultibandExposure, filters, filterKwargs, singleType, **kwargs)
157+
return makeTripleFromKwargs(MultibandExposure, bands, bandKwargs, singleType, **kwargs)
158158

159159
def _buildSingles(self, image=None, mask=None, variance=None):
160160
"""Make a new list of single band objects
@@ -184,7 +184,7 @@ def _buildSingles(self, image=None, mask=None, variance=None):
184184
variance = self.variance
185185

186186
dtype = image.array.dtype
187-
for f in self.filters:
187+
for f in self.bands:
188188
maskedImage = MaskedImage(image=image[f], mask=mask[f], variance=variance[f], dtype=dtype)
189189
single = Exposure(maskedImage, dtype=dtype)
190190
singles.append(single)
@@ -227,7 +227,7 @@ def computePsfKernelImage(self, position):
227227
"""Get a multiband PSF image
228228
229229
The PSF Kernel Image is computed for each band
230-
and combined into a (filter, y, x) array and stored
230+
and combined into a (band, y, x) array and stored
231231
as `self._psfImage`.
232232
The result is not cached, so if the same PSF is expected
233233
to be used multiple times it is a good idea to store the
@@ -253,7 +253,7 @@ def computePsfImage(self, position=None):
253253
"""Get a multiband PSF image
254254
255255
The PSF Kernel Image is computed for each band
256-
and combined into a (filter, y, x) array and stored
256+
and combined into a (band, y, x) array and stored
257257
as `self._psfImage`.
258258
The result is not cached, so if the same PSF is expected
259259
to be used multiple times it is a good idea to store the
@@ -284,22 +284,22 @@ def getPsfs(self):
284284
psfs : `dict` of `lsst.afw.detection.Psf`
285285
The PSF in each band
286286
"""
287-
return {band: self[band].getPsf() for band in self.filters}
287+
return {band: self[band].getPsf() for band in self.bands}
288288

289-
def _slice(self, filters, filterIndex, indices):
289+
def _slice(self, bands, bandIndex, indices):
290290
"""Slice the current object and return the result
291291
292292
See `Multiband._slice` for a list of the parameters.
293293
This overwrites the base method to attach the PSF to
294294
each individual exposure.
295295
"""
296-
image = self.image._slice(filters, filterIndex, indices)
296+
image = self.image._slice(bands, bandIndex, indices)
297297
if self.mask is not None:
298-
mask = self._mask._slice(filters, filterIndex, indices)
298+
mask = self._mask._slice(bands, bandIndex, indices)
299299
else:
300300
mask = None
301301
if self.variance is not None:
302-
variance = self._variance._slice(filters, filterIndex, indices)
302+
variance = self._variance._slice(bands, bandIndex, indices)
303303
else:
304304
variance = None
305305

@@ -312,10 +312,10 @@ def _slice(self, filters, filterIndex, indices):
312312
return (image, mask, variance)
313313

314314
_psfs = self.getPsfs()
315-
psfs = [_psfs[band] for band in filters]
315+
psfs = [_psfs[band] for band in bands]
316316

317317
result = MultibandExposure(
318-
filters=filters,
318+
bands=bands,
319319
image=image,
320320
mask=mask,
321321
variance=variance,

0 commit comments

Comments
 (0)