示例#1
0
def test_lacosmic():
    spec = load_spectrograph('keck_deimos')
    file = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'keck_deimos',
                        '1200G_M_5500', 'd0315_45929.fits')
    par = ProcessImagesPar(use_biasimage=False,
                           use_pixelflat=False,
                           use_illumflat=False)
    img = RawImage(file, spec, 1)
    pimg = img.process(par)
    test_img = pimg.image[:500, :500]
    test_var = utils.inverse(pimg.ivar[:500, :500])
    crmask = procimg.lacosmic(test_img, varframe=test_var, maxiter=1)
    assert np.sum(crmask) == 1240, 'L.A.Cosmic changed'

    _crmask = procimg.lacosmic(test_img, varframe=test_var, maxiter=2)
    assert np.sum(_crmask) > np.sum(
        crmask), '2nd iteration should find more cosmics'

    _crmask = procimg.lacosmic(test_img,
                               saturation=6000.,
                               varframe=test_var,
                               maxiter=1)
    assert np.sum(_crmask) < np.sum(
        crmask), 'Should have flagged some pixels as saturated'

    __crmask = procimg.lacosmic(test_img,
                                saturation=np.full(test_img.shape, 6000.),
                                varframe=test_var,
                                maxiter=1)
    assert np.array_equal(__crmask, _crmask), 'Saturation array failed.'
示例#2
0
    def build_crmask(stack, proc_par, det, spectrograph, ivar=None, binning=None):
        """
        Generate the CR mask frame

        Wrapper to procimg.lacosmic

        Parameters
        ----------
        varframe : ndarray, optional

        Returns
        -------
        self.crmask : ndarray
          1. = Masked CR

        """
        # Run LA Cosmic to get the cosmic ray mask
        varframe = utils.calc_ivar(ivar)
        saturation = spectrograph.detector[det-1]['saturation']
        nonlinear = spectrograph.detector[det-1]['nonlinear']
        #sigclip, objlim = spectrograph.get_lacosmics_par(proc_par,binning=binning)
        crmask = procimg.lacosmic(det, stack, saturation, nonlinear,
                                  varframe=varframe, maxiter=proc_par['lamaxiter'],
                                  grow=proc_par['grow'],
                                  remove_compact_obj=proc_par['rmcompact'],
                                  sigclip=proc_par['sigclip'],
                                  sigfrac=proc_par['sigfrac'],
                                  objlim=proc_par['objlim'])

        # Return
        return crmask
示例#3
0
    def build_crmask(self, par, subtract_img=None):
        """
        Generate the CR mask frame

        Mainly a wrapper to :func:`pypeit.core.procimg.lacosmic`

        Args:
            par (:class:`pypeit.par.pypeitpar.ProcessImagesPar`):
                Parameters that dictate the processing of the images.  See
                :class:`pypeit.par.pypeitpar.ProcessImagesPar` for the
                defaults.
            subtract_img (`numpy.ndarray`_, optional):
                If provided, subtract this from the image prior to CR detection

        Returns:
            `numpy.ndarray`_: Copy of self.crmask (boolean)

        """
        var = utils.inverse(self.ivar)
        use_img = self.image if subtract_img is None else self.image - subtract_img
        # Run LA Cosmic to get the cosmic ray mask
        self.crmask = procimg.lacosmic(use_img,
                                       self.detector['saturation'],
                                       self.detector['nonlinear'],
                                       varframe=var,
                                       maxiter=par['lamaxiter'],
                                       grow=par['grow'],
                                       remove_compact_obj=par['rmcompact'],
                                       sigclip=par['sigclip'],
                                       sigfrac=par['sigfrac'],
                                       objlim=par['objlim'])
        # Return
        return self.crmask.copy()
示例#4
0
    def build_crmask(self,
                     spectrograph,
                     det,
                     par,
                     image,
                     rawvarframe,
                     subtract_img=None):
        """
        Generate the CR mask frame

        Mainly a wrapper to procimg.lacosmic

        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.
            image (np.ndarray):
                Image to identify CR's in
            rawvarframe (np.ndarray):
                Variance image
            subtract_img (np.ndarray, optional):
                If provided, subtract this from the image prior to CR detection

        Returns:
            np.ndarray: Copy of self.crmask (boolean)

        """
        use_img = image if subtract_img is None else image - subtract_img
        # Run LA Cosmic to get the cosmic ray mask
        self.crmask = procimg.lacosmic(
            det,
            use_img,
            spectrograph.detector[det - 1]['saturation'],
            spectrograph.detector[det - 1]['nonlinear'],
            varframe=rawvarframe,
            maxiter=par['lamaxiter'],
            grow=par['grow'],
            remove_compact_obj=par['rmcompact'],
            sigclip=par['sigclip'],
            sigfrac=par['sigfrac'],
            objlim=par['objlim'])
        # Return
        return self.crmask.copy()