Ejemplo n.º 1
0
    def initialize(self, wngrid):
        """
        Initializes the blackbody spectrum on the given wavenumber grid

        Parameters
        ----------
        wngrid: :obj:`array`
            Wavenumber grid cm-1 to compute black body spectrum

        """
        self.sed = black_body(wngrid, self.temperature)
Ejemplo n.º 2
0
def test_blackbody(temperature):
    wngrid = np.linspace(200, 30000, 200)

    bb = black_body(wngrid, temperature)/np.pi

    bb_as = BlackBody(temperature=temperature * u.K)
    expect_flux = bb_as(wngrid * u.k).to(u.W/u.m**2/u.micron/u.sr,
                                         equivalencies=u.spectral_density(
                                                     wngrid*u.k))

    assert bb == pytest.approx(expect_flux.value, rel=1e-3)
Ejemplo n.º 3
0
    def evaluate_emission(self, wngrid, return_contrib):
        from taurex.util.util import compute_dz

        if self.usingKTables:
            return self.evaluate_emission_ktables(wngrid, return_contrib)

        dz = self.deltaz

        total_layers = self.nLayers

        density = self.densityProfile

        wngrid_size = wngrid.shape[0]

        temperature = self.temperatureProfile
        tau = np.zeros(shape=(self.nLayers, wngrid_size))
        surface_tau = np.zeros(shape=(1, wngrid_size))

        layer_tau = np.zeros(shape=(1, wngrid_size))

        dtau = np.zeros(shape=(1, wngrid_size))

        # Do surface first
        # for layer in range(total_layers):
        for contrib in self.contribution_list:
            contrib.contribute(self,
                               0,
                               total_layers,
                               0,
                               0,
                               density,
                               surface_tau,
                               path_length=dz)
        self.debug('density = %s', density[0])
        self.debug('surface_tau = %s', surface_tau)

        BB = black_body(wngrid, temperature[0]) / PI

        _mu = 1.0 / self._mu_quads[:, None]
        _w = self._wi_quads[:, None]
        I = BB * (np.exp(-surface_tau * _mu))

        self.debug('I1_pre %s', I)
        # Loop upwards
        for layer in range(total_layers):
            layer_tau[...] = 0.0
            dtau[...] = 0.0
            for contrib in self.contribution_list:
                contrib.contribute(self,
                                   layer + 1,
                                   total_layers,
                                   0,
                                   0,
                                   density,
                                   layer_tau,
                                   path_length=dz)
                contrib.contribute(self,
                                   layer,
                                   layer + 1,
                                   0,
                                   0,
                                   density,
                                   dtau,
                                   path_length=dz)
            # for contrib in self.contribution_list:

            self.debug('Layer_tau[%s]=%s', layer, layer_tau)

            dtau += layer_tau

            dtau_calc = 0.0
            if dtau.min() < self._clamp:
                dtau_calc = np.exp(-dtau)
            layer_tau_calc = 0.0
            if layer_tau.min() < self._clamp:
                layer_tau_calc = np.exp(-layer_tau)

            _tau = layer_tau_calc - dtau_calc

            if isinstance(_tau, float):
                tau[layer] += _tau
            else:
                tau[layer] += _tau[0]

            self.debug('dtau[%s]=%s', layer, dtau)
            BB = black_body(wngrid, temperature[layer]) / PI
            self.debug('BB[%s]=%s,%s', layer, temperature[layer], BB)

            dtau_calc = 0.0
            if dtau.min() < self._clamp:
                dtau_calc = np.exp(-dtau * _mu)
            layer_tau_calc = 0.0
            if layer_tau.min() < self._clamp:
                layer_tau_calc = np.exp(-layer_tau * _mu)

            I += BB * (layer_tau_calc - dtau_calc)

        self.debug('I: %s', I)

        return I, _mu, _w, tau
