Beispiel #1
0
def test_compute_climatology_daisy_chain(ds):
    dset = open_dataset(ds, decode_times=False)

    computed_dset = compute_mon_climatology(dset)
    assert isinstance(computed_dset, xr.Dataset)

    computed_dset2 = compute_mon_anomaly(computed_dset)
    assert isinstance(computed_dset2, xr.Dataset)

    computed_dset3 = compute_ann_mean(computed_dset)
    assert isinstance(computed_dset3, xr.Dataset)

    computed_dset3 = compute_ann_mean(computed_dset2)
    assert isinstance(computed_dset3, xr.Dataset)
Beispiel #2
0
def test_compute_climatology_multi_drop_time_bound(ds):
    dset = open_dataset(ds, decode_times=False)
    dset_time_bound = dset.time.attrs['bounds']
    dset = dset.drop(dset_time_bound)
    del dset.time.attrs['bounds']

    computed_dset = compute_mon_climatology(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]

    computed_dset = compute_ann_mean(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]

    computed_dset = compute_mon_anomaly(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    assert (dset.time.values == computed_dset.time.values).all()
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]
Beispiel #3
0
def test_compute_ann_mean_values_missing(dset):
    dset.variable_1.values[0:3, :, :] = np.nan
    computed_dset = compute_ann_mean(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    expected = np.array([0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0])
    np.testing.assert_equal(computed_dset.variable_1.values.ravel(), expected)
Beispiel #4
0
def test_compute_climatology_multi(ds):
    dset = open_dataset(ds, decode_times=False)
    print(dset)
    computed_dset = compute_mon_climatology(dset)
    print(computed_dset)
    print()
    assert isinstance(computed_dset, xr.Dataset)
    computed_dset = compute_ann_mean(dset)
    print(computed_dset)
    print()
    assert isinstance(computed_dset, xr.Dataset)
    computed_dset = compute_mon_anomaly(dset)
    print(computed_dset)
    print()
    assert isinstance(computed_dset, xr.Dataset)
Beispiel #5
0
def test_compute_climatology_multi_decoded(ds):
    dset = open_dataset(ds, decode_times=True)

    computed_dset = compute_mon_climatology(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]

    computed_dset = compute_ann_mean(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]

    computed_dset = compute_mon_anomaly(dset)
    assert isinstance(computed_dset, xr.Dataset)
    assert computed_dset.time.dtype == dset.time.dtype
    assert (dset.time.values == computed_dset.time.values).all()
    for key, value in dset.time.attrs.items():
        assert key in computed_dset.time.attrs
        assert value == computed_dset.time.attrs[key]
Beispiel #6
0
def test_compute_ann_mean(dset):
    computed_dset = compute_ann_mean(dset)
    assert isinstance(computed_dset, xr.Dataset)
    expected = np.array([0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0])
    np.testing.assert_equal(computed_dset.variable_1.values.ravel(), expected)