コード例 #1
0
ファイル: test_rami4atm.py プロジェクト: nollety/eradiate
def test_ramiatm_experiment_surface_adjustment(mode_mono):
    """Create a Rami4ATM experiment and assert the central patch surface is created with the
    correct parameters, according to the canopy and atmosphere."""
    from mitsuba.core import ScalarTransform4f

    ctx = KernelDictContext()

    s = Rami4ATMExperiment(
        atmosphere=HomogeneousAtmosphere(width=ureg.Quantity(42.0, "km")),
        canopy=DiscreteCanopy.homogeneous(
            lai=3.0,
            leaf_radius=0.1 * ureg.m,
            l_horizontal=10.0 * ureg.m,
            l_vertical=2.0 * ureg.m,
            padding=0,
        ),
        surface=CentralPatchSurface(central_patch=LambertianSurface(),
                                    background_surface=LambertianSurface()),
    )

    expected_trafo = ScalarTransform4f.scale(
        1400) * ScalarTransform4f.translate((-0.499642857, -0.499642857, 0.0))

    kernel_dict = s.kernel_dict(ctx=ctx)

    assert np.allclose(kernel_dict["bsdf_surface"]["weight"]["to_uv"].matrix,
                       expected_trafo.matrix)
コード例 #2
0
def test_ckd_basic(modes_all_ckd):
    """
    CKD correctness check
    =====================

    We check for correctness when using CKD modes with atmosphere-free scenes.
    This test is designed to check that the CKD infrastructure
    (preprocessing, spectral loop, postprocessing) works.
    """

    # Configure experiment, run and postprocess results
    exp = OneDimExperiment(
        atmosphere=None,
        surface=LambertianSurface(reflectance=1.0),
        measures=[
            MultiDistantMeasure.from_viewing_angles(
                zeniths=np.arange(-60, 61, 5) * ureg.deg,
                azimuths=0.0 * ureg.deg,
                spectral_cfg={
                    "bin_set": "10nm",
                    "bins": [
                        "550",
                        "560",
                        "570",
                        "510",
                    ],  # We specify bins in arbitrary order on purpose
                },
            )
        ],
    )
    exp.run()

    # Reflectance is uniform, equal to 1
    assert np.allclose(exp.results["measure"].data_vars["brf"], 1.0)
コード例 #3
0
ファイル: test_lambertian.py プロジェクト: nollety/eradiate
def test_lambertian(mode_mono):
    ctx = KernelDictContext()

    # Default constructor
    ls = LambertianSurface()

    # Check if produced scene can be instantiated
    kernel_dict = KernelDict.from_elements(ls, ctx=ctx)
    assert kernel_dict.load() is not None

    # Constructor with arguments
    ls = LambertianSurface(width=1000.0,
                           reflectance={
                               "type": "uniform",
                               "value": 0.3
                           })

    # Check if produced scene can be instantiated
    assert KernelDict.from_elements(ls, ctx=ctx).load() is not None
コード例 #4
0
def test_spectral_loop(mode_mono, cls, wavelengths, irradiance):
    """
    Spectral loop
    =============

    This test case checks if the spectral loop implementation and
    post-processing behaves as intended.

    Rationale
    ---------

    The scene consists of a square Lambertian surface with reflectance
    :math:`\\rho = 1` illuminated by a directional emitter positioned at the
    zenith. The reflected radiance is computed in monochromatic mode for a
    single wavelength and for multiple wavelength. The experiment is repeated:

    * for all solver applications supporting this type of scene;
    * for several spectral configurations (single wavenlength, multiple
      ascending, multiple descending);
    * for several irradiance spectra (uniform, solar).

    Expected behaviour
    ------------------

    All BRF values are equal to 1.
    """
    if cls == "onedim":
        cls_exp = OneDimExperiment
        kwargs = {"atmosphere": None}
    elif cls == "rami":
        cls_exp = RamiExperiment
        kwargs = {"canopy": None}
    else:
        raise ValueError

    if irradiance == "uniform":
        illumination = DirectionalIllumination(irradiance=1.0)
    elif irradiance == "solar":
        illumination = DirectionalIllumination(
            irradiance=SolarIrradianceSpectrum())

    exp = cls_exp(
        surface=LambertianSurface(reflectance=1.0),
        illumination=illumination,
        measures=[
            MultiDistantMeasure(
                spp=1,
                spectral_cfg={"wavelengths": wavelengths},
            )
        ],
        **kwargs,
    )

    exp.run()
    assert np.allclose(np.squeeze(exp.results["measure"].brf.values), 1.0)
コード例 #5
0
def test_centralpatch_compute_scale(modes_all_double):
    ctx = KernelDictContext()
    cs = CentralPatchSurface(width=10 * ureg.m,
                             central_patch=LambertianSurface(width=1 * ureg.m))

    scale = cs._compute_scale_parameter(ctx=ctx)

    assert np.allclose(scale, 3.33333333)

    ctx = ctx.evolve(override_canopy_width=2 * ureg.m)
    scale = cs._compute_scale_parameter(ctx=ctx)
    assert np.allclose(scale, 1.6666666666667)
コード例 #6
0
def test_centralpatch_instantiate(mode_mono):
    ctx = KernelDictContext()

    # Default constructor
    cs = CentralPatchSurface()

    # Check if produced scene can be instantiated
    kernel_dict = KernelDict.from_elements(cs, ctx=ctx)
    assert kernel_dict.load() is not None

    # background width must be AUTO
    with pytest.raises(ValueError):
        cs = CentralPatchSurface(
            width=1000.0,
            central_patch=LambertianSurface(reflectance={
                "type": "uniform",
                "value": 0.3
            }),
            background_surface=LambertianSurface(reflectance={
                "type": "uniform",
                "value": 0.3
            },
                                                 width=10 * ureg.m),
        )

    # Constructor with arguments
    cs = CentralPatchSurface(
        width=1000.0,
        central_patch=LambertianSurface(reflectance={
            "type": "uniform",
            "value": 0.3
        }),
        background_surface=LambertianSurface(reflectance={
            "type": "uniform",
            "value": 0.8
        }),
    )

    # Check if produced scene can be instantiated
    assert KernelDict.from_elements(cs, ctx=ctx).load() is not None
コード例 #7
0
def test_black(mode_mono):
    ctx = KernelDictContext()

    # Default constructor
    bs = BlackSurface()

    # Check if produced scene can be instantiated
    kernel_dict = KernelDict.from_elements(bs, ctx=ctx)
    assert kernel_dict.load() is not None

    # Check if the correct kernel dict is created
    ls = LambertianSurface(reflectance={"type": "uniform", "value": 0})

    assert KernelDict.from_elements(ls, ctx=ctx) == KernelDict.from_elements(
        bs, ctx=ctx
    )
コード例 #8
0
def test_centralpatch_scale_kernel_dict(mode_mono):
    from mitsuba.core import ScalarTransform4f

    cs = CentralPatchSurface(
        width=3000.0 * ureg.km,
        central_patch=LambertianSurface(width=100 * ureg.km),
        id="surface",
    )

    ctx = KernelDictContext()

    kernel_dict = cs.bsdfs(ctx=ctx)

    assert np.allclose(
        kernel_dict["bsdf_surface"]["weight"]["to_uv"].matrix,
        (ScalarTransform4f.scale(10) * ScalarTransform4f.translate(
            (-0.45, -0.45, 0))).matrix,
    )