Beispiel #1
0
    def _find_required_columns(self, columnList):
        """Search and store the index of a list of required columns

        The method searches for a list of column names given in the input.
        In case that the column does not ecist, an exception is thrown.
        The index of existing columns is written into a dictionary with the
        column name as key.

        @param columnList: list with required columns
        @type columnList: []
        """
        # go over all columns
        for aColumn in columnList:
            # find it
            colIndex = self.find(aColumn)

            # complain if not found
            if colIndex < 0:
                err_msg = (
                    "\nThe table: {0:s} does not contain column: {1}".format(
                        self.filename, aColumn))
                raise aXeSIMError(err_msg)
            else:
                # add the index to the dictionary
                self.reqColIndex[aColumn] = colIndex
Beispiel #2
0
    def find_magnitude_columns(self, mag_wavelength=None):
        """Identify all magnitude columns

        The method identifiy all magnitude columns and can select the
        one with the wavelength closest to a given input wavelength.
        An exception is thrown in case that no magnitude column is found.

        @param mag_wavelength: characteristic wavelength
        @type mag_wavelength: float
        """
        # search for
        # magnitude columns in general
        self.mag_cols = self._search_mcols()

        # if magnitude columns exist,
        # search the one closest to the
        # desired wavelength
        if len(self.mag_cols) > 0:
            if (mag_wavelength is not None):
                mag_index = self._identify_magcol(self.mag_cols,
                                                  mag_wavelength)
            else:
                mag_index = 0

            # set the column number and the wavelength
            self.magwave = float(self.mag_cols[mag_index][1])
            self.reqColIndex['MAGNITUDE'] = self.mag_cols[mag_index][0]
        else:
            # enhance the error counter
            err_msg = ("\nModel spectrum list: {0:s} does not contain any "
                       "magnitude column!".format(self.filename))
            raise aXeSIMError(err_msg)
Beispiel #3
0
    def __init__(self, inlist):
        """Initializer for the class

        Parameters
        ----------
        inlist: str
            name of list with the fits images
        """
        # initialize the list of spectra
        self._imalist = []

        # load the list with input images
        ilist = axe_asciidata.open(inlist)

        # go over the image names
        for item in ilist[0]:

            # check whether the file is there
            if not os.path.isfile(getSIMDATA(item)):
                error_message = ("\nDid not find image: {0:s} !!".format(
                    str(getSIMDATA(item))))
                raise aXeSIMError(error_message)

            # apend the fits to the liast
            self._imalist.append(ArtImage(getSIMDATA(item.strip())))
Beispiel #4
0
    def _basic_checks(self):
        """Do some fundamental checks"""
        # this check should be removed
        # at some time.....
        # check that there is at leas one row
        if self.nrows < 1:
            err_msg = ("\nThe table: {0:s} must contain at least one row!"
                       .format(self.filename))
            raise aXeSIMError(err_msg)

        # this check should be removed
        # at some time.....
        # check that there is at leas one row
        if (len(self.header) > 0):
            err_msg = ("\nThe table: {0:s} must not contain header comments!"
                       .format(self.filename))
            raise aXeSIMError(err_msg)
Beispiel #5
0
    def fill_columns(self, WCSimage, WCSext=None):
        """Fill up column information to be ready for aXe

        The method completes the model object tables with columns
        requested by aXe.

        Parameters
        ----------
        WCSimage: str
            the reference image with WCS
        WCSext: str
            the extension to use


        ra_dec = iraf.xy2rd(infile=WCSimage, x=self['X_IMAGE'][index],\
                            y=, hms='NO', Stdout=1)
        """

        # check that the image exists
        if not os.path.isfile(WCSimage):
            err_msg = "The WCS image: {0:s} does not exist!".format(WCSimage)
            raise aXeSIMError(err_msg)

        # append the image extesnion
        if WCSext is not None:
            WCSimage = fits.getheader(WCSimage, ext=WCSext)
        else:
            WCSimage = fits.getheader(WCSimage)

        # go over all rows
        for index in range(self.nrows):

            # just copy some information
            # later it would be reasonable
            # to give more reasonable values
            self['A_WORLD'][index] = self['A_IMAGE'][index]
            self['B_WORLD'][index] = self['B_IMAGE'][index]
            self['THETA_WORLD'][index] = self['THETA_IMAGE'][index]

            # transform x,y to ra and dec
            ra, dec = WCSimage.all_world2pix(self['Y_IMAGE'][index],
                                             self['X_IMAGE'][index])

            # store ra and dec
            self['X_WORLD'][index] = float(ra)
            self['Y_WORLD'][index] = float(dec)

        # save the changes
        self.flush()
