|
6 | 6 | import pandas as pd |
7 | 7 | import pytest |
8 | 8 | from scipy.integrate import quad |
| 9 | +from scipy.interpolate import RegularGridInterpolator as RGI |
9 | 10 |
|
10 | 11 | import waveresponse as wr |
11 | 12 | from waveresponse import ( |
@@ -1498,16 +1499,19 @@ def test_interpolate_complex_polar(self): |
1498 | 1499 | vp = vp_amp * (np.cos(vp_phase) + 1j * np.sin(vp_phase)) |
1499 | 1500 | grid = Grid(yp, xp, vp, freq_hz=True, degrees=True) |
1500 | 1501 |
|
1501 | | - y = np.linspace(0.5, 1.0, 20) |
1502 | | - x = np.linspace(5.0, 15.0, 10) |
| 1502 | + y = np.linspace(0.0, 2.0, 200) |
| 1503 | + x = np.linspace(0.0, 359.0, 100) |
1503 | 1504 | vals_amp_expect = np.array( |
1504 | 1505 | [[a_amp * x_i + b_amp * y_i for x_i in x] for y_i in y] |
1505 | 1506 | ) |
1506 | | - vals_phase_expect = np.array( |
1507 | | - [[a_phase * x_i + b_phase * y_i for x_i in x] for y_i in y] |
1508 | | - ) |
1509 | | - vals_expect = vals_amp_expect * ( |
1510 | | - np.cos(vals_phase_expect) + 1j * np.sin(vals_phase_expect) |
| 1507 | + x_, y_ = np.meshgrid(x, y, indexing="ij", sparse=True) |
| 1508 | + vals_phase_cos_expect = RGI((xp, yp), np.cos(vp_phase).T)((x_, y_)).T |
| 1509 | + vals_phase_sin_expect = RGI((xp, yp), np.sin(vp_phase).T)((x_, y_)).T |
| 1510 | + |
| 1511 | + vals_expect = ( |
| 1512 | + vals_amp_expect |
| 1513 | + * (vals_phase_cos_expect + 1j * vals_phase_sin_expect) |
| 1514 | + / np.abs(vals_phase_cos_expect + 1j * vals_phase_sin_expect) |
1511 | 1515 | ) |
1512 | 1516 |
|
1513 | 1517 | vals_out = grid.interpolate( |
@@ -1692,11 +1696,14 @@ def test_reshape_complex_polar(self): |
1692 | 1696 | vals_amp_expect = np.array( |
1693 | 1697 | [[a_amp * x_i + b_amp * y_i for x_i in x] for y_i in y] |
1694 | 1698 | ) |
1695 | | - vals_phase_expect = np.array( |
1696 | | - [[a_phase * x_i + b_phase * y_i for x_i in x] for y_i in y] |
1697 | | - ) |
1698 | | - vals_expect = vals_amp_expect * ( |
1699 | | - np.cos(vals_phase_expect) + 1j * np.sin(vals_phase_expect) |
| 1699 | + x_, y_ = np.meshgrid(x, y, indexing="ij", sparse=True) |
| 1700 | + vals_phase_cos_expect = RGI((xp, yp), np.cos(vp_phase).T)((x_, y_)).T |
| 1701 | + vals_phase_sin_expect = RGI((xp, yp), np.sin(vp_phase).T)((x_, y_)).T |
| 1702 | + |
| 1703 | + vals_expect = ( |
| 1704 | + vals_amp_expect |
| 1705 | + * (vals_phase_cos_expect + 1j * vals_phase_sin_expect) |
| 1706 | + / np.abs(vals_phase_cos_expect + 1j * vals_phase_sin_expect) |
1700 | 1707 | ) |
1701 | 1708 |
|
1702 | 1709 | np.testing.assert_array_almost_equal(freq_out, freq_expect) |
|
0 commit comments