Exemplo n.º 1
0
    def mopup(self):
        """Deleting tmp-files, copying SPC's, STP's"""

        # get the root name of the dispersed image
        root_name = self.dispersed_image.split('.fits')[0]

        #  get the root name of the simulated image
        result_root = self.simul_grisim.split('.fits')[0]

        # move and rename the SPC-file
        out_spc = config_util.getOUTPUT(root_name + '_2.SPC.fits')
        result_spc = config_util.getOUTSIM(result_root + '_2.SPC.fits')
        shutil.move(out_spc, result_spc)

        # move and rename the STP-file
        out_stp = config_util.getOUTPUT(root_name + '_2.STP.fits')
        result_stp = config_util.getOUTSIM(result_root + '_2.STP.fits')
        shutil.move(out_stp, result_stp)

        # delete the background subtracted
        # grism image
        os.unlink(config_util.getDATA(self.dispersed_image))

        # delete the GOL, the OAF and the PET
        result_cat = config_util.getOUTPUT(root_name + '_2.cat')
        if os.path.isfile(result_cat):
            os.unlink(result_cat)
        result_oaf = config_util.getOUTPUT(root_name + '_2.OAF')
        if os.path.isfile(result_oaf):
            os.unlink(result_oaf)
        result_pet = config_util.getOUTPUT(root_name + '_2.PET.fits')
        if os.path.isfile(result_pet):
            os.unlink(result_pet)
Exemplo n.º 2
0
    def prepare_extraction(self):
        """Prepares the aXe extraction

        The module does some preparatory stuff before the extraction
        can start. This includes copying the simulated dispersed image
        to AXE_IMAGE_PATH and subtracting the background on this copy.
        """
        # give brief feedback
        _log.info('Dummy extraction on the dispersed image:')
        sys.stdout.flush()

        # get a random filenames
        tmpfile1 = config_util.get_random_filename('t', '.fits')

        # copy the grism image to AXE_IMAGE_PATH
        shutil.copy(config_util.getOUTSIM(self.simul_grisim),
                    config_util.getDATA(tmpfile1))

        # subtract the background from
        # the grism image
        # expression = "(a - b)"
        # iraf.imexpr(expr=expression, output=tmpfile2,
        #    a=config_util.getDATA(tmpfile1)+'[SCI]', b=self.bck_flux, Stdout=1)

        in_image = fits.open(config_util.getDATA(tmpfile1))
        in_image['sci'].data -= self.bck_flux
        in_image.close()

        # store the name of the background
        # subtracted grism image - this was tmpfile
        self.dispersed_image = tmpfile1
Exemplo n.º 3
0
    def _check_files(self):
        """Checks the existence of the input files"""
        # check the direct image
        if not os.path.isfile(config_util.getDATA(self.direct_image)):
            err_msg = ("\nThe direct image is not available: {0:s}".format(
                config_util.getDATA(self.direct_image)))
            raise aXeSIMError(err_msg)

        # check the configuration file
        if not os.path.isfile(config_util.getCONF(self.configfile)):
            err_msg = (
                "\nThe configuration file is not available: {0:s}".format(
                    config_util.getCONF(self.configfile)))
            raise aXeSIMError(err_msg)

        # check the simulated grism image
        if not os.path.isfile(config_util.getOUTSIM(self.simul_grisim)):
            err_msg = ("\nThe grism image is not available: {0:s}".format(
                config_util.getOUTSIM(self.simul_grisim)))
            raise aXeSIMError(err_msg)

        # check the IOL
        if not os.path.isfile(self.iolname):
            err_msg = (
                "\nThe Input Object List is not available: {0:s}".format(
                    self.iolname))
            raise aXeSIMError(err_msg)

        try:
            float(self.bck_flux)
        except ValueError:
            # check the background image
            if not os.path.isfile(config_util.getCONF(self.bck_flux)):
                err_msg = (
                    "\nThe background imagage is not available: {0:s}".format(
                        config_util.getCONF(self.bck_flux)))
                raise aXeSIMError(err_msg)
Exemplo n.º 4
0
    def tofits(self, fitsname, indata_copy=0):
        """
        Converts and stores the spectra in a fits file

        Converts all images stored in the class instance to a
        multi-extension fits image with a name gvien as input.
        A flagg indicates whether, besides the normal output to
        AXE_OUTSIM_PATH, a copy to AXE_IMAGE_PATH is desired.

        Parameters
        ----------
        fitsname: str
            name for the MEX fits file
        indata_copy: int
            flag to save also a copy
        """
        # create a HDU list
        hdulist = fits.HDUList()

        # create an empty primary HDU
        phdu = fits.PrimaryHDU()

        # put the primary to the list
        hdulist.append(phdu)

        # give a linefeed
        print()

        # check whther the fitsname
        # ends with '.fits'
        if ('.fits' not in fitsname[-5:]):
            fitsname += '.fits'

        # initialize an index
        index = 0

        # go over all spectra
        for ima in self._imalist:
            # enhance the counter
            index += 1

            # append the the image HDU
            # to the output fits
            hdulist.append(ima.imgHDU)

            # print what you do on the screen
            print("Adding: {0:s} to {1:s}, ext: {2:s}".format(
                os.path.basename(ima.filename), fitsname, str(index)))

        # delete older versions
        # of the fits name
        if os.path.isfile(getOUTSIM(fitsname)):
            os.unlink(getOUTSIM(fitsname))

        print("\nWriting images to file: {0:s} ...".format(
            getOUTSIM(fitsname)))
        # write it to fits
        hdulist.writeto(getOUTSIM(fitsname))
        # give an end notice
        print('Done')

        # check whether a copy
        # is needed at AXE_IMAGE_PATH directory
        if indata_copy:
            # delete older versions
            # of the fits name
            if os.path.isfile(getDATA(fitsname)):
                os.unlink(getDATA(fitsname))

            print("Writing images to file: {0:s} ...".format(
                getDATA(fitsname)))
            # write it to fits
            hdulist.writeto(getDATA(fitsname))
            # give an end notice
            print('Done')

        # add an extra linefeed
        print('')