LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack Class Reference
Inheritance diagram for lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack:

Public Member Functions

 __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)
 
 add_masked_image (self, masked_image, weight=1.0)
 
 fill_stacked_masked_image (self, stacked_masked_image)
 
 add_image (self, image, weight=1.0)
 
 fill_stacked_image (self, stacked_image)
 

Static Public Member Functions

 stats_ctrl_to_threshold_dict (stats_ctrl)
 

Public Attributes

 shape
 
 bit_mask_value
 
 mask_map
 
 no_good_pixels_mask
 
 calc_error_from_input_variance
 
 compute_n_image
 
 mask_threshold_dict
 
 sum_weight
 
 sum_wdata
 
 sum_w2var
 
 sum_weight2
 
 sum_wdata2
 
 or_mask
 
 rejected_weights_by_bit
 
 masked_pixels_mask
 
 n_image
 

Detailed Description

Stack masked images.

Parameters
----------
shape : `tuple`
    Shape of the input and output images.
bit_mask_value : `int`
    Bit mask to flag for "bad" inputs that should not be stacked.
mask_threshold_dict : `dict` [`int`: `float`], optional
    Dictionary of mapping from bit number to threshold for flagging.
    Only bad bits (in bit_mask_value) which mask fractional weight
    greater than this threshold will be flagged in the output image.
mask_map : `list` [`tuple`], optional
    Mapping from input image bits to aggregated coadd bits.
no_good_pixels_mask : `int`, optional
    Bit mask to set when there are no good pixels in the stack.
    If not set then will set coadd masked image 'NO_DATA' bit.
calc_error_from_input_variance : `bool`, optional
    Calculate the error from the input variance?
compute_n_image : `bool`, optional
    Calculate the n_image map as well as stack?

Definition at line 30 of file accumulator_mean_stack.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.__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 )

Definition at line 53 of file accumulator_mean_stack.py.

57 compute_n_image=False):
58 self.shape = shape
59 self.bit_mask_value = bit_mask_value
60 self.mask_map = mask_map
61 self.no_good_pixels_mask = no_good_pixels_mask
62 self.calc_error_from_input_variance = calc_error_from_input_variance
63 self.compute_n_image = compute_n_image
64
65 # Only track threshold bits that are in the bad bit_mask_value.
66 self.mask_threshold_dict = {}
67 for bit in mask_threshold_dict:
68 if (self.bit_mask_value & 2**bit) > 0:
69 self.mask_threshold_dict[bit] = mask_threshold_dict[bit]
70
71 # sum_weight holds the sum of weights for each pixel.
72 self.sum_weight = np.zeros(shape, dtype=np.float64)
73 # sum_wdata holds the sum of weight*data for each pixel.
74 self.sum_wdata = np.zeros(shape, dtype=np.float64)
75
76 if calc_error_from_input_variance:
77 # sum_w2var holds the sum of weight**2 * variance for each pixel.
78 self.sum_w2var = np.zeros(shape, dtype=np.float64)
79 else:
80 # sum_weight2 holds the sum of weight**2 for each pixel.
81 self.sum_weight2 = np.zeros(shape, dtype=np.float64)
82 # sum_wdata2 holds the sum of weight * data**2 for each pixel.
83 self.sum_wdata2 = np.zeros(shape, dtype=np.float64)
84
85 self.or_mask = np.zeros(shape, dtype=np.int64)
86 self.rejected_weights_by_bit = {}
87 for bit in self.mask_threshold_dict:
88 self.rejected_weights_by_bit[bit] = np.zeros(shape, dtype=np.float64)
89
90 self.masked_pixels_mask = np.zeros(shape, dtype=np.int64)
91
92 if self.compute_n_image:
93 self.n_image = np.zeros(shape, dtype=np.int32)
94

Member Function Documentation

◆ add_image()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.add_image ( self,
image,
weight = 1.0 )
Add an image to the stack.

No bit-filtering is performed when adding an image.

Parameters
----------
image : `lsst.afw.image.Image`
    Image to add to the stack.
weight : `float` or `np.ndarray`, optional
    Weight to apply for weighted mean.  If an array,
    must be same size and shape as input image.

Definition at line 181 of file accumulator_mean_stack.py.

