def test_shuffled_anomaly(): res = ClimateData.SmallTestData().anomaly().std(axis=0) exp = np.array([0.31, 0.6355, 0.31, 0.6355, 0.31, 0.6355]) assert np.allclose(res, exp, atol=1e-04) res = ClimateData.SmallTestData().shuffled_anomaly().std(axis=0) exp = np.array([0.31, 0.6355, 0.31, 0.6355, 0.31, 0.6355]) assert np.allclose(res, exp, atol=1e-04)
def test_anomaly(): res = ClimateData.SmallTestData().anomaly()[:, 0] exp = np.array([ -0.5, -0.321, -0.1106, 0.1106, 0.321, 0.5, 0.321, 0.1106, -0.1106, -0.321 ]) assert np.allclose(res, exp, atol=1e-04)
def test_phase_mean(): res = ClimateData.SmallTestData().phase_mean() exp = np.array([[0.5, 0.5, -0.5, -0.5, 0.5, 0.5], [0.63, 0.321, -0.63, -0.321, 0.63, 0.321], [0.6984, 0.1106, -0.6984, -0.1106, 0.6984, 0.1106], [0.6984, -0.1106, -0.6984, 0.1106, 0.6984, -0.1106], [0.63, -0.321, -0.63, 0.321, 0.63, -0.321]]) assert np.allclose(res, exp, atol=1e-04)
def test_window(): data = ClimateData.SmallTestData() data.set_window(window={"time_min": 0., "time_max": 0., "lat_min": 10., "lat_max": 20., "lon_min": 5., "lon_max": 10.}) res = data.anomaly() exp = np.array([[0.5, -0.5], [0.321, -0.63], [0.1106, -0.6984], [-0.1106, -0.6984], [-0.321, -0.63], [-0.5, 0.5], [-0.321, 0.63], [-0.1106, 0.6984], [0.1106, 0.6984], [0.321, 0.63]]) assert np.allclose(res, exp, atol=1e-04)
def test_calculate_similarity_measure(): res = TsonisClimateNetwork.SmallTestNetwork().calculate_similarity_measure( anomaly=ClimateData.SmallTestData().anomaly()) exp = np.array([[1., -0.2538, -1., 0.2538, 1., -0.2538], [-0.2538, 1., 0.2538, -1., -0.2538, 1.], [-1., 0.2538, 1., -0.2538, -1., 0.2538], [0.2538, -1., -0.2538, 1., 0.2538, -1.], [1., -0.2538, -1., 0.2538, 1., -0.2538], [-0.2538, 1., 0.2538, -1., -0.2538, 1.]], dtype=np.float32) assert np.allclose(res, exp, atol=1e-04)
def test_set_global_window(): data = ClimateData.SmallTestData() data.set_window(window={"time_min": 0., "time_max": 4., "lat_min": 10., "lat_max": 20., "lon_min": 5., "lon_max": 10.}) res = data.grid.grid()["lat"] exp = np.array([10., 15.], dtype=np.float32) assert np.allclose(res, exp, atol=1e-04) data.set_global_window() res = data.grid.grid()["lat"] exp = np.array([0., 5., 10., 15., 20., 25.], dtype=np.float32) assert np.allclose(res, exp, atol=1e-04)
def test_indices_selected_phases(): res = ClimateData.SmallTestData().indices_selected_phases([0, 1, 4]) exp = np.array([0, 1, 4, 5, 6, 9]) assert (res == exp).all()
def test_phase_indices(): res = ClimateData.SmallTestData().phase_indices() exp = np.array([[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]) assert (res == exp).all()