LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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

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

Static Public Member Functions

def 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 28 of file accumulator_mean_stack.py.

Constructor & Destructor Documentation

◆ __init__()

def 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 51 of file accumulator_mean_stack.py.

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

Member Function Documentation

◆ add_image()

def 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 179 of file accumulator_mean_stack.py.

179  def add_image(self, image, weight=1.0):
180  """Add an image to the stack.
181 
182  No bit-filtering is performed when adding an image.
183 
184  Parameters
185  ----------
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.
191  """
192  self.sum_weight[:, :] += weight
193  self.sum_wdata[:, :] += weight*image.array[:]
194 
195  if self.compute_n_image:
196  self.n_image[:, :] += 1
197 

◆ add_masked_image()

def 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 93 of file accumulator_mean_stack.py.

93  def add_masked_image(self, masked_image, weight=1.0):
94  """Add a masked image to the stack.
95 
96  Parameters
97  ----------
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.
103  """
104  good_pixels = np.where(((masked_image.mask.array & self.bit_mask_value) == 0)
105  & np.isfinite(masked_image.mask.array))
106 
107  self.sum_weight[good_pixels] += weight
108  self.sum_wdata[good_pixels] += weight*masked_image.image.array[good_pixels]
109 
110  if self.compute_n_image:
111  self.n_image[good_pixels] += 1
112 
113  if self.calc_error_from_input_variance:
114  self.sum_w2var[good_pixels] += (weight**2.)*masked_image.variance.array[good_pixels]
115  else:
116  self.sum_weight2[good_pixels] += weight**2.
117  self.sum_wdata2[good_pixels] += weight*(masked_image.image.array[good_pixels]**2.)
118 
119  # Mask bits are propagated for good pixels
120  self.or_mask[good_pixels] |= masked_image.mask.array[good_pixels]
121 
122  # Bad pixels are only tracked if they cross a threshold
123  for bit in self.mask_threshold_dict:
124  bad_pixels = ((masked_image.mask.array & 2**bit) > 0)
125  self.rejected_weights_by_bit[bit][bad_pixels] += weight
126  self.masked_pixels_mask[bad_pixels] |= 2**bit
127 

◆ fill_stacked_image()

def 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 198 of file accumulator_mean_stack.py.

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

◆ fill_stacked_masked_image()

def 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 128 of file accumulator_mean_stack.py.

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

◆ stats_ctrl_to_threshold_dict()

def 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 215 of file accumulator_mean_stack.py.

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

Member Data Documentation

◆ bit_mask_value

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.bit_mask_value

Definition at line 57 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 60 of file accumulator_mean_stack.py.

◆ compute_n_image

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.compute_n_image

Definition at line 61 of file accumulator_mean_stack.py.

◆ mask_map

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.mask_map

Definition at line 58 of file accumulator_mean_stack.py.

◆ mask_threshold_dict

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.mask_threshold_dict

Definition at line 64 of file accumulator_mean_stack.py.

◆ masked_pixels_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.masked_pixels_mask

Definition at line 88 of file accumulator_mean_stack.py.

◆ n_image

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.n_image

Definition at line 91 of file accumulator_mean_stack.py.

◆ no_good_pixels_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.no_good_pixels_mask

Definition at line 59 of file accumulator_mean_stack.py.

◆ or_mask

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.or_mask

Definition at line 83 of file accumulator_mean_stack.py.

◆ rejected_weights_by_bit

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.rejected_weights_by_bit

Definition at line 84 of file accumulator_mean_stack.py.

◆ shape

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.shape

Definition at line 56 of file accumulator_mean_stack.py.

◆ sum_w2var

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_w2var

Definition at line 76 of file accumulator_mean_stack.py.

◆ sum_wdata

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_wdata

Definition at line 72 of file accumulator_mean_stack.py.

◆ sum_wdata2

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_wdata2

Definition at line 81 of file accumulator_mean_stack.py.

◆ sum_weight

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_weight

Definition at line 70 of file accumulator_mean_stack.py.

◆ sum_weight2

lsst.meas.algorithms.accumulator_mean_stack.AccumulatorMeanStack.sum_weight2

Definition at line 79 of file accumulator_mean_stack.py.


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