Beispiel #6
0
    def check_simdirim_input(self, incat, config, tpass_direct, model_spectra,
                             model_images, nx, ny, exptime, bck_flux):
        """Does basic checks on the parameters

        The method checks whether all input values are reasonable, e.g.
        the exposure time and background flux >= 0.0 and similar.
        Input files are checked for existence. Also the input type is
        checked for the numbers.

        Parameters
        ----------
        incat: str
            name of model object table
        config: str
            aXe configuration file name
        tpass_direct: str
            total passband file
        model_spectra: str
            name of model spectra
        model_images: str
            name of model images
        nx: int
            number of pixels in x
        ny: int
            number of pixels in y
        exptime: float
            exposure time
        bck_flux: float
            flux in background
        """

        # do the setup
        config_util.axe_setup(axesim=True)

        # check the existence of the
        # model object table
        if not os.path.isfile(config_util.getDATA(incat)):
            error_message = (
                "The Model Object Table does not exist: {0}".format(
                    config_util.getDATA(incat)))
            raise aXeSIMError(error_message)

        # check the existence of the
        # axe configuration file
        if not os.path.isfile(config_util.getCONF(config)):
            error_message = (
                "The aXe configuration file does not exist: {0}".format(
                    config_util.getCONF(config)))
            raise aXeSIMError(error_message)

        else:
            # load the aXe configuration file
            conf = configfile.ConfigFile(config_util.getCONF(config))

            # make the internal checks
            n_sens = conf.check_files(check_glob=False)

            # make sure there is
            # at least one sens. file
            if n_sens < 1:
                error_message = ("There must be at least one sensitivity "
                                 "file in: {0}".format(
                                     config_util.getCONF(config)))
                raise aXeSIMError(error_message)

        # check the existence of the
        # total passband file
        if not os.path.isfile(config_util.getSIMDATA(tpass_direct)):
            error_message = (
                "The total passband file does not exist: {0}".format(
                    config_util.getSIMDATA(tpass_direct)))
            raise aXeSIMError(error_message)

        if model_spectra is not None:
            # check the existence of the
            # model spectra file
            if not os.path.isfile(config_util.getDATA(model_spectra)):
                error_message = (
                    "The model spectra file does not exist: {0}".format(
                        config_util.getDATA(config)))
                raise aXeSIMError(error_message)

        if model_images is not None:
            # check the existence of the
            # model images file
            if not os.path.isfile(config_util.getDATA(model_images)):
                error_message = (
                    "The model images file does not exist: {0}".format(
                        config_util.getDATA(config)))
                raise aXeSIMError(error_message)

        # check the nx-value
        if ((nx is not None) and (nx <= 0.0)):
            error_message = ("Value for 'nx' or 'nx_dir' must be positive: "
                             "{0:s}".format(str(nx)))
            raise aXeSIMError(error_message)

        # check the ny-value
        if ((ny is not None) and (ny <= 0)):
            error_message = ("Value for 'ny' or 'ny_dir' must be positive: "
                             "{0:s}".format(str(ny)))
            raise aXeSIMError(error_message)

        # check the exptime-value
        if ((exptime is not None) and (exptime < 0)):
            error_message = ("Value for 'exptime' or 'exptime_dir' must be "
                             "positive: {0:s}".format(str(exptime)))
            raise aXeSIMError(error_message)

        if bck_flux is not None:
            # check the bck_flux-value
            try:
                # convert to float
                bck = float(bck_flux)

                # check for positive value
                if bck < 0:
                    error_message = ("Value for 'bck_flux' or 'bck_flux_dir'"
                                     " must be positive: {0:s}".format(
                                         str(bck_flux)))
                    raise aXeSIMError(error_message)

                # catch a string
            except ValueError:
                # check for existence of file
                if not os.path.isfile(config_util.getCONF(bck_flux)):
                    error_message = (
                        "The background file does not exist: {0}".format(
                            config_util.getCONF(bck_flux)))
                    raise aXeSIMError(error_message)
