Beispiel #1
0
    def test_planck(self):
        import astropy.units as u
        import astropy.constants as const

        wave = np.logspace(-1, 3, 10000) * u.um
        I = util.planck(wave, 300, unit=u.Unit('W/(m2 um sr)'))
        assert allclose(wave[I.value.argmax()], 2.8977685e3 / 300, rtol=1e-3)

        F = (util.davint(wave.value, I.value, wave.value[0], wave.value[-1])
             * np.pi)
        assert allclose(F, const.sigma_sb.si.value * 300.**4, rtol=1e-5)
Beispiel #2
0
    def test_irac(self, test=True):
        import astropy.units as u
        from mskpy.util import planck
        from mskpy.instruments import IRAC

        irac = IRAC()

        # Color correction standard values from the IRAC Instrument
        # Handbook.  Those calculations are good to ~1%.
        templates = dict(
            nu_2 = (lambda w: w.value**2 * u.Jy,
                    [1.0037, 1.0040, 1.0052, 1.0111], 0.015),
            nu_1 = (lambda w: w.value**1 * u.Jy,
                    [1.0, 1.0, 1.0, 1.0], 0.015),
            nu0 = (lambda w: w.value**0 * u.Jy,
                   [1.0, 1.0, 1.0, 1.0], 0.015),
            nu1 = (lambda w: w.value**-1 * u.Jy,
                   [1.0037, 1.0040, 1.0052, 1.0113], 0.015),
            nu2 = (lambda w: w.value**-2 * u.Jy,
                   [1.0111, 1.0121, 1.0155, 1.0337], 0.015),
            bb5000 = (lambda x: planck(x, 5000., unit=u.Jy / u.sr) * u.sr,
                      [1.0063, 1.0080, 1.0114, 1.0269], 0.015),
            bb2000 = (lambda x: planck(x, 2000., unit=u.Jy / u.sr) * u.sr,
                      [0.9990, 1.0015, 1.0048, 1.0163], 0.015),
            bb1500 = (lambda x: planck(x, 1500., unit=u.Jy / u.sr) * u.sr,
                      [0.9959, 0.9983, 1.0012, 1.0112], 0.015),
            bb1000 = (lambda x: planck(x, 1000., unit=u.Jy / u.sr) * u.sr,
                      [0.9933, 0.9938, 0.9952, 1.0001], 0.015),
            bb800 = (lambda x: planck(x, 800., unit=u.Jy / u.sr) * u.sr,
                     [0.9953, 0.9927, 0.9921, 0.9928], 0.015),
            bb600 = (lambda x: planck(x, 600., unit=u.Jy / u.sr) * u.sr,
                     [1.0068, 0.9961, 0.9907, 0.9839], 0.015),
            bb400 = (lambda x: planck(x, 400., unit=u.Jy / u.sr) * u.sr,
                     [1.0614, 1.0240, 1.0042, 0.9818], 0.015),
            bb200 = (lambda x: planck(x, 200., unit=u.Jy / u.sr) * u.sr,
                     [1.5138, 1.2929, 1.1717, 1.1215], 0.03)
            )

        for k, v in templates.items():
            f, K0, rtol = templates[k]
            K = irac.ccorrection(f)
            print k, (K - K0) / K0
            if test:
                assert np.allclose(K, K0, rtol=rtol)
