Ejemplo n.º 1
0
def test_sub_overscan():
    datasec = np.zeros((10, 10), dtype=int)
    datasec[:5, :-3] = 1
    datasec[5:, :-3] = 2

    oscan = np.zeros((10, 10), dtype=int)
    oscan[:5, -3:] = 1
    oscan[5:, -3:] = 2

    raw = np.zeros((10, 10), dtype=float)
    raw[datasec == 1] = 10.
    raw[datasec == 2] = 20.
    raw[oscan == 1] = 9.
    raw[oscan == 2] = 19.

    raw_sub, _ = procimg.subtract_overscan(raw,
                                           datasec,
                                           oscan,
                                           method='median')
    assert np.array_equal(raw_sub[datasec > 0], np.ones(np.sum(datasec > 0), dtype=float)), \
            'Bad overscan subtraction'

    var = np.ones((10, 10), dtype=float)
    raw_sub, var_sub = procimg.subtract_overscan(raw,
                                                 datasec,
                                                 oscan,
                                                 method='median',
                                                 var=var)
    assert np.array_equal(var_sub[datasec > 0],
                          np.full(np.sum(datasec > 0), np.pi/2/15, dtype=float)), \
            'Bad variance calculation'
Ejemplo n.º 2
0
    def bias_subtract(self, msbias, trim=True, force=False, par=None):
        """
        Subtract the bias.

        Parameters
        ----------
        msbias : ndarray, str (optional)
          If ndarray, the input is a Bias image
          If str, the input is guides the Bias subtraction method e.g.  'overscan'
        trim

        Returns
        -------

        """
        # Check if the bias has already been subtracted
        if (inspect.stack()[0][3] in self.steps) & (not force):
            msgs.warn("Images already bias subtracted.  Use force=True to reset proc_images "
                      "and do it again. Returning...")
            return

        # Set the parameters
        if par is not None and not isinstance(par, pypeitpar.ProcessImagesPar):
            raise TypeError('Provided ParSet for must be type ProcessImagesPar.')
        if par is not None:
            self.proc_par = par

        # If trimming, get the image identifying amplifier used for the
        # data section
        datasec_img = self.spectrograph.get_datasec_img(self.files[0], det=self.det)
        msgs.info("Bias subtracting your image(s)")
        # Reset proc_images -- Is there any reason we wouldn't??
        numamplifiers = self.spectrograph.detector[self.det-1]['numamplifiers']
        for kk,image in enumerate(self.raw_images):
            # Bias subtract (move here from procimg)
            if isinstance(msbias, np.ndarray):
                msgs.info("Subtracting bias image from raw frame")
                # Trim?
                if trim:
                    image = procimg.trim_frame(image, datasec_img < 1)
                temp = image-msbias
            elif isinstance(msbias, str) and msbias == 'overscan':
                msgs.info("Using overscan to subtract")
                temp = procimg.subtract_overscan(image, numamplifiers, self.datasec[kk],
                                                 self.oscansec[kk],
                                                 method=self.proc_par['overscan'],
                                                 params=self.proc_par['overscan_par'])
                # Trim?
                if trim:
                    temp = procimg.trim_frame(temp, datasec_img < 1)
            else:
                msgs.error('Could not subtract bias level with the input bias approach.')
            # Save
            if kk==0:
                # Instantiate proc_images
                self.proc_images = np.zeros((temp.shape[0], temp.shape[1], self.nloaded))
            self.proc_images[:,:,kk] = temp.copy()
        # Step
        self.steps.append(inspect.stack()[0][3])
Ejemplo n.º 3
0
    def subtract_overscan(self, force=False):
        """
        Analyze and subtract the overscan from the image

        Args:
            force (bool, optional):
                Force the processing even if the image was already processed

        """
        step = inspect.stack()[0][3]
        # Check if already trimmed
        if self.steps[step] and (not force):
            msgs.warn("Image was already trimmed")

        temp = procimg.subtract_overscan(self.image, self.rawdatasec_img, self.oscansec_img,
                                         method=self.par['overscan'],
                                         params=self.par['overscan_par'])
        # Fill
        self.steps[step] = True
        self.image = temp