Exemple #1
0
def test_instantiate_from_one(shane_kast_blue_sci_files):
    """
    Run on a single science frame
    """
    #
    det = 1
    # Load calibrations
    pixelflat = load_kast_blue_masters(pixflat=True)[0]
    bpm = kast_blue.empty_bpm(shane_kast_blue_sci_files[0], det)
    # Process steps
    bias = None
    par = kast_par['scienceframe']['process']
    process_steps = procimg.init_process_steps(bias, par)
    process_steps += ['trim', 'apply_gain', 'orient']
    process_steps += ['flatten']
    process_steps += ['extras']
    process_steps += ['crmask']
    # Load
    rawImage = rawimage.RawImage(shane_kast_blue_sci_files[0], kast_blue, det)
    processRawImage = processrawimage.ProcessRawImage(rawImage,
                                                      kast_par['scienceframe']['process'])
    pypeItImage = processRawImage.process(process_steps, pixel_flat=pixelflat)
    # Do it
    sciImg = scienceimage.ScienceImage(kast_blue, det, kast_par['scienceframe']['process'],
                                       pypeItImage.image, pypeItImage.ivar, bpm)
Exemple #2
0
    def build_stack(self, files, bpm, reject_cr=False):
        """
        Generate a set of stack arrays useful for image processing

        These are generated from the internal ProcessImage objects
        held in self.pimages which need to have been previously
        generated/loaded

        Note:  To save on memory, the image attributes of each
        ProcessImage in self.pimages is reset after it contributes
        to the stack arrays.

        Args:
            bpm (np.ndarray):
                Bad pixel mask image
            reject_cr (bool, optional):
                If true, generate a CR image

        Returns:
            tuple: np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray
                sciimg_stack, sciivar_stack, rn2img_stack, crmask_stack, mask_stack

        """
        # Get it ready
        nimages = len(files)
        shape = (nimages, bpm.shape[0], bpm.shape[1])
        sciimg_stack = np.zeros(shape)
        sciivar_stack = np.zeros(shape)
        rn2img_stack = np.zeros(shape)
        crmask_stack = np.zeros(shape, dtype=bool)

        # Mask
        bitmask = maskimage.ImageBitMask()
        mask_stack = np.zeros(shape, bitmask.minimum_dtype(asuint=True))

        # Loop on the files
        for kk, ifile in enumerate(files):
            # Instantiate
            sciImage = scienceimage.ScienceImage(self.spectrograph, self.det,
                                                 self.par['process'], bpm)
            # Process
            sciimg_stack[kk, :, :] = sciImage.process_raw(
                ifile, self.bias, self.pixel_flat, illum_flat=self.illum_flat)
            # Construct raw variance image and turn into inverse variance
            sciivar_stack[kk, :, :] = sciImage.build_ivar()
            # Mask cosmic rays
            if reject_cr:
                crmask_stack[kk, :, :] = sciImage.build_crmask()
            # Build read noise squared image
            rn2img_stack[kk, :, :] = sciImage.build_rn2img()
            # Final mask for this image
            mask_stack[kk, :, :] = sciImage.build_mask(
                saturation=self.spectrograph.detector[self.det -
                                                      1]['saturation'],
                mincounts=self.spectrograph.detector[self.det -
                                                     1]['mincounts'])

        # Return
        return sciimg_stack, sciivar_stack, rn2img_stack, crmask_stack, mask_stack
Exemple #3
0
def test_standard_instantiate():
    """
    Simple instantiate
    """
    # Empty
    bpm = np.zeros((100, 100))
    sciImg = scienceimage.ScienceImage(kast_blue, [],
                                       kast_par['scienceframe']['process'],
                                       bpm)
    assert sciImg.nfiles == 0
Exemple #4
0
def test_standard_instantiate():
    """
    Simple instantiate
    """
    # Empty
    bpm = np.zeros((100,100))
    det = 1
    sciImg = scienceimage.ScienceImage(kast_blue, det, kast_par['scienceframe']['process'],
                                       np.zeros_like(bpm),
                                       np.zeros_like(bpm),
                                       bpm)