25 __all__ = [
'AccumulatorMeanStack']
29 """Stack masked images.
34 Shape of the input and output images.
35 bit_mask_value : `int`
36 Bit mask to flag for "bad" inputs that should not be stacked.
37 mask_threshold_dict : `dict` [`int`: `float`], optional
38 Dictionary of mapping from bit number to threshold for flagging.
39 Only bad bits (in bit_mask_value) which mask fractional weight
40 greater than this threshold will be flagged in the output image.
41 mask_map : `list` [`tuple`], optional
42 Mapping from input image bits to aggregated coadd bits.
43 no_good_pixels_mask : `int`, optional
44 Bit mask to set when there are no good pixels in the stack.
45 If not set then will set coadd masked image 'NO_DATA' bit.
46 calc_error_from_input_variance : `bool`, optional
47 Calculate the error from the input variance?
48 compute_n_image : `bool`, optional
49 Calculate the n_image map as well as stack?
52 bit_mask_value, mask_threshold_dict={},
53 mask_map=[], no_good_pixels_mask=None,
54 calc_error_from_input_variance=True,
55 compute_n_image=False):
65 for bit
in mask_threshold_dict:
70 self.
sum_weightsum_weight = np.zeros(shape, dtype=np.float64)
72 self.
sum_wdatasum_wdata = np.zeros(shape, dtype=np.float64)
74 if calc_error_from_input_variance:
76 self.
sum_w2varsum_w2var = np.zeros(shape, dtype=np.float64)
79 self.
sum_weight2sum_weight2 = np.zeros(shape, dtype=np.float64)
81 self.
sum_wdata2sum_wdata2 = np.zeros(shape, dtype=np.float64)
83 self.
or_maskor_mask = np.zeros(shape, dtype=np.int64)
91 self.
n_imagen_image = np.zeros(shape, dtype=np.int32)
94 """Add a masked image to the stack.
98 masked_image : `lsst.afw.image.MaskedImage`
99 Masked image to add to the stack.
100 weight : `float` or `np.ndarray`, optional
101 Weight to apply for weighted mean. If an array,
102 must be same size and shape as input masked_image.
104 good_pixels = np.where(((masked_image.mask.array & self.
bit_mask_valuebit_mask_value) == 0)
105 & np.isfinite(masked_image.mask.array))
107 self.
sum_weightsum_weight[good_pixels] += weight
108 self.
sum_wdatasum_wdata[good_pixels] += weight*masked_image.image.array[good_pixels]
111 self.
n_imagen_image[good_pixels] += 1
114 self.
sum_w2varsum_w2var[good_pixels] += (weight**2.)*masked_image.variance.array[good_pixels]
116 self.
sum_weight2sum_weight2[good_pixels] += weight**2.
117 self.
sum_wdata2sum_wdata2[good_pixels] += weight*(masked_image.image.array[good_pixels]**2.)
120 self.
or_maskor_mask[good_pixels] |= masked_image.mask.array[good_pixels]
124 bad_pixels = ((masked_image.mask.array & 2**bit) > 0)
129 """Fill the stacked mask image after accumulation.
133 stacked_masked_image : `lsst.afw.image.MaskedImage`
136 with np.warnings.catch_warnings():
138 np.warnings.simplefilter(
"ignore")
147 variance = self.
sum_wdata2sum_wdata2/self.
sum_weightsum_weight - stacked_masked_image.image.array[:, :]**2.
154 stacked_masked_image.variance.array[:, :] = mean_var
161 self.
or_maskor_mask[propagate] |= 2**bit
165 for mask_tuple
in self.
mask_mapmask_map:
168 stacked_masked_image.mask.array[:, :] = self.
or_maskor_mask
171 mask_dict = stacked_masked_image.mask.getMaskPlaneDict()
172 no_good_pixels_mask = 2**(mask_dict[
'NO_DATA'])
176 bad_pixels = (self.
sum_weightsum_weight <= 0.0)
177 stacked_masked_image.mask.array[bad_pixels] |= no_good_pixels_mask
180 """Add an image to the stack.
182 No bit-filtering is performed when adding an image.
186 image : `lsst.afw.image.Image`
187 Image to add to the stack.
188 weight : `float` or `np.ndarray`, optional
189 Weight to apply for weighted mean. If an array,
190 must be same size and shape as input image.
193 self.
sum_wdatasum_wdata[:, :] += weight*image.array[:]
199 """Fill the image after accumulation.
203 stacked_image : `lsst.afw.image.Image`
206 with np.warnings.catch_warnings():
209 np.warnings.simplefilter(
"ignore")
216 """Convert stats control to threshold dict.
220 stats_ctrl : `lsst.afw.math.StatisticsControl`
224 threshold_dict : `dict`
225 Dict mapping from bit to propagation threshold.
228 for bit
in range(64):
229 threshold_dict[bit] = stats_ctrl.getMaskPropagationThreshold(bit)
231 return threshold_dict
def __init__(self, shape, bit_mask_value, mask_threshold_dict={}, mask_map=[], no_good_pixels_mask=None, calc_error_from_input_variance=True, compute_n_image=False)
def fill_stacked_image(self, stacked_image)
calc_error_from_input_variance
def add_masked_image(self, masked_image, weight=1.0)
def stats_ctrl_to_threshold_dict(stats_ctrl)
def add_image(self, image, weight=1.0)
def fill_stacked_masked_image(self, stacked_masked_image)