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.
101 good_pixels = np.where(((masked_image.mask.array & self.
bit_mask_valuebit_mask_value) == 0)
102 & np.isfinite(masked_image.mask.array))
104 self.
sum_weightsum_weight[good_pixels] += weight
105 self.
sum_wdatasum_wdata[good_pixels] += weight*masked_image.image.array[good_pixels]
108 self.
n_imagen_image[good_pixels] += 1
111 self.
sum_w2varsum_w2var[good_pixels] += (weight**2.)*masked_image.variance.array[good_pixels]
113 self.
sum_weight2sum_weight2[good_pixels] += weight**2.
114 self.
sum_wdata2sum_wdata2[good_pixels] += weight*(masked_image.image.array[good_pixels]**2.)
117 self.
or_maskor_mask[good_pixels] |= masked_image.mask.array[good_pixels]
121 bad_pixels = ((masked_image.mask.array & 2**bit) > 0)
126 """Fill the stacked mask image after accumulation.
130 stacked_masked_image : `lsst.afw.image.MaskedImage`
133 with np.warnings.catch_warnings():
135 np.warnings.simplefilter(
"ignore")
144 variance = self.
sum_wdata2sum_wdata2/self.
sum_weightsum_weight - stacked_masked_image.image.array[:, :]**2.
151 stacked_masked_image.variance.array[:, :] = mean_var
158 self.
or_maskor_mask[propagate] |= 2**bit
162 for mask_tuple
in self.
mask_mapmask_map:
165 stacked_masked_image.mask.array[:, :] = self.
or_maskor_mask
168 mask_dict = stacked_masked_image.maskedImage().getMask().getMaskPlaneDict()
169 no_good_pixels_mask = 2**(mask_dict[
'NO_DATA'])
173 bad_pixels = (self.
sum_weightsum_weight <= 0.0)
174 stacked_masked_image.mask.array[bad_pixels] |= no_good_pixels_mask
178 """Convert stats control to threshold dict.
182 stats_ctrl : `lsst.afw.math.StatisticsControl`
186 threshold_dict : `dict`
187 Dict mapping from bit to propagation threshold.
190 for bit
in range(64):
191 threshold_dict[bit] = stats_ctrl.getMaskPropagationThreshold(bit)
193 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)
calc_error_from_input_variance
def add_masked_image(self, masked_image, weight=1.0)
def stats_ctrl_to_threshold_dict(stats_ctrl)
def fill_stacked_masked_image(self, stacked_masked_image)