Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-pisani-4ss committed Jul 1, 2024
1 parent cd404e6 commit 95c315f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/waveresponse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,15 @@ def rotate(self, angle, degrees=False):
dirs_new = _robust_modulus(new._dirs - angle, 2.0 * np.pi)
new._dirs, new._vals = _sort(dirs_new, new._vals)
return new

def _interpolate_function(self, complex_convert="rectangular", **kw):
"""
Interpolation function based on ``scipy.interpolate.interp2d``.
"""
xp = np.concatenate(
(self._dirs[-1:] - 2 * np.pi, self._dirs, self._dirs[:1] + 2.0 * np.pi)
)

yp = self._freq
zp = np.concatenate(
(
Expand All @@ -616,7 +616,7 @@ def _interpolate_function(self, complex_convert="rectangular", **kw):
),
axis=1,
)

if np.all(np.isreal(zp)):
return RGI((xp, yp), zp.T, **kw)
elif complex_convert.lower() == "polar":
Expand Down Expand Up @@ -648,7 +648,6 @@ def interpolate(
complex_convert="rectangular",
fill_value=0.0,
):

freq = np.asarray_chkfinite(freq).reshape(-1)
dirs = np.asarray_chkfinite(dirs).reshape(-1)

Expand All @@ -662,11 +661,14 @@ def interpolate(
self._check_dirs(dirs)

interp_fun = self._interpolate_function(
complex_convert=complex_convert, method='linear', bounds_error=False, fill_value = fill_value
complex_convert=complex_convert,
method="linear",
bounds_error=False,
fill_value=fill_value,
)
xxnew, yynew = np.meshgrid(dirs, freq, indexing='ij', sparse=True)
xxnew, yynew = np.meshgrid(dirs, freq, indexing="ij", sparse=True)
return interp_fun((xxnew, yynew)).T

def reshape(
self,
freq,
Expand Down
4 changes: 3 additions & 1 deletion src/waveresponse/_standardized1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@ def _spectrum(self, omega, hs, tp):
A_secondary = (3.26 / 16.0) * hs_secondary**2 * omega_p_secondary**3
B_secondary = omega_p_secondary**4

spectrum_secondary = A_secondary / omega**4 * np.exp(-B_secondary / omega**4)
spectrum_secondary = (
A_secondary / omega**4 * np.exp(-B_secondary / omega**4)
)

return spectrum_primary + spectrum_secondary

Expand Down
6 changes: 4 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ def test_interpolate(self):
vals_expect = np.array([[a * x_i + b * y_i for x_i in x] for y_i in y])

vals_out = grid.interpolate(y, x, freq_hz=True, degrees=True)

np.testing.assert_array_almost_equal(vals_out, vals_expect)

def test_interpolate2(self):
Expand Down Expand Up @@ -3360,7 +3360,9 @@ def test_moment_m2_rads(self):

m_out = spectrum.moment(2, freq_hz=False)

m_expect = (1.0 / 3.0) * (0.0 - 360.0) * (f0**3 - f1**3) * (2.0 * np.pi) ** 2
m_expect = (
(1.0 / 3.0) * (0.0 - 360.0) * (f0**3 - f1**3) * (2.0 * np.pi) ** 2
)

# not exactly same due to error in trapezoid for higher order functions
assert m_out == pytest.approx(m_expect, rel=0.1)
Expand Down

0 comments on commit 95c315f

Please sign in to comment.