Beispiel #3
0
    def test_irac(self, test=True):
        import astropy.units as u
        from mskpy.util import planck
        from mskpy.instruments import IRAC

        irac = IRAC()

        # Color correction standard values from the IRAC Instrument
        # Handbook.  Those calculations are good to ~1%.
        templates = dict(
            nu_2 = (lambda w: w.value**2 * u.Jy,
                    [1.0037, 1.0040, 1.0052, 1.0111], 0.015),
            nu_1 = (lambda w: w.value**1 * u.Jy,
                    [1.0, 1.0, 1.0, 1.0], 0.015),
            nu0 = (lambda w: w.value**0 * u.Jy,
                   [1.0, 1.0, 1.0, 1.0], 0.015),
            nu1 = (lambda w: w.value**-1 * u.Jy,
                   [1.0037, 1.0040, 1.0052, 1.0113], 0.015),
            nu2 = (lambda w: w.value**-2 * u.Jy,
                   [1.0111, 1.0121, 1.0155, 1.0337], 0.015),
            bb5000 = (lambda x: planck(x, 5000., unit=u.Jy / u.sr) * u.sr,
                      [1.0063, 1.0080, 1.0114, 1.0269], 0.015),
            bb2000 = (lambda x: planck(x, 2000., unit=u.Jy / u.sr) * u.sr,
                      [0.9990, 1.0015, 1.0048, 1.0163], 0.015),
            bb1500 = (lambda x: planck(x, 1500., unit=u.Jy / u.sr) * u.sr,
                      [0.9959, 0.9983, 1.0012, 1.0112], 0.015),
            bb1000 = (lambda x: planck(x, 1000., unit=u.Jy / u.sr) * u.sr,
                      [0.9933, 0.9938, 0.9952, 1.0001], 0.015),
            bb800 = (lambda x: planck(x, 800., unit=u.Jy / u.sr) * u.sr,
                     [0.9953, 0.9927, 0.9921, 0.9928], 0.015),
            bb600 = (lambda x: planck(x, 600., unit=u.Jy / u.sr) * u.sr,
                     [1.0068, 0.9961, 0.9907, 0.9839], 0.015),
            bb400 = (lambda x: planck(x, 400., unit=u.Jy / u.sr) * u.sr,
                     [1.0614, 1.0240, 1.0042, 0.9818], 0.015),
            bb200 = (lambda x: planck(x, 200., unit=u.Jy / u.sr) * u.sr,
                     [1.5138, 1.2929, 1.1717, 1.1215], 0.03)
            )

        for k, v in templates.items():
            f, K0, rtol = templates[k]
            K = irac.ccorrection(f)
            print(k, (K - K0) / K0)
            if test:
                assert np.allclose(K, K0, rtol=rtol)
Beispiel #4
0
    def __call__(self, p=None, composition=None, **kwargs):
        """Evaluate the scaler.

        Requires `radius`, `rh_f`, `Delta`, and `composition`.  If
        `self.composition` is defined, then it takes precedence.

        """
        from mskpy.util import planck
        from . import particle

        gtm_filename = {'amorphouscarbon': 'am-carbon.fits',
                        'amorphousolivine50': 'am-olivine50.fits'}

        if self.composition is None:
            if p is not None:
                composition = p.params['pfunc']['composition'].split('(')[0]
            else:
                composition = str(composition).split('(')[0]
        else:
            composition = str(self.composition).split('(')[0]
        composition = composition.lower().strip()

        try:
            radius, rh_f, Delta = self._get(
                ('radius', 'rh_f', 'Delta'), p, kwargs)
        except KeyError:
            return 1.0
        
        if composition in gtm_filename:
            from dust import readgtm, gtmInterp
            from scipy import interpolate
            from scipy.interpolate import splrep, splev
            gtm = readgtm(gtm_filename[composition])
            T = np.zeros_like(radius)
            rh = np.median(rh_f)

            T_rh = np.zeros_like(gtm[2])
            for i in range(len(gtm[2])):
                T_rh[i] = splev(rh, splrep(gtm[3], gtm[0][0, i]))

            T = splev(radius, splrep(gtm[2], T_rh))
        else:
            if self.require_grain_model:
                raise MissingGrainModel

            T = 278. / np.sqrt(rh_f)
        
        radius = np.array(radius)
        if radius.ndim == 0:
            radius = radius[np.newaxis]

        Q = np.ones_like(radius)
        k = self.wave / 2 / np.pi
        
        i = radius < k
        if any(i):
            Q[i] = radius[i] / k
            
        sigma = np.pi * (radius * 1e-9)**2  # km**2
        B = planck(self.wave, T, unit=u.Unit(self.unit) / u.sr).value
        
        return Q * sigma * B / Delta**2