def test_instantiate(deimos_flat_files, kast_blue_bias_files):
    one_file = deimos_flat_files[0]
    spectograph = load_spectrograph('keck_deimos')
    # DEIMOS
    deimos_flat = processrawimage.ProcessRawImage(one_file, spectograph, 3,
                                                  par)
    # Test
    assert isinstance(deimos_flat.image, np.ndarray)
    assert deimos_flat.rawdatasec_img.shape == (4096, 2128)

    # Kast blue
    one_file = kast_blue_bias_files[0]
    spectograph2 = load_spectrograph('shane_kast_blue')
    kastb_bias = processrawimage.ProcessRawImage(one_file, spectograph2, 1,
                                                 par)
Exemple #2
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)
def test_overscan_subtract(deimos_flat_files):
    one_file = deimos_flat_files[0]
    spectograph = load_spectrograph('keck_deimos')
    # DEIMOS
    deimos_flat = processrawimage.ProcessRawImage(one_file, spectograph, 3,
                                                  par)
    # Bias subtract
    pre_sub = deimos_flat.image.copy()
    _ = deimos_flat.subtract_overscan()
    oscan = np.median(pre_sub - deimos_flat.image)
    assert np.isclose(oscan, 1001.2, rtol=0.01)
    # Trim
    _ = deimos_flat.trim()
    # Test
    assert deimos_flat.steps['subtract_overscan']
    assert deimos_flat.steps['trim']
    assert deimos_flat.image.shape == (4096, 2048)
Exemple #4
0
    def process_one(self,
                    filename,
                    process_steps,
                    bias,
                    pixel_flat=None,
                    illum_flat=None,
                    bpm=None):
        """
        Process a single image

        Args:
            filename (str):
                File to process
            process_steps (list):
                List of processing steps
            bias (np.ndarray or None):
                Bias image
            pixel_flat (np.ndarray, optional):
                Flat image
            illum_flat (np.ndarray, optional):
                Illumination image
            bpm (np.ndarray, optional):
                Bad pixel mask

        Returns:
            :class:`pypeit.images.pypeitimage.PypeItImage`:

        """
        # Load raw image
        rawImage = rawimage.RawImage(filename, self.spectrograph, self.det)
        # Process
        processrawImage = processrawimage.ProcessRawImage(rawImage,
                                                          self.par,
                                                          bpm=bpm)
        processedImage = processrawImage.process(process_steps,
                                                 bias=bias,
                                                 pixel_flat=pixel_flat,
                                                 illum_flat=illum_flat)
        # Return
        return processedImage
Exemple #5
0
    def from_single_file(cls,
                         spectrograph,
                         det,
                         par,
                         bpm,
                         filename,
                         bias,
                         pixel_flat,
                         illum_flat=None):
        """
        Instantiate from a single file

        This will also generate the ivar, crmask, rn2img and mask

        Args:
            spectrograph (:class:`pypeit.spectrographs.spectrograph.Spectrograph`):
                Spectrograph used to take the data.
            det (:obj:`int`, optional):
                The 1-indexed detector number to process.
            par (:class:`pypeit.par.pypeitpar.ProcessImagesPar`):
                Parameters that dictate the processing of the images.  See
                :class:`pypeit.par.pypeitpar.ProcessImagesPar` for the
                defaults.
            bpm (np.ndarray):
                Bad pixel mask.  Held in ImageMask
            filename (str):
                Filename
            bias (np.ndarray or None):
                Bias image
            pixel_flat (np.ndarray):
                Flat image
            illum_flat (np.ndarray, optional):
                Illumination image

        Returns:
            ScienceImage:

        """
        slf = cls(spectrograph, det, par, bpm)
        slf.files = [filename]
        # Build up
        prawImage = processrawimage.ProcessRawImage(filename, slf.spectrograph,
                                                    slf.det, slf.par)
        # Save a bit
        slf.filename = filename
        slf.exptime = prawImage.exptime
        # Process steps
        process_steps = procimg.init_process_steps(bias, slf.par)
        process_steps += ['trim', 'apply_gain', 'orient']
        if (pixel_flat is not None) or (illum_flat is not None):
            process_steps += ['flatten']
        # Do it
        slf.image = prawImage.process(process_steps,
                                      pixel_flat=pixel_flat,
                                      bias=bias,
                                      illum_flat=illum_flat,
                                      bpm=slf.bpm,
                                      debug=True)
        # Build the rest
        slf.build_ivar()
        slf.build_rn2img()
        slf.build_crmask()
        slf.build_mask(
            saturation=slf.spectrograph.detector[slf.det - 1]['saturation'],
            mincounts=slf.spectrograph.detector[slf.det - 1]['mincounts'])
        # Return
        return slf