181 def add_image(self, image, weight=1.0):
182 """Add an image to the stack.
183
184 No bit-filtering is performed when adding an image.
185
186 Parameters
187 ----------
188 image : `lsst.afw.image.Image`
189 Image to add to the stack.
190 weight : `float` or `np.ndarray`, optional
191 Weight to apply for weighted mean. If an array,
192 must be same size and shape as input image.
193 """
194 self.sum_weight[:, :] += weight
195 self.sum_wdata[:, :] += weight*image.array[:]
196
197 if self.compute_n_image:
198 self.n_image[:, :] += 1
199

◆ add_masked_image()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.add_masked_image ( self,
masked_image,
weight = 1.0 )
Add a masked image to the stack.

Parameters
----------
masked_image : `lsst.afw.image.MaskedImage`
    Masked image to add to the stack.
weight : `float` or `np.ndarray`, optional
    Weight to apply for weighted mean.  If an array,
    must be same size and shape as input masked_image.

Definition at line 95 of file accumulator_mean_stack.py.

95 def add_masked_image(self, masked_image, weight=1.0):
96 """Add a masked image to the stack.
97
98 Parameters
99 ----------
100 masked_image : `lsst.afw.image.MaskedImage`
101 Masked image to add to the stack.
102 weight : `float` or `np.ndarray`, optional
103 Weight to apply for weighted mean. If an array,
104 must be same size and shape as input masked_image.
105 """
106 good_pixels = np.where(((masked_image.mask.array & self.bit_mask_value) == 0)
107 & np.isfinite(masked_image.mask.array))
108
109 self.sum_weight[good_pixels] += weight
110 self.sum_wdata[good_pixels] += weight*masked_image.image.array[good_pixels]
111
112 if self.compute_n_image:
113 self.n_image[good_pixels] += 1
114
115 if self.calc_error_from_input_variance:
116 self.sum_w2var[good_pixels] += (weight**2.)*masked_image.variance.array[good_pixels]
117 else:
118 self.sum_weight2[good_pixels] += weight**2.
119 self.sum_wdata2[good_pixels] += weight*(masked_image.image.array[good_pixels]**2.)
120
121 # Mask bits are propagated for good pixels
122 self.or_mask[good_pixels] |= masked_image.mask.array[good_pixels]
123
124 # Bad pixels are only tracked if they cross a threshold
125 for bit in self.mask_threshold_dict:
126 bad_pixels = ((masked_image.mask.array & 2**bit) > 0)
127 self.rejected_weights_by_bit[bit][bad_pixels] += weight
128 self.masked_pixels_mask[bad_pixels] |= 2**bit
129

◆ fill_stacked_image()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.fill_stacked_image ( self,
stacked_image )
Fill the image after accumulation.

Parameters
----------
stacked_image : `lsst.afw.image.Image`
    Total image.

Definition at line 200 of file accumulator_mean_stack.py.

200 def fill_stacked_image(self, stacked_image):
201 """Fill the image after accumulation.
202
203 Parameters
204 ----------
205 stacked_image : `lsst.afw.image.Image`
206 Total image.
207 """
208 with warnings.catch_warnings():
209 # Let the NaNs through, this should only happen
210 # if we're stacking with no inputs.
211 warnings.simplefilter("ignore")
212
213 # The image plane is sum(weight*data)/sum(weight)
214 stacked_image.array[:, :] = self.sum_wdata/self.sum_weight
215

◆ fill_stacked_masked_image()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.fill_stacked_masked_image ( self,
stacked_masked_image )
Fill the stacked mask image after accumulation.

Parameters
----------
stacked_masked_image : `lsst.afw.image.MaskedImage`
    Total masked image.

Definition at line 130 of file accumulator_mean_stack.py.