Beispiel #7
0
    def check_simdispim_input(self, incat, config, lambda_psf, model_spectra,
                              model_images, nx, ny, exptime, bck_flux,
                              extraction, extrfwhm, orient, slitless_geom,
                              adj_sens):
        """Does basic checks on the parameters

        The method checks whether all input values are reasonable, e.g.
        the exposure time and background flux >= 0.0 and similar.
        Input files are checked for existence. Also the input type is
        checked for the numbers.

        Parameters
        ----------
        incat: str
            name of model object table
        config: str
            aXe configuration file name
        lambda_psf: float
            wavelength the object shapes were determined at
        model_spectra: str
            name of model spectra
        model_images: str
            name of model images
        nx: int
            number of pixels in x
        ny: int
            number of pixels in y
        exptime: float
            exposure time
        bck_flux: float
            flux in background
        extraction: bool
            flag for default extraction
        extrfwhm: float
            multiplier for extraction width
        orient: bool
            flag for tilted extraction
        slitless_geom: bool
            flag for slitless optimized extraction
        adj_sens: bool
            flag for adjusted flux conversion
        """

        # do the setup
        config_util.axe_setup(axesim=True)

        # check the existence of the
        # model object table
        if not os.path.isfile(config_util.getDATA(incat)):
            msg = ("The Model Object Table does not exist: {}".format(
                config_util.getDATA(incat)))
            raise aXeSIMError(msg)

        # check the existence of the
        # axe configuration file
        if not os.path.isfile(config_util.getCONF(config)):
            msg = ("The aXe configuration file does not exist: {}".format(
                config_util.getCONF(config)))
            raise aXeSIMError(msg)

        else:
            # load the aXe configuration file
            conf = configfile.ConfigFile(config_util.getCONF(config))

            # make the internal checks
            n_sens = conf.check_files(check_glob=False)

            # make sure there is
            # at least one sens. file
            if n_sens < 1:
                msg = ("There must be at least one sensitivity file in: {}".
                       format(config_util.getCONF(config)))
                raise aXeSIMError(msg)

        # check whether the configuration files
        # allows the requested extraction
        if extraction and (slitless_geom or adj_sens):
            extr_ready = conf.confirm_extrkeys()

            # error and out
            if not extr_ready:
                msg = ("It is not possible to perform the requested"
                       "extraction. The likely cause is that the configuration"
                       "file does NOT contain the keywords 'POBJSIZE' or "
                       "'SMFACTOR' or their values are NOT reasonable "
                       "(e.g. <0.0)!")
                raise aXeSIMError(msg)

        # check the lambda_psf-value
        if ((lambda_psf is not None) and (lambda_psf <= 0.0)):
            msg = ("Value for 'lambda_psf' must be positive: {0:s}".format(
                str(lambda_psf)))
            raise aXeSIMError(msg)

        if (model_spectra is not None):
            # check the existence of the
            # model spectra file
            if not os.path.isfile(config_util.getDATA(model_spectra)):
                msg = ("The model spectra file does not exist: {}".format(
                    config_util.getDATA(model_spectra)))
                raise aXeSIMError(msg)

        if model_images is not None:
            # check the existence of the
            # model images file
            if not os.path.isfile(config_util.getDATA(model_images)):
                msg = ("The model images file does not exist: ".format(
                    config_util.getDATA(model_images)))
                raise aXeSIMError(msg)

        # check the nx-value
        if ((nx is not None) and (nx <= 0.0)):
            msg = ("Value for 'nx' or 'nx_disp' must be positive: {0:g}".
                   format(nx))
            raise aXeSIMError(msg)

        # check the ny-value
        if ((ny is not None) and (ny <= 0)):
            error_message = ("Value for 'ny' or 'ny_disp' must be "
                             "positive: {0:g}".format(ny))
            raise aXeSIMError(error_message)

        # check the exptime-value
        if ((exptime is not None) and (exptime < 0)):
            error_message = ("Value for 'exptime' or 'exptime_disp' must be "
                             "positive: {0:g}".format(exptime))
            raise aXeSIMError(error_message)

        # the extraction width must be set!
        if not extrfwhm:
            error_message = ("Value for 'extrfwhm' must not be 0.0 to create"
                             "PETs, but extrfwhm={0:0.1f}!".format(extrfwhm))
            raise aXeSIMError(error_message)

        # negative extraction width is significant ONLY
        # if orient="NO"
        if orient and extrfwhm < 0.0:
            error_message = (
                "Negative width extrfwhm={0:0.1f} together with "
                "extraction orient=yes does NOT make sense!".format(extrfwhm))
            raise aXeSIMError(error_message)

        try:
            # convert to float
            bck = float(bck_flux)

            # check for positive value
            if bck < 0:
                error_message = ("Value for 'bck_flux' or 'bck_flux_disp'"
                                 " most be positive: {0:g}".format(bck_flux))
                raise aXeSIMError(error_message)

        # catch a string
        except ValueError:
            # check for existence of file
            if not os.path.isfile(config_util.getCONF(bck_flux)):
                error_message = (
                    "The background file does not exist: {0}".format(
                        config_util.getCONF(bck_flux)))
                raise aXeSIMError(error_message)