Example #1
0
def test_add_srf(modes_all_single):
    if eradiate.mode().has_flags(ModeFlags.ANY_MONO):
        spectral_cfg = {"wavelengths": [550.0]}
    elif eradiate.mode().has_flags(ModeFlags.ANY_CKD):
        spectral_cfg = {"bins": ["550"]}
    else:
        pytest.skip(f"Please add test for '{eradiate.mode().id}' mode")

    exp = OneDimExperiment(
        atmosphere=None,
        measures=MultiDistantMeasure.from_viewing_angles(
            zeniths=[-60, -45, 0, 45, 60],
            azimuths=0.0,
            spp=1,
            spectral_cfg=spectral_cfg,
        ),
    )
    exp.process()
    measure = exp.measures[0]

    # Apply basic post-processing
    values = Pipeline([
        Gather(var="radiance"),
        AggregateCKDQuad(var="radiance", measure=measure)
    ]).transform(measure.results)

    step = AddSpectralResponseFunction(measure=measure)
    result = step.transform(values)

    # The spectral response function is added to the dataset as a data variable
    assert "srf" in result.data_vars
    # Its only dimension is wavelength
    assert set(result.srf.dims) == {"srf_w"}
Example #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)
Example #3
0
def test_add_viewing_angles(mode_mono, measure_type, expected_zenith,
                            expected_azimuth):
    # Initialise test data
    if measure_type == "multi_distant-nohplane":
        measure = MultiDistantMeasure.from_viewing_angles(
            zeniths=[-60, -45, 0, 45, 60],
            azimuths=0.0,
            auto_hplane=False,
            spp=1,
        )

    elif measure_type == "multi_distant-hplane":
        measure = MultiDistantMeasure.from_viewing_angles(
            zeniths=[-60, -45, 0, 45, 60],
            azimuths=0.0,
            auto_hplane=True,
            spp=1,
        )

    elif measure_type == "hemispherical_distant":
        measure = HemisphericalDistantMeasure(
            film_resolution=(2, 2),
            spp=1,
        )

    else:
        assert False

    exp = OneDimExperiment(atmosphere=None, measures=measure)
    exp.process()
    measure = exp.measures[0]

    # Apply basic post-processing
    values = Gather(var="radiance").transform(measure.results)

    step = AddViewingAngles(measure=measure)
    result = step.transform(values)

    # Produced dataset has viewing angle coordinates
    assert "vza" in result.coords
    assert "vaa" in result.coords

    # Viewing angles are set to appropriate values
    assert np.allclose(expected_zenith, result.coords["vza"].values.squeeze())
    assert np.allclose(expected_azimuth, result.coords["vaa"].values.squeeze())
Example #4
0
def test_apply_spectral_response_function_transform(mode_id, spectral_cfg):
    """
    Unit tests for ApplySpectralResponseFunction.transform().
    """
    # Prepare basic data
    eradiate.set_mode(mode_id)

    exp = OneDimExperiment(
        atmosphere=None,
        measures=MultiDistantMeasure.from_viewing_angles(
            id="measure",
            zeniths=[-60, -45, 0, 45, 60],
            azimuths=0.0,
            spp=1,
            spectral_cfg=spectral_cfg,
        ),
    )
    measure = exp.measures[0]
    exp.process(measure)

    # Apply first steps of post-processing
    pipeline = exp.pipeline(measure)
    values = pipeline.transform(measure.results, stop_after="add_viewing_angles")

    # Apply tested pipeline step
    step = ApplySpectralResponseFunction(measure=measure, vars=["radiance"])

    if eradiate.mode().has_flags(ModeFlags.ANY_MONO):
        # In mono modes, the dataset produced by previous steps is missing
        # bin data required for the step to run successfully
        with pytest.raises(ValueError):
            step.transform(values)
        return

    # In binned modes, computation goes through
    result = step.transform(values)

    # The step adds a SRF-weighted variable
    assert "radiance_srf" in result.data_vars
    assert np.all(result.radiance_srf > 0.0)