130 def fill_stacked_masked_image(self, stacked_masked_image):
131 """Fill the stacked mask image after accumulation.
132
133 Parameters
134 ----------
135 stacked_masked_image : `lsst.afw.image.MaskedImage`
136 Total masked image.
137 """
138 with warnings.catch_warnings():
139 # Let the NaNs through and flag bad pixels below
140 warnings.simplefilter("ignore")
141
142 # The image plane is sum(weight*data)/sum(weight)
143 stacked_masked_image.image.array[:, :] = self.sum_wdata/self.sum_weight
144
145 if self.calc_error_from_input_variance:
146 mean_var = self.sum_w2var/(self.sum_weight**2.)
147 else:
148 # Compute the biased estimator
149 variance = self.sum_wdata2/self.sum_weight - stacked_masked_image.image.array[:, :]**2.
150 # De-bias
151 variance *= (self.sum_weight**2.)/(self.sum_weight**2. - self.sum_weight2)
152
153 # Compute the mean variance
154 mean_var = variance*self.sum_weight2/(self.sum_weight**2.)
155
156 stacked_masked_image.variance.array[:, :] = mean_var
157
158 # Propagate bits when they cross the threshold
159 for bit in self.mask_threshold_dict:
160 hypothetical_total_weight = self.sum_weight + self.rejected_weights_by_bit[bit]
161 self.rejected_weights_by_bit[bit] /= hypothetical_total_weight
162 propagate = np.where(self.rejected_weights_by_bit[bit] > self.mask_threshold_dict[bit])
163 self.or_mask[propagate] |= 2**bit
164
165 # Map mask planes to new bits for pixels that had at least one
166 # bad input rejected and are in the mask_map.
167 for mask_tuple in self.mask_map:
168 self.or_mask[(self.masked_pixels_mask & mask_tuple[0]) > 0] |= mask_tuple[1]
169
170 stacked_masked_image.mask.array[:, :] = self.or_mask
171
172 if self.no_good_pixels_mask is None:
173 mask_dict = stacked_masked_image.mask.getMaskPlaneDict()
174 no_good_pixels_mask = 2**(mask_dict['NO_DATA'])
175 else:
176 no_good_pixels_mask = self.no_good_pixels_mask
177
178 bad_pixels = (self.sum_weight <= 0.0)
179 stacked_masked_image.mask.array[bad_pixels] |= no_good_pixels_mask
180

◆ stats_ctrl_to_threshold_dict()

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.stats_ctrl_to_threshold_dict ( stats_ctrl)
static
Convert stats control to threshold dict.

Parameters
----------
stats_ctrl : `lsst.afw.math.StatisticsControl`

Returns
-------
threshold_dict : `dict`
    Dict mapping from bit to propagation threshold.

Definition at line 217 of file accumulator_mean_stack.py.

217 def stats_ctrl_to_threshold_dict(stats_ctrl):
218 """Convert stats control to threshold dict.
219
220 Parameters
221 ----------
222 stats_ctrl : `lsst.afw.math.StatisticsControl`
223
224 Returns
225 -------
226 threshold_dict : `dict`
227 Dict mapping from bit to propagation threshold.
228 """
229 threshold_dict = {}
230 for bit in range(64):
231 threshold_dict[bit] = stats_ctrl.getMaskPropagationThreshold(bit)
232
233 return threshold_dict

Member Data Documentation

◆ bit_mask_value

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.bit_mask_value

Definition at line 59 of file accumulator_mean_stack.py.

◆ calc_error_from_input_variance

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.calc_error_from_input_variance

Definition at line 62 of file accumulator_mean_stack.py.

◆ compute_n_image

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.compute_n_image

Definition at line 63 of file accumulator_mean_stack.py.

◆ mask_map

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.mask_map

Definition at line 60 of file accumulator_mean_stack.py.

◆ mask_threshold_dict

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.mask_threshold_dict

Definition at line 66 of file accumulator_mean_stack.py.

◆ masked_pixels_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.masked_pixels_mask

Definition at line 90 of file accumulator_mean_stack.py.

◆ n_image

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.n_image

Definition at line 93 of file accumulator_mean_stack.py.

◆ no_good_pixels_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.no_good_pixels_mask

Definition at line 61 of file accumulator_mean_stack.py.

◆ or_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.or_mask

Definition at line 85 of file accumulator_mean_stack.py.

◆ rejected_weights_by_bit

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.rejected_weights_by_bit

Definition at line 86 of file accumulator_mean_stack.py.

◆ shape

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.shape

Definition at line 58 of file accumulator_mean_stack.py.

◆ sum_w2var

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_w2var

Definition at line 78 of file accumulator_mean_stack.py.

◆ sum_wdata

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_wdata

Definition at line 74 of file accumulator_mean_stack.py.

◆ sum_wdata2

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_wdata2

Definition at line 83 of file accumulator_mean_stack.py.

◆ sum_weight

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_weight

Definition at line 72 of file accumulator_mean_stack.py.

◆ sum_weight2

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_weight2

Definition at line 81 of file accumulator_mean_stack.py.


The documentation for this class was generated from the following file: