diff --git a/mhkit/acoustics/__init__.py b/mhkit/acoustics/__init__.py index eb6857c6..f91eec6f 100644 --- a/mhkit/acoustics/__init__.py +++ b/mhkit/acoustics/__init__.py @@ -6,4 +6,4 @@ """ from mhkit.acoustics import io, graphics -from .base import * +from .analysis import * diff --git a/mhkit/acoustics/base.py b/mhkit/acoustics/analysis.py similarity index 99% rename from mhkit/acoustics/base.py rename to mhkit/acoustics/analysis.py index 6c8a6f89..946d5580 100644 --- a/mhkit/acoustics/base.py +++ b/mhkit/acoustics/analysis.py @@ -75,6 +75,7 @@ def minimum_frequency( --------- Jennings 2011 - Computational Ocean Acoustics, 2nd ed. """ + # Convert water_depth to a NumPy array for vectorized operations water_depth = np.asarray(water_depth) @@ -124,6 +125,8 @@ def sound_pressure_spectral_density( spsd: xarray.DataArray (time, freq) Spectral density [Pa^2/Hz] indexed by time and frequency """ + + # Type checks if not isinstance(pressure, xr.DataArray): raise TypeError("'pressure' must be an xarray.DataArray.") if not isinstance(fs, (int, float)): @@ -367,6 +370,8 @@ def band_average( Frequency band-averaged sound pressure spectral density level [dB re 1 uPa^2/Hz] indexed by time and frequency """ + + # Type checks if not isinstance(spsdl, xr.DataArray): raise TypeError("'spsdl' must be an xarray.DataArray.") if not isinstance(octave, int): @@ -618,6 +623,7 @@ def _band_sound_pressure_level( out: xarray.DataArray (time, freq_bins) Sound pressure level [dB re 1 uPa] indexed by time and frequency of specified bandwidth """ + # Type checks if not isinstance(spsd, xr.DataArray): raise TypeError("'spsd' must be an xarray.DataArray.") @@ -703,6 +709,7 @@ def third_octave_sound_pressure_level( mspl: xarray.DataArray (time, freq_bins) Sound pressure level [dB re 1 uPa] indexed by time and third octave bands """ + # Type checks if not isinstance(spsd, xr.DataArray): raise TypeError("'spsd' must be an xarray.DataArray.") @@ -761,6 +768,7 @@ def decidecade_sound_pressure_level( mspl : xarray.DataArray (time, freq_bins) Sound pressure level [dB re 1 uPa] indexed by time and third octave bands """ + # Type checks if not isinstance(spsd, xr.DataArray): raise TypeError("'spsd' must be an xarray.DataArray.") diff --git a/mhkit/acoustics/graphics.py b/mhkit/acoustics/graphics.py index 73b03f5c..4cc28d91 100644 --- a/mhkit/acoustics/graphics.py +++ b/mhkit/acoustics/graphics.py @@ -5,7 +5,7 @@ """ import matplotlib.pyplot as plt -from .base import _fmax_warning +from .analysis import _fmax_warning def plot_spectogram(spsdl, fmin=10, fmax=100000, fig=None, ax=None, **kwargs): diff --git a/mhkit/acoustics/io.py b/mhkit/acoustics/io.py index a626fadd..d33df056 100644 --- a/mhkit/acoustics/io.py +++ b/mhkit/acoustics/io.py @@ -122,7 +122,7 @@ def _calculate_voltage_and_time( raw_voltage = raw.astype(float) / max_count * peak_voltage # Get time - end_time = np.datetime64(start_time) + np.timedelta64(length, "s") + end_time = np.datetime64(start_time) + np.timedelta64(length * 1000, "ms") time = pd.date_range(start_time, end_time, raw.size + 1) return raw_voltage, time, max_count diff --git a/mhkit/dolfyn/adv/clean.py b/mhkit/dolfyn/adv/clean.py index bf91efac..69a03587 100644 --- a/mhkit/dolfyn/adv/clean.py +++ b/mhkit/dolfyn/adv/clean.py @@ -6,7 +6,6 @@ from ..velocity import VelBinner from ..tools.misc import group, slice1d_along_axis -warnings.simplefilter("ignore", np.exceptions.RankWarning) sin = np.sin cos = np.cos diff --git a/mhkit/tests/acoustics/test_analysis.py b/mhkit/tests/acoustics/test_analysis.py index e6a4959b..fa861cba 100644 --- a/mhkit/tests/acoustics/test_analysis.py +++ b/mhkit/tests/acoustics/test_analysis.py @@ -237,7 +237,7 @@ def test_fmax_warning(self): """ Test that fmax warning adjusts the maximum frequency if necessary. """ - from mhkit.acoustics.base import _fmax_warning + from mhkit.acoustics.analysis import _fmax_warning # Test case where fmax is greater than Nyquist frequency fn = 1000 @@ -260,7 +260,7 @@ def test_validate_method(self): """ Test the validation of the 'method' parameter in band_average or time_average. """ - from mhkit.acoustics.base import _validate_method + from mhkit.acoustics.analysis import _validate_method # Valid method string method_name, method_arg = _validate_method("median")