Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into develop
  • Loading branch information
ssolson committed Aug 19, 2024
2 parents 3b5578b + e0d59c7 commit 6c62bfd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mhkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Ignore future warnings
_warn.simplefilter(action="ignore", category=FutureWarning)

__version__ = "v0.8.1"
__version__ = "v0.8.2"

__copyright__ = """
Copyright 2019, Alliance for Sustainable Energy, LLC under the terms of
Expand Down
21 changes: 21 additions & 0 deletions mhkit/tests/wave/test_resource_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ def test_surface_elevation_rmse(self):

self.assertLess(rmse_sum, 0.02)

def test_mhkit_spectrum_without_frequency_index_name_defined(self):
S = wave.resource.jonswap_spectrum(self.f, self.Tp, self.Hs)
S.index.name = None

eta_ifft_xr = wave.resource.surface_elevation(S, self.t, seed=1, method="ifft")
eta_sos_xr = wave.resource.surface_elevation(
S, self.t, seed=1, method="sum_of_sines"
)

assert_allclose(eta_ifft_xr, eta_sos_xr)

def test_user_spectrum_without_frequency_index_name_defined(self):
spectra = pd.DataFrame({"magnitude": [1.0, 2.0, 3.0]}, index=[0.0, 1.0, 2.0])
time = [0.0, 1.0, 2.0]

result = wave.resource.surface_elevation(spectra, time, seed=1)

expected_magnitude = [-0.983917, 1.274248, -2.129812]

assert_allclose(result["magnitude"], expected_magnitude, atol=1e-6)

def test_ifft_sum_of_sines(self):
S = wave.resource.jonswap_spectrum(self.f, self.Tp, self.Hs)

Expand Down
9 changes: 5 additions & 4 deletions mhkit/wave/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def surface_elevation(

if frequency_dimension == "":
frequency_dimension = list(S.coords)[0]

elif frequency_dimension not in list(S.dims):
raise ValueError(
f"frequency_dimension is not a dimension of S ({list(S.dims)}). Got: {frequency_dimension}."
Expand Down Expand Up @@ -366,8 +367,8 @@ def surface_elevation(
np.random.seed(seed)
phase = xr.DataArray(
data=2 * np.pi * np.random.rand(S[var].size),
dims="Frequency",
coords={"Frequency": f},
dims=frequency_dimension,
coords={frequency_dimension: f},
)
else:
phase = phases[var]
Expand All @@ -392,8 +393,8 @@ def surface_elevation(
B = B.reshape((len(time_index), len(omega)))
B = xr.DataArray(
data=B,
dims=["Time", "Frequency"],
coords={"Time": time_index, "Frequency": f},
dims=["Time", frequency_dimension],
coords={"Time": time_index, frequency_dimension: f},
)

# wave elevation
Expand Down

0 comments on commit 6c62bfd

Please sign in to comment.