From 62b85fb9355ab3dd914d649ac0cd635ce3ecf8d7 Mon Sep 17 00:00:00 2001 From: ssolson Date: Fri, 9 Aug 2024 07:41:24 -0600 Subject: [PATCH 1/3] matplotlib >=3.8 (#345) Bug fix by removing matplotlib version check needed for < 3.8.0 --- environment.yml | 2 +- mhkit/wave/contours.py | 8 +------- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/environment.yml b/environment.yml index ac679176d..ee1b37bf0 100644 --- a/environment.yml +++ b/environment.yml @@ -8,7 +8,7 @@ dependencies: - pandas>=1.0.0 - numpy>=1.21.0, <2.0.0 - scipy<=1.13.1 - - matplotlib + - matplotlib>=3.8.0 - requests - lxml - scikit-learn diff --git a/mhkit/wave/contours.py b/mhkit/wave/contours.py index 905c560b8..b2a054c4c 100644 --- a/mhkit/wave/contours.py +++ b/mhkit/wave/contours.py @@ -8,11 +8,8 @@ import numpy as np import warnings from mhkit.utils import to_numeric_array - import matplotlib -mpl_version = tuple(map(int, matplotlib.__version__.split("."))) - # Contours def environmental_contours(x1, x2, sea_state_duration, return_period, method, **kwargs): @@ -1696,10 +1693,7 @@ def _bivariate_KDE(x1, x2, bw, fit, nb_steps, Ndata_bivariate_KDE, kwargs): x1_bivariate_KDE = [] x2_bivariate_KDE = [] - if mpl_version < (3, 8): # For versions before 3.8 - segments = vals.allsegs[0] - else: - segments = [path.vertices for path in vals.get_paths()] + segments = [path.vertices for path in vals.get_paths()] for seg in segments: x1_bivariate_KDE.append(seg[:, 1]) diff --git a/requirements.txt b/requirements.txt index 381f1068f..1f68d7614 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ pandas>=1.0.0 numpy>=1.21.0, <2.0.0 scipy<=1.13.1 -matplotlib +matplotlib>=3.8.0 requests pecos>=0.3.0 fatpack diff --git a/setup.py b/setup.py index c30ff2e9f..8d2825b3b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ "pandas>=1.0.0", "numpy>=1.21.0, <2.0.0", "scipy<=1.13.1", - "matplotlib", + "matplotlib>=3.8.0", "requests", "pecos>=0.3.0", "fatpack", From 09b9d7f3b75eb64f49722752711cb1b1d42fc804 Mon Sep 17 00:00:00 2001 From: ssolson Date: Sat, 10 Aug 2024 08:04:51 -0600 Subject: [PATCH 2/3] MHKiT version increase for new release (#346) *MHKiT v0.8.2 --- mhkit/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mhkit/__init__.py b/mhkit/__init__.py index 82283fec3..116453146 100644 --- a/mhkit/__init__.py +++ b/mhkit/__init__.py @@ -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 From e0d59c78c9872d7e858b6dd7941825f4c2a470e1 Mon Sep 17 00:00:00 2001 From: Andrew Simms Date: Wed, 14 Aug 2024 05:46:25 -0600 Subject: [PATCH 3/3] Fix: Handle unnamed index/dimension in wave.resource.surface_elevation (#341) * Fix: If unnamed, set spectrum dim_0 name to "Frequency" * Test: input spectrum without index name defined * Fix: Use found frequency dimension name * Test: input wave spectrum with unnamed index --- mhkit/tests/wave/test_resource_spectrum.py | 21 +++++++++++++++++++++ mhkit/wave/resource.py | 9 +++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/mhkit/tests/wave/test_resource_spectrum.py b/mhkit/tests/wave/test_resource_spectrum.py index 387f87189..5ac06cb29 100644 --- a/mhkit/tests/wave/test_resource_spectrum.py +++ b/mhkit/tests/wave/test_resource_spectrum.py @@ -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) diff --git a/mhkit/wave/resource.py b/mhkit/wave/resource.py index 7475fb331..ca5800502 100644 --- a/mhkit/wave/resource.py +++ b/mhkit/wave/resource.py @@ -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}." @@ -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] @@ -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