Пример #1
0
def test_verify_no_need_for_control(PM_da_initialized_1d, PM_da_control_1d):
    """Tests that no error is thrown when no control present
    when calling verify(reference=['uninitialized'])."""
    v = "tos"
    comparison = "m2e"
    pm = PerfectModelEnsemble(PM_da_initialized_1d).load()
    # verify needs to control
    skill = pm.verify(metric="mse", comparison=comparison, dim="init")
    assert not skill[v].isnull().any()
    # control not needed for normalized metrics as normalized
    # with verif which is the verification member in PM and
    # not the control simulation.
    assert (not pm.verify(metric="nmse", comparison=comparison,
                          dim="init")[v].isnull().any())

    with pytest.raises(DatasetError) as e:
        pm.verify(metric="mse",
                  comparison=comparison,
                  dim="init",
                  reference=["persistence"])
    assert "at least one control dataset" in str(e.value)

    # unlikely case that control gets deleted after generating uninitialized
    pm = pm.add_control(PM_da_control_1d).generate_uninitialized()
    pm._datasets["control"] = {}
    assert (not pm._compute_uninitialized(
        metric="mse", comparison=comparison, dim="init")[v].isnull().any())

    assert (not pm.verify(metric="mse",
                          comparison=comparison,
                          dim="init",
                          reference=["uninitialized"])[v].isnull().any())
Пример #2
0
def test_HindcastEnsemble_as_PerfectModelEnsemble(hindcast_recon_1d_mm):
    """Test that initialized dataset for HindcastEnsemble can also be used for
        PerfectModelEnsemble."""
    v = "SST"
    alignment = "maximize"
    hindcast = hindcast_recon_1d_mm
    assert (not hindcast.verify(
        metric="acc", comparison="e2o", dim="init",
        alignment=alignment)[v].isnull().any())

    # try PerfectModelEnsemble predictability
    init = hindcast.get_initialized()
    pm = PerfectModelEnsemble(init)

    assert (not pm.verify(metric="acc",
                          comparison="m2e",
                          dim=["member", "init"])[v].isnull().any())

    pm = pm.add_control(
        init.isel(member=0, lead=0, drop=True).rename({
            "init": "time"
        }).resample(time="1MS").interpolate("linear"))

    pm = pm.generate_uninitialized()
    assert (not pm.verify(
        metric="acc",
        comparison="m2e",
        dim=["member", "init"],
        reference=["uninitialized"],
    )[v].isnull().any())

    pm.bootstrap(iterations=2,
                 metric="acc",
                 comparison="m2e",
                 dim=["member", "init"])
Пример #3
0
def test_HindcastEnsemble_as_PerfectModelEnsemble(hindcast_recon_1d_mm):
    """Test that initialized dataset for HindcastEnsemble can also be used for
    PerfectModelEnsemble."""
    v = "SST"
    alignment = "maximize"
    hindcast = hindcast_recon_1d_mm.isel(lead=[0, 1])
    assert (
        not hindcast.verify(
            metric="acc", comparison="e2o", dim="init", alignment=alignment
        )[v]
        .isnull()
        .any()
    )

    # try PerfectModelEnsemble predictability
    init = hindcast.get_initialized()
    pm = PerfectModelEnsemble(init)

    assert (
        not pm.verify(metric="acc", comparison="m2e", dim=["member", "init"])[v]
        .isnull()
        .any()
    )
def test_PerfectModelEnsemble_time_resolution_verify(
        HindcastEnsemble_time_resolution):
    """Test that PerfectModelEnsemble.verify() in any lead time resolution works."""
    pm = PerfectModelEnsemble(
        HindcastEnsemble_time_resolution.get_initialized())
    assert pm.verify(**PerfectModelEnsemble_verify_kw).notnull().any()