Пример #1
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
Пример #2
0
    def build_image(self, bias=None, bpm=None, ignore_saturation=True):
        """
        Load, process and combine the images for a Calibration

        Args:
            bias (np.ndarray, optional):
                Bias image
            bpm (np.ndarray, optional):
                Bad pixel mask
            ignore_saturation (bool, optional):
                If True, turn off the saturation flag in the individual images before stacking
                This avoids having such values set to 0 which for certain images (e.g. flat calibrations)
                has unintended consequences.

        Returns:
            PypeItImage:

        """
        combineImage = combineimage.CombineImage(self.spectrograph, self.det, self.proc_par, self.file_list)
        self.pypeitImage = combineImage.run(self.process_steps, bias, bpm=bpm, ignore_saturation=ignore_saturation)
        # Return
        return self.pypeitImage
Пример #3
0
def buildimage_fromlist(spectrograph,
                        det,
                        frame_par,
                        file_list,
                        bias=None,
                        bpm=None,
                        dark=None,
                        flatimages=None,
                        sigma_clip=False,
                        sigrej=None,
                        maxiters=5,
                        ignore_saturation=True,
                        slits=None):
    """
    Build a PypeItImage from a list of files (and instructions)

    Args:
        spectrograph (:class:`pypeit.spectrographs.spectrograph.Spectrograph`):
            Spectrograph used to take the data.
        det (:obj:`int`):
            The 1-indexed detector number to process.
        frame_par (:class:`pypeit.par.pypeitpar.FramePar`):
            Parameters that dictate the processing of the images.  See
            :class:`pypeit.par.pypeitpar.ProcessImagesPar` for the
            defaults.
        file_list (list):
            List of files
        bpm (np.ndarray, optional):
            Bad pixel mask.  Held in ImageMask
        bias (np.ndarray, optional):
            Bias image
        flatimages (:class:`pypeit.flatfield.FlatImages`, optional):  For flat fielding
        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):
        ignore_saturation (bool, optional):
            Should be True for calibrations and False otherwise

    Returns:
        :class:`pypeit.images.pypeitimage.PypeItImage`:  Or one of its children

    """
    # Check
    if not isinstance(frame_par, pypeitpar.FrameGroupPar):
        msgs.error('Provided ParSet for must be type FrameGroupPar.')
    #process_steps = procimg.set_process_steps(bias, frame_par)
    #
    combineImage = combineimage.CombineImage(spectrograph, det,
                                             frame_par['process'], file_list)
    pypeitImage = combineImage.run(bias=bias,
                                   bpm=bpm,
                                   dark=dark,
                                   flatimages=flatimages,
                                   sigma_clip=sigma_clip,
                                   sigrej=sigrej,
                                   maxiters=maxiters,
                                   ignore_saturation=ignore_saturation,
                                   slits=slits)
    #
    # Decorate according to the type of calibration
    #   Primarily for handling MasterFrames
    #   WARNING, any internals in pypeitImage are lost here
    if frame_par['frametype'] == 'bias':
        finalImage = BiasImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] == 'dark':
        finalImage = DarkImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] == 'arc':
        finalImage = ArcImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] == 'tilt':
        finalImage = TiltImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] == 'trace':
        finalImage = TraceImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] == 'align':
        finalImage = AlignImage.from_pypeitimage(pypeitImage)
    elif frame_par['frametype'] in [
            'pixelflat', 'science', 'standard', 'illumflat'
    ]:
        finalImage = pypeitImage
    else:
        finalImage = None
        embed(header='193 of buildimage')

    # Internals
    finalImage.process_steps = pypeitImage.process_steps
    finalImage.files = file_list
    finalImage.rawheadlist = pypeitImage.rawheadlist
    finalImage.head0 = pypeitImage.head0

    # Return
    return finalImage