Ejemplo n.º 4
0
    def evaluate_emission_ktables(self, wngrid, return_contrib):

        from taurex.util.util import compute_dz
        from taurex.contributions import AbsorptionContribution

        dz = compute_dz(self.altitudeProfile)
        total_layers = self.nLayers
        density = self.densityProfile
        wngrid_size = wngrid.shape[0]
        temperature = self.temperatureProfile
        tau = np.zeros(shape=(self.nLayers, wngrid_size))
        surface_tau = np.zeros(shape=(1, wngrid_size))
        layer_tau = np.zeros(shape=(1, wngrid_size))
        tmp_tau = np.zeros(shape=(1, wngrid_size))
        dtau = np.zeros(shape=(1, wngrid_size))

        mol_type = AbsorptionContribution

        non_molecule_absorption = \
            [c for c in self.contribution_list
             if not isinstance(c, mol_type)]
        contrib_types = [type(c) for c in self.contribution_list]
        molecule_absorption = None
        if mol_type in contrib_types:
            molecule_absorption = \
                self.contribution_list[contrib_types.index(mol_type)]

        _mu = 1.0 / self._mu_quads[:, None]
        _w = self._wi_quads[:, None]

        # Do surface first
        # for layer in range(total_layers):
        for contrib in non_molecule_absorption:
            contrib.contribute(self,
                               0,
                               total_layers,
                               0,
                               0,
                               density,
                               surface_tau,
                               path_length=dz)

        surface_tau = surface_tau * _mu
        if molecule_absorption is not None:
            for idx, m in enumerate(_mu):
                tmp_tau[...] = 0.0
                molecule_absorption.contribute(self,
                                               0,
                                               total_layers,
                                               0,
                                               0,
                                               density,
                                               tmp_tau,
                                               path_length=dz * m)
                surface_tau[idx] += tmp_tau[0]

        self.debug('density = %s', density[0])
        self.debug('surface_tau = %s', surface_tau)

        BB = black_body(wngrid, temperature[0]) / PI

        I = BB * (np.exp(-surface_tau))

        for layer in range(total_layers):
            layer_tau[...] = 0.0
            dtau[...] = 0.0
            for contrib in non_molecule_absorption:
                contrib.contribute(self,
                                   layer + 1,
                                   total_layers,
                                   0,
                                   0,
                                   density,
                                   layer_tau,
                                   path_length=dz)
                contrib.contribute(self,
                                   layer,
                                   layer + 1,
                                   0,
                                   0,
                                   density,
                                   dtau,
                                   path_length=dz)

            k_dtau = None
            k_layer = None
            wg = None
            if molecule_absorption is not None:
                wg = molecule_absorption.weights
                ng = len(wg)
                sigma = molecule_absorption.sigma_xsec

                k_layer = contribute_ktau_emission(layer + 1, total_layers, 0,
                                                   sigma, density, dz, wg,
                                                   wngrid_size, 0, ng)

                k_dtau = contribute_ktau_emission(layer, layer + 1, 0, sigma,
                                                  density, dz, wg, wngrid_size,
                                                  0, ng)
                k_dtau += k_layer

            dtau += layer_tau

            self.debug('dtau[%s]=%s', layer, dtau)
            BB = black_body(wngrid, temperature[layer]) / PI
            self.debug('BB[%s]=%s,%s', layer, temperature[layer], BB)

            dtau_calc = np.exp(-dtau * _mu)
            layer_tau_calc = np.exp(-layer_tau * _mu)

            if molecule_absorption is not None:
                dtau_calc *= np.sum(np.exp(-k_dtau * _mu[:, None]) * wg,
                                    axis=-1)
                layer_tau_calc *= np.sum(np.exp(-k_layer * _mu[:, None]) * wg,
                                         axis=-1)

            I += BB * (layer_tau_calc - dtau_calc)

            dtau_calc = 0.0
            if dtau.min() < self._clamp:
                dtau_calc = np.exp(-dtau)
            layer_tau_calc = 0.0
            if layer_tau.min() < self._clamp:
                layer_tau_calc = np.exp(-layer_tau)

            if molecule_absorption is not None:

                if k_dtau.min() < self._clamp:
                    dtau_calc *= np.sum(np.exp(-k_dtau) * wg, axis=-1)
                if k_layer.min() < self._clamp:
                    layer_tau_calc *= np.sum(np.exp(-k_layer) * wg, axis=-1)

            _tau = layer_tau_calc - dtau_calc

            if isinstance(_tau, float):
                tau[layer] += _tau
            else:
                tau[layer] += _tau[0]

        self.debug('I: %s', I)

        return I, _mu, _w, tau
Ejemplo n.º 5
0
    def path_integral(self, wngrid, return_contrib):
        dz = np.gradient(self.altitudeProfile)

        density = self.densityProfile

        wngrid_size = wngrid.shape[0]

        total_layers = self.nLayers

        temperature = self.temperatureProfile
        tau = np.zeros(shape=(self.nLayers, wngrid_size))
        surface_tau = np.zeros(shape=(1, wngrid_size))

        layer_tau = np.zeros(shape=(1, wngrid_size))

        dtau = np.zeros(shape=(1, wngrid_size))

        # Do surface first
        # for layer in range(total_layers):
        for contrib in self.contribution_list:
            contrib.contribute(self,
                               0,
                               total_layers,
                               0,
                               0,
                               density,
                               surface_tau,
                               path_length=dz)
        self.debug('density = %s', density[0])
        self.debug('surface_tau = %s', surface_tau)

        BB = black_body(wngrid, temperature[0]) / PI

        _mu = 1.0 / self._mu_quads[:, None]
        _w = self._wi_quads[:, None]
        I = BB * (np.exp(-surface_tau * _mu))

        self.debug('I1_pre %s', I)
        # Loop upwards
        for layer in range(total_layers):
            layer_tau[...] = 0.0
            dtau[...] = 0.0
            for contrib in self.contribution_list:
                contrib.contribute(self,
                                   layer + 1,
                                   total_layers,
                                   0,
                                   0,
                                   density,
                                   layer_tau,
                                   path_length=dz)
                contrib.contribute(self,
                                   layer,
                                   layer + 1,
                                   0,
                                   0,
                                   density,
                                   dtau,
                                   path_length=dz)

            _tau = np.exp(-layer_tau) - np.exp(-dtau)

            tau[layer] += _tau[0]
            # for contrib in self.contribution_list:

            self.debug('Layer_tau[%s]=%s', layer, layer_tau)

            dtau += layer_tau
            self.debug('dtau[%s]=%s', layer, dtau)
            BB = black_body(wngrid, temperature[layer]) / PI
            self.debug('BB[%s]=%s,%s', layer, temperature[layer], BB)
            I += BB * (np.exp(-layer_tau * _mu) - np.exp(-dtau * _mu))

        self.debug('I: %s', I)

        flux_total = 2.0 * np.pi * sum(I * (_w / _mu))
        self.debug('flux_total %s', flux_total)

        return self.compute_final_flux(flux_total).flatten(), tau
 def integrate_nlayers():
     for n in range(NLAYERS):
         integrate_emission_layer(dtau, ltau, mu, black_body(wngrid, T[n]))