Beispiel #1
0
    def cd(self, value):
        """
        Validates that the input CD matrix is a 2x2 2D array.

        """
        if np.shape(value) != (2, 2):
            raise InputParameterError("Expected CD matrix to be a 2x2 array")
Beispiel #2
0
    def __init__(self, modelname="MWRV31", **kwargs):

        if modelname not in self.possnames.keys():
            raise InputParameterError("modelname not recognized")
        filename = self.possnames[modelname][0]
        self.Rv = self.possnames[modelname][1]

        # get the tabulated information
        data_path = pkg_resources.resource_filename("dust_extinction", "data/")

        a = Table.read(
            data_path + filename,
            data_start=1,
            header_start=None,
            format="ascii.basic",
        )

        self.data_x = 1.0 / a["col1"].data

        # normalized by wavelength closest to V band
        sindxs = np.argsort(np.absolute(self.data_x - 1.0 / 0.55))

        self.data_axav = a["col10"].data / a["col10"].data[sindxs[0]]

        # accuracy of the data based on calculations
        self.data_tolerance = 1e-6

        super().__init__(**kwargs)
Beispiel #3
0
 def shift(self, value):
     """
     Validates that the shift vector is a 2D vector.  This allows
     either a "row" vector.
     """
     if not (np.ndim(value) == 1 and np.shape(value) == (2, )):
         raise InputParameterError(  # pragma: no cover
             "Expected 'shift' to be a 2 element row vector.")
Beispiel #4
0
    def matrix(self, value):
        """
        Validates that the input matrix is a 2x2 2D array.

        """

        if np.shape(value) != (2, 2):
            raise InputParameterError(
                "Expected transformation matrix to be a 2x2 array")
Beispiel #5
0
    def crpix(self, value):
        """
        Validates that the crpix vector is a 2D vector.  This allows
        either a "row" vector.

        """
        if not (np.ndim(value) == 1 and np.shape(value) == (2, )):
            raise InputParameterError(
                "Expected 'crpix' to be a 2 element row vector.")
Beispiel #6
0
    def Av(self, value):
        """
        Check that Av is in the valid range

        Parameters
        ----------
        value: float
            Av value to check

        Raises
        ------
        InputParameterError
           Input Av values outside of defined range
        """

        if (value < 0.0):
            raise InputParameterError("parameter Av must be positive")
Beispiel #7
0
    def ampl(self, value):
        """
        Check that ampl is in the valid range

        Parameters
        ----------
        value: float
            ampl value to check

        Raises
        ------
        InputParameterError
           Input ampl values outside of defined range
        """

        if value < 0.0:
            raise InputParameterError("parameter ampl must be positive")
Beispiel #8
0
    def fA(self, value):
        """
        Check that fA is in the valid range

        Parameters
        ----------
        value: float
            fA value to check

        Raises
        ------
        InputParameterError
           Input fA values outside of defined range
        """
        if not (self.fA_range[0] <= value <= self.fA_range[1]):
            raise InputParameterError("parameter fA must be between " +
                                      str(self.fA_range[0]) + " and " +
                                      str(self.fA_range[1]))
Beispiel #9
0
    def Rv(self, value):
        """
        Check that Rv is in the valid range

        Parameters
        ----------
        value: float
            R(V) value to check

        Raises
        ------
        InputParameterError
           Input Rv values outside of defined range
        """
        if not (self.Rv_range[0] <= value <= self.Rv_range[1]):
            raise InputParameterError("parameter Rv must be between " +
                                      str(self.Rv_range[0]) + " and " +
                                      str(self.Rv_range[1]))
Beispiel #10
0
    def slope(self, value):
        """
        Check that the slope is in the valid range

        Parameters
        ----------
        value: float
            slope value to check

        Raises
        ------
        InputParameterError
           Input slope values outside of defined range
        """

        if (value < -3.0) or (value > 3.0):
            raise InputParameterError("parameter slope must be between "
                                      "-3.0 and 3.0")
Beispiel #11
0
    def extinguish(self, x, Av=None, Ebv=None):
        """
        Calculate the extinction as a fraction

        Parameters
        ----------
        x: float
           expects either x in units of wavelengths or frequency
           or assumes wavelengths in wavenumbers [1/micron]

           internally wavenumbers are used

        Av: float
           A(V) value of dust column
           Av or Ebv must be set

        Ebv: float
           E(B-V) value of dust column
           Av or Ebv must be set

        Returns
        -------
        frac_ext: np array (float)
           fractional extinction as a function of x
        """
        # get the extinction curve
        axav = self(x)

        # check that av or ebv is set
        if (Av is None) and (Ebv is None):
            raise InputParameterError('neither Av or Ebv passed, one required')

        # if Av is not set and Ebv set, convert to Av
        if Av is None:
            Av = self.Rv * Ebv

        # return fractional extinction
        return np.power(10.0, -0.4 * axav * Av)