예제 #1
0
    def build_pixflat(self, trim=True, force=False):
        """
        Generate the flat image.

        Args:
            trim (:obj:`bool`, optional):
                Trim the image down to just the data section.
            force (:obj:`bool`, optional):
                Force the flat to be reconstructed if it already exists

        Returns:
            pypeitimage.PypeItImage:  The image with the unnormalized pixel-flat data.
        """
        if self.rawflatimg is None or force:
            # Process steps
            self.process_steps = procimg.init_process_steps(
                self.msbias, self.par['process'])
            ## JFH We never need untrimmed images. Why is this even an option?
            if trim:
                self.process_steps += ['trim']
            self.process_steps += ['apply_gain']
            self.process_steps += ['orient']
            # Turning this on leads to substantial edge-tracing problems when last tested
            #     JXP November 22, 2019
            #if self.par['cr_reject']:
            #    self.process_steps += ['crmask']
            self.steps.append(inspect.stack()[0][3])
            # Do it
            self.rawflatimg = super(FlatField,
                                    self).build_image(bias=self.msbias,
                                                      bpm=self.msbpm,
                                                      ignore_saturation=True)
        return self.rawflatimg
예제 #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)
예제 #3
0
    def build_pixflat(self, trim=True, force=False):
        """
        Generate the flat image.

        Args:
            trim (:obj:`bool`, optional):
                Trim the image down to just the data section.
            force (:obj:`bool`, optional):
                Force the flat to be reconstructed if it already exists

        Returns:
            `numpy.ndarray`_:  The image with the unnormalized
            pixel-flat data.
        """
        if self.rawflatimg is None or force:
            # Process steps
            self.process_steps = procimg.init_process_steps(self.msbias, self.par['process'])
            if trim:
                self.process_steps += ['trim']
            self.process_steps += ['apply_gain']
            self.process_steps += ['orient']
            self.steps.append(inspect.stack()[0][3])
            # Do it
            self.rawflatimg = super(FlatField, self).build_image(bias=self.msbias,
                                                                 bpm=self.msbpm)
        return self.rawflatimg
예제 #4
0
def build_from_file_list(spectrograph, det, par, bpm,
                   file_list, bias, pixel_flat, illum_flat=None,
                   sigma_clip=False, sigrej=None, maxiters=5):
    """
    Build a ScienceImage from a file list
    using a default set of process steps

    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`):
            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
        file_list (list):
            List of files
        bias (np.ndarray or None):
            Bias image
        pixel_flat (np.ndarray):
            Flat image
        illum_flat (np.ndarray, optional):
            Illumination image
        sigrej (int or float, optional): Rejection threshold for sigma clipping.
             Code defaults to determining this automatically based on the numberr of images provided.
        maxiters (int, optional):

    Returns:
        ScienceImage:

    """
    # Process steps
    process_steps = procimg.init_process_steps(bias, par)
    process_steps += ['trim', 'apply_gain', 'orient']
    if (pixel_flat is not None) or (illum_flat is not None):
        process_steps += ['flatten']
    process_steps += ['extras']
    if par['cr_reject']:
        process_steps += ['crmask']

    combineImage = combineimage.CombineImage(spectrograph, det, par, file_list)
    pypeitImage = combineImage.run(process_steps, bias, bpm=bpm, pixel_flat=pixel_flat,
                                 illum_flat=illum_flat, sigma_clip=sigma_clip,
                                 sigrej=sigrej, maxiters=maxiters)

    # Instantiate
    slf = ScienceImage(spectrograph, det, par, pypeitImage.image, pypeitImage.ivar,
                                pypeitImage.bpm, rn2img=pypeitImage.rn2img,
                                crmask=pypeitImage.crmask, mask=pypeitImage.mask,
                                files=file_list)
    # Return
    return slf
예제 #5
0
def test_combine(deimos_flat_files):
    spectograph = load_spectrograph('keck_deimos')
    # DEIMOS
    deimos_flats = calibrationimage.CalibrationImage(spectograph, 3, par, files=deimos_flat_files)
    # Process steps
    psteps = procimg.init_process_steps(None, deimos_flats.proc_par)
    assert 'subtract_overscan' in psteps
    psteps += ['trim', 'orient', 'apply_gain']
    deimos_flats.process_steps = psteps
    # Bias subtract (and trim)
    deimos_flats.build_image()
    # Test
    assert deimos_flats.image.shape == (4096,2048)
예제 #6
0
 def __init__(self, spectrograph, files=None, det=1, par=None, bias=None):
     self.par = pypeitpar.FrameGroupPar('trace') if par is None else par
     # Start us up
     calibrationimage.CalibrationImage.__init__(self,
                                                spectrograph,
                                                det,
                                                self.par['process'],
                                                files=files)
     # Processing steps
     self.process_steps = procimg.init_process_steps(
         bias, self.par['process'])
     self.process_steps += ['trim']
     self.process_steps += ['apply_gain']
     self.process_steps += ['orient']
예제 #7
0
def process_raw_for_jfh(filename,
                        spectrograph,
                        det=1,
                        proc_par=None,
                        process_steps=None,
                        bias=None):
    """
    Process an input raw frame for JFH

    Args:
        filename (str):
        spectrograph (:class:`pypeit.spectrographs.spectrograph.Spectrograph`):
            Spectrograph used to take the data.
        proc_par (:class:`pypeit.par.pypeitpar.ProcessImagesPar`):
            Parameters that dictate the processing of the images.  See
            :class:`pypeit.par.pypeitpar.ProcessImagesPar` for the
            defaults.
        det (:obj:`int`, optional):
            The 1-indexed detector number to process.
        process_steps (list, optional):
            Processing steps.
        bias (str or np.ndarray or None):
            Bias image or command

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

    """
    # Setup
    if proc_par is None:
        par = spectrograph.default_pypeit_par()
        msgs.warn("Using the Processing parameters from scienceframe")
        proc_par = par['scienceframe']['process']
    if process_steps is None:
        process_steps = procimg.init_process_steps(bias, proc_par)
        process_steps += ['trim']
        process_steps += ['orient']
        process_steps += ['apply_gain']

    # Generate the rawImage
    rawImage = rawimage.RawImage(filename, spectrograph, det)

    # Now Process
    processRawImage = ProcessRawImage(rawImage, proc_par)
    pypeitImage = processRawImage.process(process_steps, bias=bias)

    # Return
    return pypeitImage
예제 #8
0
    def __init__(self,
                 spectrograph,
                 files=None,
                 det=1,
                 par=None,
                 master_key=None,
                 master_dir=None,
                 reuse_masters=False,
                 msbias=None):

        # Parameters unique to this Object
        self.msbias = msbias

        # Parameters
        self.par = pypeitpar.FrameGroupPar(
            self.frametype) if par is None else par

        # Start us up
        calibrationimage.CalibrationImage.__init__(self,
                                                   spectrograph,
                                                   det,
                                                   self.par['process'],
                                                   files=files)

        # MasterFrames: Specifically pass the ProcessImages-constructed
        # spectrograph even though it really only needs the string name
        masterframe.MasterFrame.__init__(self,
                                         self.master_type,
                                         master_dir=master_dir,
                                         master_key=master_key,
                                         reuse_masters=reuse_masters)
        # Process steps
        self.process_steps = procimg.init_process_steps(
            self.msbias, self.par['process'])
        self.process_steps += ['trim']
        self.process_steps += ['orient']
        self.process_steps += ['apply_gain']
예제 #9
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