Ejemplo n.º 1
0
def test_blackbody_dimensionless():
    """Test support for dimensionless (but not unscaled) units for scale"""
    T = 3000 * u.K
    r = 1e14 * u.cm
    DL = 100 * u.Mpc
    scale = np.pi * (r / DL)**2

    bb1 = BlackBody(temperature=T, scale=scale)
    # even though we passed scale with units, we should be able to evaluate with unitless
    bb1.evaluate(0.5, T.value, scale.to_value(u.dimensionless_unscaled))

    bb2 = BlackBody(temperature=T, scale=scale.to_value(u.dimensionless_unscaled))
    bb2.evaluate(0.5, T.value, scale.to_value(u.dimensionless_unscaled))

    # bolometric flux for both cases should be equivalent
    assert(bb1.bolometric_flux == bb2.bolometric_flux)
Ejemplo n.º 2
0
def test_blackbody_return_units():
    # return of evaluate has no units when temperature has no units
    b = BlackBody(1000.0 * u.K, scale=1.0)
    assert not isinstance(b.evaluate(1.0 * u.micron, 1000.0, 1.0), u.Quantity)

    # return has "standard" units when scale has no units
    b = BlackBody(1000.0 * u.K, scale=1.0)
    assert isinstance(b(1.0 * u.micron), u.Quantity)
    assert b(1.0 * u.micron).unit == u.erg / (u.cm**2 * u.s * u.Hz * u.sr)

    # return has scale units when scale has units
    b = BlackBody(1000.0 * u.K, scale=1.0 * u.MJy / u.sr)
    assert isinstance(b(1.0 * u.micron), u.Quantity)
    assert b(1.0 * u.micron).unit == u.MJy / u.sr

    # scale has units but evaluate scale has no units
    assert_quantity_allclose(b.evaluate(1.0 * u.micron, 1000.0 * u.K, 4.0),
                             89668184.86321202 * u.MJy / u.sr)