コード例 #1
0
ファイル: test_data.py プロジェクト: vishalbelsare/pyunicorn
def test_window():
    lon_min = Data.SmallTestData().window()["lon_min"]
    lon_max = Data.SmallTestData().window()["lon_max"]
    lon_min_ref = 2.5
    lon_max_ref = 15.0
    isequal = np.allclose(lon_min, lon_min_ref) and \
              np.allclose(lon_max, lon_max_ref)
    assert isequal
コード例 #2
0
def test_observable():
    obs = Data.SmallTestData().observable()
    obs_ref = np.array([[0.00000000e+00, 1.00000000e+00, 1.22464680e-16,
                         -1.00000000e+00, -2.44929360e-16, 1.00000000e+00],
                        [3.09016994e-01, 9.51056516e-01, -3.09016994e-01,
                         -9.51056516e-01, 3.09016994e-01, 9.51056516e-01],
                        [5.87785252e-01, 8.09016994e-01, -5.87785252e-01,
                         -8.09016994e-01, 5.87785252e-01, 8.09016994e-01],
                        [8.09016994e-01, 5.87785252e-01, -8.09016994e-01,
                         -5.87785252e-01, 8.09016994e-01, 5.87785252e-01],
                        [9.51056516e-01, 3.09016994e-01, -9.51056516e-01,
                         -3.09016994e-01, 9.51056516e-01, 3.09016994e-01],
                        [1.00000000e+00, 1.22464680e-16, -1.00000000e+00,
                         -2.44929360e-16, 1.00000000e+00, 3.67394040e-16],
                        [9.51056516e-01, -3.09016994e-01, -9.51056516e-01,
                         3.09016994e-01, 9.51056516e-01, -3.09016994e-01],
                        [8.09016994e-01, -5.87785252e-01, -8.09016994e-01,
                         5.87785252e-01, 8.09016994e-01, -5.87785252e-01],
                        [5.87785252e-01, -8.09016994e-01, -5.87785252e-01,
                         8.09016994e-01, 5.87785252e-01, -8.09016994e-01],
                        [3.09016994e-01, -9.51056516e-01, -3.09016994e-01,
                         9.51056516e-01, 3.09016994e-01, -9.51056516e-01]])

    isequal = np.allclose(obs, obs_ref)
    assert isequal
コード例 #3
0
ファイル: TestTimeseries.py プロジェクト: afcarl/pyunicorn
def create_test_data():
    # Create test time series
    tdata = Data.SmallTestData().observable()
    n_index, n_times = tdata.shape
    # subtract means form the input data
    tdata -= np.mean(tdata, axis=1)[:, None]
    # normalize the data
    tdata /= np.sqrt(np.sum(tdata * tdata, axis=1))[:, None]
    return tdata
コード例 #4
0
def test_SmallTestData():
    res = Data.SmallTestData().observable()
    exp = np.array([[0., 1., 0., -1., -0., 1.],
                    [0.309, 0.9511, -0.309, -0.9511, 0.309, 0.9511],
                    [0.5878, 0.809, -0.5878, -0.809, 0.5878, 0.809],
                    [0.809, 0.5878, -0.809, -0.5878, 0.809, 0.5878],
                    [0.9511, 0.309, -0.9511, -0.309, 0.9511, 0.309],
                    [1., 0., -1., -0., 1., 0.],
                    [0.9511, -0.309, -0.9511, 0.309, 0.9511, -0.309],
                    [0.809, -0.5878, -0.809, 0.5878, 0.809, -0.5878],
                    [0.5878, -0.809, -0.5878, 0.809, 0.5878, -0.809],
                    [0.309, -0.9511, -0.309, 0.9511, 0.309, -0.9511]])
    assert np.allclose(res, exp, atol=1e-04)
コード例 #5
0
def test_set_window():
    data = Data.SmallTestData()
    data.set_window(window={"time_min": 0., "time_max": 4., "lat_min": 10.,
                            "lat_max": 20., "lon_min": 5., "lon_max": 10.})
    obs = data.observable()
    obs_ref = np.array([[1.22464680e-16, -1.00000000e+00],
                        [-3.09016994e-01, -9.51056516e-01],
                        [-5.87785252e-01, -8.09016994e-01],
                        [-8.09016994e-01, -5.87785252e-01],
                        [-9.51056516e-01, -3.09016994e-01]])

    isequal = np.allclose(obs, obs_ref)
    assert isequal
コード例 #6
0
def test_set_global_window():
    data = Data.SmallTestData()
    data.set_window(window={"time_min": 0., "time_max": 4.,
                            "lat_min": 10., "lat_max": 20., "lon_min": 5.,
                            "lon_max": 10.})

    lat1 = data.grid.grid()["lat"]
    data.set_global_window()
    lat2 = data.grid.grid()["lat"]

    lat1_ref = np.array([10., 15.], dtype=np.float32)
    lat2_ref = np.array([0., 5., 10., 15., 20., 25.], dtype=np.float32)

    isequal = np.allclose(lat1, lat1_ref) and np.allclose(lat2, lat2_ref)
    assert isequal