def build_mask(dqarr, bitvalue): """Build a bit mask from an input DQ array and a bitvalue flag In the returned bit mask, 1 is good, 0 is bad """ bitvalue = interpret_bit_flags(bitvalue, mnemonic_map=pixel) if bitvalue is None: return (np.ones(dqarr.shape, dtype=np.uint8)) return np.logical_not(np.bitwise_and(dqarr, ~bitvalue)).astype(np.uint8)
def dqimage(image, flag): thebit = dqflags.interpret_bit_flags(flag, mnemonic_map=datamodels.dqflags.pixel) newimage = image.copy() indx = np.where((image & thebit) == 0) if (len(indx[0]) > 0): newimage[indx] = 0 indx = np.where((image & thebit) != 0) if (len(indx[0]) > 0): newimage[indx] = 1 return newimage
def process(self, target, psf): # Open the input science target model with datamodels.open(target) as target_model: # Get the name of the psf mask reference file to use self.mask_name = self.get_reference_file(target_model, 'psfmask') self.log.info('Using PSFMASK reference file %s', self.mask_name) # Check for a valid reference file if self.mask_name == 'N/A': self.log.warning('No PSFMASK reference file found') self.log.warning('Align_refs step will be skipped') return None # Open the psf mask reference file mask_model = datamodels.ImageModel(self.mask_name) # Open the input psf images psf_model = datamodels.open(psf) # Retrieve the box size for the filter box_size = self.median_box_length # Get the bit value of bad pixels. A value of 0 treats all pixels as good. bad_bitvalue = self.bad_bits bad_bitvalue = interpret_bit_flags(bad_bitvalue, mnemonic_map=pixel) if bad_bitvalue is None: bad_bitvalue = 0 # Replace bad pixels in the psf images psf_model = median_replace_img(psf_model, box_size, bad_bitvalue) # Replace bad pixels in the target images target_model = median_replace_img(target_model, box_size, bad_bitvalue) # Call the alignment routine result = imageregistration.align_models(target_model, psf_model, mask_model) result.meta.cal_step.align_psfs = 'COMPLETE' mask_model.close() psf_model.close() return result
def test_dqflags(): assert dqflags.dqflags_to_mnemonics(1, PIXEL) == {'DO_NOT_USE'} assert dqflags.dqflags_to_mnemonics(7, PIXEL) == {'JUMP_DET', 'DO_NOT_USE', 'SATURATED'} assert dqflags.interpret_bit_flags('DO_NOT_USE + WARM', mnemonic_map=PIXEL) == 4097