|
6 | 6 |
|
7 | 7 |
|
8 | 8 | def test_semilagrangian(): |
9 | | - """Tests semilagrangian extrapolation.""" |
| 9 | + """Test semilagrangian extrapolation with number of timesteps.""" |
10 | 10 | # inputs |
11 | | - precip = np.ones((8, 8)) |
| 11 | + precip = np.zeros((8, 8)) |
| 12 | + precip[0, 0] = 1 |
12 | 13 | v = np.ones((8, 8)) |
13 | 14 | velocity = np.stack([v, v]) |
14 | 15 | num_timesteps = 1 |
15 | 16 | # expected |
16 | | - expected = np.ones((1, 8, 8)) |
| 17 | + expected = np.zeros((1, 8, 8)) |
17 | 18 | expected[:, :, 0] = np.nan |
18 | 19 | expected[:, 0, :] = np.nan |
| 20 | + expected[:, 1, 1] = 1 |
19 | 21 | # result |
20 | 22 | result = extrapolate(precip, velocity, num_timesteps) |
21 | 23 | assert_array_almost_equal(result, expected) |
| 24 | + |
| 25 | + |
| 26 | +def test_semilagrangian_timesteps(): |
| 27 | + """Test semilagrangian extrapolation with list of timesteps.""" |
| 28 | + # inputs |
| 29 | + precip = np.zeros((8, 8)) |
| 30 | + precip[0, 0] = 1 |
| 31 | + v = np.ones((8, 8)) * 10 |
| 32 | + velocity = np.stack([v, v]) |
| 33 | + timesteps = [0.1] |
| 34 | + # expected |
| 35 | + expected = np.zeros((1, 8, 8)) |
| 36 | + expected[:, :, 0] = np.nan |
| 37 | + expected[:, 0, :] = np.nan |
| 38 | + expected[:, 1, 1] = 1 |
| 39 | + # result |
| 40 | + result = extrapolate(precip, velocity, timesteps) |
| 41 | + assert_array_almost_equal(result, expected) |
0 commit comments