Пример #4
0
def buildimage_fromlist(spectrograph,
                        det,
                        frame_par,
                        file_list,
                        bias=None,
                        bpm=None,
                        dark=None,
                        flatimages=None,
                        maxiters=5,
                        ignore_saturation=True,
                        slits=None,
                        mosaic=None):
    """
    Perform basic image processing on a list of images and combine the results.

    .. warning::

        For image mosaics (when ``det`` is a tuple) the processing behavior is
        hard-coded such that bias and dark frames are *not* reformatted into a
        mosaic image.  They are saved in their native multi-image format.
        Bad-pixel masks are also expected to be in multi-image format.  See
        :class:`~pypeit.images.rawimage.RawImage`.

    Args:
        spectrograph (:class:`~pypeit.spectrographs.spectrograph.Spectrograph`):
            Spectrograph used to take the data.
        det (:obj:`int`, :obj:`tuple`):
            The 1-indexed detector number(s) to process.  If a tuple, it must
            include detectors viable as a mosaic for the provided spectrograph;
            see :func:`~pypeit.spectrographs.spectrograph.Spectrograph.allowed_mosaics`.
        frame_par (:class:`~pypeit.par.pypeitpar.FramePar`):
            Parameters that dictate the processing of the images.  See
            :class:`~pypeit.par.pypeitpar.ProcessImagesPar` for the
            defaults.
        file_list (:obj:`list`):
            List of files
        bias (:class:`~pypeit.images.buildimage.BiasImage`, optional):
            Bias image for bias subtraction; passed directly to
            :func:`~pypeit.images.rawimage.RawImage.process` for all images.
        bpm (`numpy.ndarray`_, optional):
            Bad pixel mask; passed directly to
            :func:`~pypeit.images.rawimage.RawImage.process` for all images.
        dark (:class:`~pypeit.images.buildimage.DarkImage`, optional):
            Dark-current image; passed directly to
            :func:`~pypeit.images.rawimage.RawImage.process` for all images.
        flatimages (:class:`~pypeit.flatfield.FlatImages`, optional):
            Flat-field images for flat fielding; passed directly to
            :func:`~pypeit.images.rawimage.RawImage.process` for all images.
        maxiters (:obj:`int`, optional):
            When ``combine_method='mean'``) and sigma-clipping
            (``sigma_clip`` is True), this sets the maximum number of
            rejection iterations.  If None, rejection iterations continue
            until no more data are rejected; see
            :func:`~pypeit.core.combine.weighted_combine``.
        ignore_saturation (:obj:`bool`, optional):
            If True, turn off the saturation flag in the individual images
            before stacking.  This avoids having such values set to 0, which
            for certain images (e.g. flat calibrations) can have unintended
            consequences.
        slits (:class:`~pypeit.slittrace.SlitTraceSet`, optional):
            Edge traces for all slits.  These are used to calculate spatial
            flexure between the image and the slits, and for constructing the
            slit-illumination correction.  See
            :class:`pypeit.images.rawimage.RawImage.process`.

    Returns:
        :class:`~pypeit.images.pypeitimage.PypeItImage`:  The processed and
        combined image.
    """
    # Check
    if not isinstance(frame_par, pypeitpar.FrameGroupPar):
        msgs.error('Provided ParSet for must be type FrameGroupPar.')
    if not valid_frametype(frame_par['frametype'], quiet=True):
        # NOTE: This should not be necessary because FrameGroupPar explicitly
        # requires frametype to be valid
        msgs.error(
            f'{frame_par["frametype"]} is not a valid PypeIt frame type.')

    # Should the detectors be reformatted into a single image mosaic?
    if mosaic is None:
        mosaic = isinstance(
            det, tuple) and frame_par['frametype'] not in ['bias', 'dark']

    # Do it
    combineImage = combineimage.CombineImage(spectrograph, det,
                                             frame_par['process'], file_list)
    pypeitImage = combineImage.run(
        bias=bias,
        bpm=bpm,
        dark=dark,
        flatimages=flatimages,
        sigma_clip=frame_par['process']['clip'],
        sigrej=frame_par['process']['comb_sigrej'],
        maxiters=maxiters,
        ignore_saturation=ignore_saturation,
        slits=slits,
        combine_method=frame_par['process']['combine'],
        mosaic=mosaic)
    # Decorate according to the type of calibration, primarily as needed for
    # handling MasterFrames.  WARNING: Any internals (i.e., the ones defined by
    # the _init_internals method) in pypeitImage are lost here.
    return frame_image_classes[frame_par['frametype']].from_pypeitimage(pypeitImage) \
            if frame_par['frametype'] in frame_image_classes.keys() else pypeitImage