Ejemplo n.º 1
0
    def write(self, outfile, hdr=None, iext=None):
        """
        Write the image(s) to a multi-extension FITS file

        Note: This method cannot be named "save" as it would conflict
        with the imported module

        Extensions will be:
           PRIMARY
           IMAGE
           IVAR (optional)
           MASK (optional)

        Args:
            outfile:
            iext (str, optional):
                Name for the first extension
                Defaults to IMAGE
            hdr (`astropy.io.fits.Header`, optional):
                The header to write

        """
        if hdr is None:
            hdr = initialize_header()

        # Chk
        if not self.validate():
            msgs.warn("Image is not ready to save.")
            return

        # Save whatever is available
        data = [self.image]
        if iext is None:
            ext = ['IMAGE']
        else:
            ext = [iext]

        # Work on the rest
        for item in ['ivar', 'mask']:
            if getattr(self, item) is not None:
                data.append(getattr(self, item))
                ext.append(item.upper())

        # TODO -- Default to float32 for float images?
        # Write the fits file
        save.write_fits(hdr, data, outfile, extnames=ext)
Ejemplo n.º 2
0
    def save(self, outfile=None, overwrite=True):
        """
        Save the wavelength tilts data to a master frame

        Args:
            outfile (:obj:`str`, optional):
                Name for the output file.  Defaults to
                :attr:`master_file_path`.
            overwrite (:obj:`bool`, optional):
                Overwrite any existing file.
        """
        _outfile = self.master_file_path if outfile is None else outfile
        # Check if it exists
        if os.path.exists(_outfile) and not overwrite:
            msgs.warn('Master file exists: {0}'.format(_outfile) +
                      msgs.newline() + 'Set overwrite=True to overwrite it.')
            return

        # Log
        msgs.info('Saving master frame to {0}'.format(_outfile))

        # Build the header
        hdr = self.build_master_header(steps=self.steps)
        #   - Set the master frame type
        hdr['FRAMETYP'] = (self.master_type,
                           'PypeIt: Master calibration frame type')
        #   - Tilts metadata
        hdr['FUNC2D'] = self.tilts_dict['func2d']
        hdr['NSLIT'] = self.tilts_dict['nslit']

        # Write the fits file
        data = [
            self.tilts_dict['tilts'], self.tilts_dict['coeffs'],
            self.tilts_dict['slitcen'], self.tilts_dict['spat_order'],
            self.tilts_dict['spec_order']
        ]
        extnames = ['TILTS', 'COEFFS', 'SLITCEN', 'SPAT_ORDER', 'SPEC_ORDER']
        save.write_fits(hdr, data, _outfile, extnames=extnames)
Ejemplo n.º 3
0
    def save(self, outfile=None, overwrite=True, image=None):
        """
        Save the master wavelength image.

        Args:
            outfile (:obj:`str`, optional):
                Name for the output file.  Defaults to
                :attr:`file_path`.
            overwrite (:obj:`bool`, optional):
                Overwrite any existing file.
        """
        _outfile = self.master_file_path if outfile is None else outfile
        # Check if it exists
        if os.path.exists(_outfile) and not overwrite:
            msgs.warn('Master file exists: {0}'.format(_outfile) +
                      msgs.newline() + 'Set overwrite=True to overwrite it.')
            return
        # Setup the items
        hdr = self.build_master_header(steps=self.steps)
        _image = self.image if image is None else image
        # Save to a multi-extension FITS
        save.write_fits(hdr, [_image], _outfile, extnames=['WAVE'])
        msgs.info('Master frame written to {0}'.format(_outfile))
Ejemplo n.º 4
0
    def save(self, outfile=None, overwrite=True):
        """
        Save the flat-field master data to a FITS file

        Extensions are:
            RAWFLAT
            PIXELFLAT
            ILLUMFLAT
            MODEL

        Args:
            outfile (:obj:`str`, optional):
                Name for the output file.  Defaults to
                :attr:`file_path`.
            overwrite (:obj:`bool`, optional):
                Overwrite any existing file.
        """
        _outfile = self.master_file_path if outfile is None else outfile
        # Check if it exists
        if os.path.exists(_outfile) and not overwrite:
            msgs.warn('Master file exists: {0}'.format(_outfile) +
                      msgs.newline() + 'Set overwrite=True to overwrite it.')
            return

        # Setup the items
        hdr = self.build_master_header(steps=self.steps,
                                       raw_files=self.file_list)
        data = [
            self.rawflatimg.image, self.mspixelflat, self.msillumflat,
            self.flat_model
        ]
        extnames = ['RAWFLAT', 'PIXELFLAT', 'ILLUMFLAT', 'MODEL']

        # Save to a multi-extension FITS
        save.write_fits(hdr, data, _outfile, extnames=extnames)
        msgs.info('Master frame written to {0}'.format(_outfile))