コード例 #1
0
def test_BasicMetrics_calculator_metadata():
    """
    Test BasicMetrics with metadata.
    """
    df = make_some_data()
    data = df[['ref', 'k1']]

    metadata_dict_template = {'network': np.array(['None'], dtype='U256')}

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")  # many warnings due to test data

        metriccalc = BasicMetrics(other_name='k1',
                                  calc_tau=False,
                                  metadata_template=metadata_dict_template)

        res = metriccalc.calc_metrics(data,
                                      gpi_info=(0, 0, 0, {
                                          'network': 'SOILSCAPE'
                                      }))

    should = dict(network=np.array(['SOILSCAPE'], dtype='U256'),
                  n_obs=np.array([366]),
                  RMSD=np.array([0.2], dtype='float32'),
                  BIAS=np.array([-0.2], dtype='float32'),
                  dtype='float32')

    assert res['n_obs'] == should['n_obs']
    assert np.isnan(res['rho'])
    assert res['RMSD'] == should['RMSD']
    assert res['BIAS'] == should['BIAS']
    assert res['network'] == should['network']
    assert np.isnan(res['R'])
    # depends on scipy version changed after v1.2.1
    assert res['p_R'] == np.array([1.]) or np.isnan(res['R'])
コード例 #2
0
def test_BasicMetrics_calculator():
    """
    Test BasicMetrics.
    """
    df = make_some_data()
    data = df[['ref', 'k1']]

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")  # many warnings due to test data

        metriccalc = BasicMetrics(other_name='k1', calc_tau=False)
        res = metriccalc.calc_metrics(data, gpi_info=(0, 0, 0))

    should = dict(n_obs=np.array([366]),
                  RMSD=np.array([0.2], dtype='float32'),
                  BIAS=np.array([-0.2], dtype='float32'))

    assert res['n_obs'] == should['n_obs']
    assert np.isnan(res['rho'])
    assert res['RMSD'] == should['RMSD']
    assert res['BIAS'] == should['BIAS']
    assert np.isnan(res['R'])

    # scipy 1.3.0 is not built for python 2.7 so we allow both for now
    assert (np.isnan(res['p_R']) or res['p_R'] == 1.0)
コード例 #3
0
def test_BasicSeasonalMetrics():
    """
    Test BasicSeasonalMetrics.
    """
    df = make_some_data()
    data = df[['ref', 'k1']]

    metriccalc = MonthsMetricsAdapter(BasicMetrics(other_name='k1'))
    res = metriccalc.calc_metrics(data, gpi_info=(0, 0, 0))

    should = dict(ALL_n_obs=np.array([366]), dtype='float32')

    assert res['ALL_n_obs'] == should['ALL_n_obs']
    assert np.isnan(res['ALL_rho'])
コード例 #4
0
def test_BasicSeasonalMetrics_metadata():
    """
    Test BasicSeasonalMetrics with metadata.
    """
    df = make_some_data()
    data = df[['ref', 'k1']]

    metadata_dict_template = {'network': np.array(['None'], dtype='U256')}

    metriccalc = MonthsMetricsAdapter(BasicMetrics(
        other_name='k1', metadata_template=metadata_dict_template))
    res = metriccalc.calc_metrics(
        data, gpi_info=(0, 0, 0, {'network': 'SOILSCAPE'}))

    assert res['network'] == np.array(['SOILSCAPE'], dtype='U256')
コード例 #5
0
def test_BasicSeasonalMetrics():
    """
    Test BasicSeasonalMetrics.
    """
    df = make_some_data()
    data = df[["ref", "k1"]]

    with pytest.warns(UserWarning):
        metriccalc = MonthsMetricsAdapter(BasicMetrics(other_name="k1"))
        res = metriccalc.calc_metrics(data, gpi_info=(0, 0, 0))

    should = {("ALL", "n_obs"): np.array([366], dtype="float32")}

    assert res[("ALL", "n_obs")] == should[("ALL", "n_obs")]
    assert np.isnan(res[("ALL", "rho")])
コード例 #6
0
def test_BasicMetrics_calculator_metadata():
    """
    Test BasicMetrics with metadata.
    """
    df = make_some_data()
    data = df[["ref", "k1"]]

    metadata_dict_template = {"network": np.array(["None"], dtype="U256")}

    metriccalc = BasicMetrics(
        other_name="k1",
        calc_tau=False,
        metadata_template=metadata_dict_template,
    )

    res = metriccalc.calc_metrics(data,
                                  gpi_info=(0, 0, 0, {
                                      "network": "SOILSCAPE"
                                  }))

    should = dict(
        network=np.array(["SOILSCAPE"], dtype="U256"),
        n_obs=np.array([366]),
        RMSD=np.array([0.2], dtype="float32"),
        BIAS=np.array([-0.2], dtype="float32"),
        dtype="float32",
    )

    assert res["n_obs"] == should["n_obs"]
    assert np.isnan(res["rho"])
    assert res["RMSD"] == should["RMSD"]
    assert res["BIAS"] == should["BIAS"]
    assert res["network"] == should["network"]
    assert np.isnan(res["R"])
    # depends on scipy version changed after v1.2.1
    assert res["p_R"] == np.array([1.0]) or np.isnan(res["R"])
コード例 #7
0
def test_BasicMetrics_calculator():
    """
    Test BasicMetrics.
    """
    df = make_some_data()
    data = df[["ref", "k1"]]

    metriccalc = BasicMetrics(other_name="k1", calc_tau=False)
    res = metriccalc.calc_metrics(data, gpi_info=(0, 0, 0))

    should = dict(
        n_obs=np.array([366]),
        RMSD=np.array([0.2], dtype="float32"),
        BIAS=np.array([-0.2], dtype="float32"),
    )

    assert res["n_obs"] == should["n_obs"]
    assert np.isnan(res["rho"])
    assert res["RMSD"] == should["RMSD"]
    assert res["BIAS"] == should["BIAS"]
    assert np.isnan(res["R"])

    # scipy 1.3.0 is not built for python 2.7 so we allow both for now
    assert np.isnan(res["p_R"]) or res["p_R"] == 1.0
コード例 #8
0
def test_BasicSeasonalMetrics():
    """
    Test BasicSeasonalMetrics.
    """
    df = make_some_data()
    data = df[['ref', 'k1']]

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")  # many warnings due to test data

        metriccalc = MonthsMetricsAdapter(BasicMetrics(other_name='k1'))
        res = metriccalc.calc_metrics(data, gpi_info=(0, 0, 0))

    should = dict(ALL_n_obs=np.array([366]), dtype='float32')

    assert res['ALL_n_obs'] == should['ALL_n_obs']
    assert np.isnan(res['ALL_rho'])
コード例 #9
0
def test_BasicSeasonalMetrics_metadata():
    """
    Test BasicSeasonalMetrics with metadata.
    """
    df = make_some_data()
    data = df[["ref", "k1"]]

    metadata_dict_template = {"network": np.array(["None"], dtype="U256")}

    with pytest.warns(UserWarning):
        metriccalc = MonthsMetricsAdapter(
            BasicMetrics(other_name="k1",
                         metadata_template=metadata_dict_template))
        res = metriccalc.calc_metrics(data,
                                      gpi_info=(0, 0, 0, {
                                          "network": "SOILSCAPE"
                                      }))

    assert res["network"] == np.array(["SOILSCAPE"], dtype="U256")