Skip to content

Commit 6d1683c

Browse files
committed
add warning for matrix bin sizes in wave.performance
1 parent cb980dc commit 6d1683c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

mhkit/wave/performance.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import matplotlib.pylab as plt
88
from os.path import join
99
from mhkit.utils import convert_to_dataarray
10+
import warnings
1011

1112

1213
def capture_length(P, J, to_pandas=True):
@@ -99,12 +100,14 @@ def _performance_matrix(X, Y, Z, statistic, x_centers, y_centers):
99100

100101
# Convert bin centers to edges
101102
xi = [np.mean([x_centers[i], x_centers[i + 1]]) for i in range(len(x_centers) - 1)]
102-
xi.insert(0, -np.inf)
103-
xi.append(np.inf)
103+
xi.insert(0, np.float64(0))
104+
xi_end = (x_centers[-1] + np.diff(x_centers[-2:])/2)[0]
105+
xi.append(xi_end)
104106

105107
yi = [np.mean([y_centers[i], y_centers[i + 1]]) for i in range(len(y_centers) - 1)]
106-
yi.insert(0, -np.inf)
107-
yi.append(np.inf)
108+
yi.insert(0, np.float64(0))
109+
yi_end = (y_centers[-1] + np.diff(y_centers[-2:])/2)[0]
110+
yi.append(yi_end)
108111

109112
# Override standard deviation with degree of freedom equal to 1
110113
if statistic == "std":
@@ -121,6 +124,14 @@ def _frequency(a):
121124
X, Y, Z, statistic, bins=[xi, yi], expand_binnumbers=False
122125
)
123126

127+
# Warn if the X (Hm0) or Y (Te) spacing is greater than the IEC TS 62600-100 Ed. 2.0 en 2024 maxima (0.5m, 1.0s).
128+
dx_edge = np.diff(x_edge)
129+
if np.any(dx_edge > 0.5):
130+
warnings.warn("Matrix bin widths are greater than the IEC TS 62600-100 limit of 0.5 meters.")
131+
dy_edge = np.diff(y_edge)
132+
if np.any(dy_edge > 0.5):
133+
warnings.warn("Matrix bin widths are greater than the IEC TS 62600-100 limit of 1.0 seconds.")
134+
124135
M = xr.DataArray(
125136
data=zi,
126137
dims=["x_centers", "y_centers"],

0 commit comments

Comments
 (0)