Skip to content

Commit fb005ce

Browse files
ssolsonakeeste
andauthored
Configure specific warnings (#401)
This PR removes the ignore all future warnings added when some packages were suggesting updating to numpy 2.0 but mhkit needed other packages to update before that could happen. --------- Co-authored-by: akeeste <[email protected]>
1 parent c0bd56e commit fb005ce

File tree

14 files changed

+261
-274
lines changed

14 files changed

+261
-274
lines changed

examples/ADCP_Delft3D_TRTS_example.ipynb

Lines changed: 179 additions & 239 deletions
Large diffs are not rendered by default.

mhkit/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
_rmc()
88

9-
# Ignore future warnings
10-
_warn.simplefilter(action="ignore", category=FutureWarning)
9+
# Use targeted warning configuration
10+
from mhkit.warnings import configure_warnings
11+
12+
configure_warnings()
1113

1214
__version__ = "v0.9.0"
1315

mhkit/acoustics/sel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def sound_exposure_level(
131131
# from weighted mean square values
132132
band = spsd.sel(freq=slice(fmin, fmax))
133133
w = w.sel(freq=slice(fmin, fmax))
134-
exposure = np.trapz(band * w, band["freq"])
134+
exposure = np.trapezoid(band * w, band["freq"])
135135

136136
# Sound exposure level (L_{E,p}) = (L_{p,rms} + 10log10(t))
137137
sel = 10 * np.log10(exposure / reference) + 10 * np.log10(

mhkit/acoustics/spl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def sound_pressure_level(
108108
# Mean square sound pressure in a specified frequency band from mean square values
109109
band = spsd.sel(freq=slice(fmin, fmax))
110110
freqs = band["freq"]
111-
pressure_squared = np.trapz(band, freqs)
111+
pressure_squared = np.trapezoid(band, freqs)
112112

113113
# Mean square sound pressure level
114114
mspl = 10 * np.log10(pressure_squared / reference)
@@ -197,7 +197,7 @@ def _band_sound_pressure_level(
197197
else:
198198
spsd_slc = spsd.sel(freq=slice(*band_range))
199199

200-
pressure_squared.loc[{"freq_bins": key}] = np.trapz(spsd_slc, x)
200+
pressure_squared.loc[{"freq_bins": key}] = np.trapezoid(spsd_slc, x)
201201

202202
# Mean square sound pressure level in dB rel 1 uPa
203203
mspl = 10 * np.log10(pressure_squared / reference)

mhkit/dolfyn/adp/discharge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _calc_discharge(vel, x, depth, surface_zoff=None):
229229
sign = -1
230230
else:
231231
sign = 1
232-
return sign * np.trapz(np.trapz(vel, depth, axis=0), x)
232+
return sign * np.trapezoid(np.trapezoid(vel, depth, axis=0), x)
233233

234234
# Extrapolate to bed
235235
vel = ds["vel"].copy()
@@ -265,7 +265,7 @@ def _calc_discharge(vel, x, depth, surface_zoff=None):
265265
(0.5 * rho * speed**3).mean().item()
266266
) # kg/m^3 * m^3/s^3 = kg/s^3 = W/m^2
267267
hydraulic_depth = abs(
268-
np.trapz((water_depth - surface_offset)[_xinds], xy[0][_xinds])
268+
np.trapezoid((water_depth - surface_offset)[_xinds], xy[0][_xinds])
269269
) / (
270270
xy[0][_xinds].max() - xy[0][_xinds].min()
271271
) # area / surface-width

mhkit/dolfyn/adv/turbulence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def _integral_TE01(self, I_tke, theta):
559559
x = np.arange(-20, 20, 1e-2) # I think this is a long enough range.
560560
out = np.empty_like(I_tke.flatten())
561561
for i, (b, t) in enumerate(zip(I_tke.flatten(), theta.flatten())):
562-
out[i] = np.trapz(
562+
out[i] = np.trapezoid(
563563
cbrt(x**2 - 2 / b * np.cos(t) * x + b ** (-2)) * np.exp(-0.5 * x**2),
564564
x,
565565
)
@@ -684,7 +684,7 @@ def integral_length_scales(self, a_cov, U_mag, fs=None):
684684
T_int = np.zeros(acov.shape[:2])
685685
for i in range(3):
686686
for t in range(a_cov["time"].size):
687-
T_int[i, t] = np.trapz(acov[i, t][: zero_crossing[i, t]], dx=1 / fs)
687+
T_int[i, t] = np.trapezoid(acov[i, t][: zero_crossing[i, t]], dx=1 / fs)
688688

689689
L_int = U_mag.values * T_int
690690

mhkit/dolfyn/time.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,17 @@ def epoch2date(ep_time, offset_hr=0, to_str=False):
123123
elif not isinstance(ep_time, (np.ndarray, list)):
124124
ep_time = [ep_time]
125125

126-
######### IMPORTANT #########
127-
# Note the use of `utcfromtimestamp` here, rather than `fromtimestamp`
128-
# This is CRITICAL! See the difference between those functions here:
129-
# https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp
130-
# Long story short: `fromtimestamp` used system-specific timezone
131-
# info to calculate the datetime object, but returns a
132-
# timezone-agnostic object.
133126
if offset_hr != 0:
134127
delta = timedelta(hours=offset_hr)
135-
time = [datetime.utcfromtimestamp(t) + delta for t in ep_time]
128+
time = [
129+
datetime.fromtimestamp(t, timezone.utc).replace(tzinfo=None) + delta
130+
for t in ep_time
131+
]
136132
else:
137-
time = [datetime.utcfromtimestamp(t) for t in ep_time]
133+
time = [
134+
datetime.fromtimestamp(t, timezone.utc).replace(tzinfo=None)
135+
for t in ep_time
136+
]
138137

139138
if to_str:
140139
time = date2str(time)

mhkit/river/io/d3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def variable_interpolation(
570570

571571
if len(idx[0]):
572572
for i in idx[0]:
573-
transformed_data[var][i] = interp.griddata(
573+
transformed_data.loc[i, var] = interp.griddata(
574574
data_raw[var][["x", "y", "waterdepth"]],
575575
data_raw[var][var],
576576
[points["x"][i], points["y"][i], points["waterdepth"][i]],
@@ -815,7 +815,7 @@ def turbulent_intensity(
815815

816816
if len(idx[0]):
817817
for i in idx[0]:
818-
turbulent_data[var][i] = interp.griddata(
818+
turbulent_data.loc[i, var] = interp.griddata(
819819
turbulent_data_raw[var][["x", "y", "waterdepth"]],
820820
turbulent_data_raw[var][var],
821821
[points["x"][i], points["y"][i], points["waterdepth"][i]],
@@ -837,7 +837,7 @@ def turbulent_intensity(
837837
zero_ind = neg_index[0][zero_bool]
838838
non_zero_ind = neg_index[0][~zero_bool]
839839
turbulent_data.loc[zero_ind, "turkin1"] = np.zeros(len(zero_ind))
840-
turbulent_data.loc[non_zero_ind, "turkin1"] = [np.nan] * len(non_zero_ind)
840+
turbulent_data.loc[non_zero_ind, "turkin1"] = np.nan
841841

842842
turbulent_data["turbulent_intensity"] = (
843843
np.sqrt(2 / 3 * turbulent_data["turkin1"]) / u_mag * 100

mhkit/river/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def energy_produced(
311311
# Sample range for pdf
312312
x = np.linspace(edges.min(), edges.max(), 1000)
313313
# Calculate the expected value of power
314-
expected_power = np.trapz(x * hist_dist.pdf(x), x=x)
314+
expected_power = np.trapezoid(x * hist_dist.pdf(x), x=x)
315315
# Note: Built-in Expected Value method often throws warning
316316
# EV = hist_dist.expect(lb=edges.min(), ub=edges.max())
317317
# Calculate energy

mhkit/tests/wave/io/test_cdip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def test_dates_to_timestamp(self):
7777
self.test_nc, start_date=start_date, end_date=end_date
7878
)
7979

80-
start_dt = datetime.utcfromtimestamp(start_stamp).replace(tzinfo=pytz.UTC)
81-
end_dt = datetime.utcfromtimestamp(end_stamp).replace(tzinfo=pytz.UTC)
80+
start_dt = datetime.fromtimestamp(start_stamp, pytz.UTC)
81+
end_dt = datetime.fromtimestamp(end_stamp, pytz.UTC)
8282

8383
self.assertEqual(start_dt, start_date)
8484
self.assertEqual(end_dt, end_date)

0 commit comments

Comments
 (0)