diff --git a/.gitignore b/.gitignore index 6918275..7338ceb 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,7 @@ docs/source/generated/ .DS_Store tests/test_data/data_exploration +tests/test_data/impulsive_data/kurtosis_result.nc +tests/test_data/impulsive_data/pileDriving_results_pypam.csv + pypam.egg-info/ diff --git a/pypam/_event.py b/pypam/_event.py index 8dccaf4..4b573f7 100644 --- a/pypam/_event.py +++ b/pypam/_event.py @@ -40,18 +40,40 @@ def cut(self, start=0, end=None): self.end += end self.signal = self.signal[start:end] - def analyze(self): + def analyze(self, impulsive=False, energy_window=0.9): """ Perform all necessary calculations for a single event + Parameters + ---------- + impulsive : bool + whether or not the analysis should perform impulsive metrics + energy_window: float + If provided, calculate relevant metrics over the given energy window (e.g. RMS_90 + for energy_window= .9). Returns ------- - rms, sel, peak + dictionary of metrics: rms, sel, peak, kurtosis, tau """ - rms = self.rms() - sel = self.sel() + + if impulsive: + windowStr = str(int(energy_window*100)) + rms = self.rms(energy_window=energy_window) + sel = super(Event, self).sel() + tau = self.pulse_width(energy_window) + + else: + windowStr = '' + rms = self.rms() + sel = self.sel() + tau = (self.end-self.start)/self.fs + peak = self.peak() - return rms, sel, peak + kurtosis = self.kurtosis() + start_time = self.start / self.fs + + out = {'startTime':start_time,'peak':peak,f'rms{windowStr}':rms,'sel':sel,'tau':tau,'kurtosis':kurtosis} + return out def sel(self, high_noise=False): """ diff --git a/pypam/acoustic_file.py b/pypam/acoustic_file.py index 77bbd44..c4133ea 100644 --- a/pypam/acoustic_file.py +++ b/pypam/acoustic_file.py @@ -137,6 +137,8 @@ def _bins(self, binsize=None, bin_overlap=0): Where i is the index, time_bin is the datetime of the beginning of the block and signal is the signal object of the bin """ + if bin_overlap>1: + raise ValueError(f'bin_overlap must be fractional.') if binsize is None: blocksize = self.file.frames - self._start_frame else: @@ -145,7 +147,7 @@ def _bins(self, binsize=None, bin_overlap=0): n_blocks = self._n_blocks(blocksize, noverlap=noverlap) time_array, _, _ = self._time_array(binsize, bin_overlap=bin_overlap) for i, block in tqdm(enumerate(sf.blocks(self.file_path, blocksize=blocksize, start=self._start_frame, - overlap=bin_overlap, always_2d=True, fill_value=0.0)), + overlap=noverlap, always_2d=True, fill_value=0.0)), total=n_blocks, leave=False, position=0): # Select the desired channel block = block[:, self.channel] @@ -155,8 +157,9 @@ def _bins(self, binsize=None, bin_overlap=0): signal = sig.Signal(signal=signal_upa, fs=self.fs, channel=self.channel) if self.dc_subtract: signal.remove_dc() - start_sample = i * blocksize + self._start_frame - end_sample = start_sample + len(signal_upa) + step = blocksize - noverlap + start_sample = i * step + self._start_frame + end_sample = start_sample + blocksize yield i, time_bin, signal, start_sample, end_sample self.file.seek(0) @@ -544,7 +547,7 @@ def _apply(self, method_name, binsize=None, db=True, band_list=None, bin_overlap def rms(self, binsize=None, bin_overlap=0, db=True): """ Calculation of root mean squared value (rms) of the signal in upa for each bin - Returns Dataframe with 'datetime' as index and 'rms' value as a column + Returns Dataset with 'datetime' as coordinate and 'rms' value as a variable Parameters ---------- @@ -558,10 +561,25 @@ def rms(self, binsize=None, bin_overlap=0, db=True): rms_ds = self._apply(method_name='rms', binsize=binsize, bin_overlap=bin_overlap, db=db) return rms_ds + def kurtosis(self, binsize=None, bin_overlap=0): + """ + Calculation of kurtosis value of the signal for each bin + Returns Dataset with 'datetime' as coordinate and 'kurtosis' value as a variable + + Parameters + ---------- + binsize : float, in sec + Time window considered. If set to None, only one value is returned + bin_overlap : float [0 to 1] + Percentage to overlap the bin windows + """ + kurtosis_ds = self._apply(method_name='kurtosis', binsize=binsize, bin_overlap=bin_overlap, db=False) + return kurtosis_ds + def aci(self, binsize=None, bin_overlap=0, nfft=1024, fft_overlap=0.5): """ Calculation of root mean squared value (rms) of the signal in upa for each bin - Returns Dataframe with 'datetime' as index and 'rms' value as a column + Returns Dataset with 'datetime' as coordinate and 'aci' value as a variable Parameters ---------- @@ -581,7 +599,7 @@ def aci(self, binsize=None, bin_overlap=0, nfft=1024, fft_overlap=0.5): def dynamic_range(self, binsize=None, bin_overlap=0, db=True): """ Compute the dynamic range of each bin - Returns a dataframe with datetime as index and dr as column + Returns a Dataset with 'datetime' as coordinate and 'dr' as variable Parameters ---------- diff --git a/pypam/signal.py b/pypam/signal.py index 1f22db9..af62ea2 100644 --- a/pypam/signal.py +++ b/pypam/signal.py @@ -289,7 +289,7 @@ def window_method(self, method_name, window, **kwargs): time.append(block.time) return time, output - def rms(self, db=True, **kwargs): + def rms(self, db=True, energy_window = None, **kwargs): """ Calculation of root mean squared value (rms) of the signal in uPa @@ -297,13 +297,42 @@ def rms(self, db=True, **kwargs): ---------- db : bool If set to True the result will be given in db, otherwise in uPa + energy_window: float + If provided, calculate the rms over the given energy window (e.g. RMS_90 + for energy_window= .9). """ - rms_val = utils.rms(self.signal) + if energy_window: + [start, end] = utils.energy_window(self.signal, energy_window) + rms_val = utils.rms(self.signal[start:end]) + else: + rms_val = utils.rms(self.signal) # Convert it to db if applicable if db: rms_val = utils.to_db(rms_val, ref=1.0, square=True) return rms_val + def pulse_width(self, energy_window, **kwargs): + """ + Returns the pulse width of an impulsive signal + according to a fractional energy window + + Parameters + ---------- + energy_window : float [0,1] + given energy window to calculate pulse width + **kwargs : TYPE + DESCRIPTION. + + Returns + ------- + tau: float + energy_window pulse width in seconds + + """ + [start, end] = utils.energy_window(self.signal, energy_window) + + return (end - start) / self.fs + def dynamic_range(self, db=True, **kwargs): """ Compute the dynamic range of each bin @@ -323,8 +352,19 @@ def dynamic_range(self, db=True, **kwargs): def sel(self, db=True, **kwargs): """ Calculate the sound exposure level of an event + + Parameters + ---------- + db : bool + If set to True the result will be given in db, otherwise in uPa + + Returns + ------- + sel: float + sound exposure level """ y = utils.sel(self.signal, self.fs) + if db: y = utils.to_db(y, square=False) return y @@ -339,6 +379,16 @@ def peak(self, db=True, **kwargs): y = utils.to_db(y, square=True) return y + def kurtosis(self, **kwargs): + """ + Calculation of kurtosis of the signal + + Parameters + ---------- + + """ + return utils.kurtosis(self.signal) + def third_octave_levels(self, db=True, **kwargs): """ Calculation of calibrated 1/3-octave band levels diff --git a/pypam/units.py b/pypam/units.py index a61b64e..a913fb7 100644 --- a/pypam/units.py +++ b/pypam/units.py @@ -17,7 +17,8 @@ 'aei': ('AEI', 'unitless'), 'adi': ('ADI', 'unitless'), 'zcr': ('zcr', 'unitless'), - 'zcr_avg': ('zcr_avg', 'unitless') + 'zcr_avg': ('zcr_avg', 'unitless'), + 'kurtosis': ('Kurtosis', 'unitless'), } diff --git a/pypam/utils.py b/pypam/utils.py index 4256065..94becca 100644 --- a/pypam/utils.py +++ b/pypam/utils.py @@ -120,7 +120,7 @@ def sel(signal, fs): Parameters ---------- signal : numpy array - Signal to compute the dynamic range + Signal to compute the SEL fs : int Sampling frequency """ @@ -135,11 +135,53 @@ def peak(signal): Parameters ---------- signal : numpy array - Signal to compute the dynamic range + Signal to compute the peak value """ return np.max(np.abs(signal)) +@nb.njit +def kurtosis(signal): + """ + Return the kurtosis of the signal according to Muller et al. 2020 + Parameters + ---------- + signal : numpy array + Signal to compute the kurtosis + """ + n = len(signal) + var = (signal - np.mean(signal)) ** 2 + mu4 = np.sum(var ** 2) / n + mu2 = np.sum(var) / (n-1) + return mu4/mu2 ** 2 + +@nb.njit +def energy_window(signal, percentage): + """ + Return sample window [start, end] which contains a given percentage of the + signals total energy. See Madsen 2005 for more details. + Parameters + ---------- + signal : numpy array + Signal to compute the sel + percentage : float between [0,1] + percentage of total energy contained in output window + """ + # calculate beginning and ending percentage window (e.g., for x=90%, window = [5%,95%]) + percent_start = .50 - percentage / 2 + percent_end = .50 + percentage / 2 + + # calculate normalized cumulative energy distribution + Ep_cs = np.cumsum(signal ** 2) + Ep_cs_norm = Ep_cs / np.max(Ep_cs) + + # find corresponding indices + iStartPercent = np.argmin(np.abs(Ep_cs_norm - percent_start)) + iEndPercent = np.argmin(np.abs(Ep_cs_norm - percent_end)) + + window = [iStartPercent, iEndPercent] + return window + @nb.njit def set_gain(wave, gain): """ diff --git a/tests/test_acoustic_file.py b/tests/test_acoustic_file.py index eceb1ec..4d9ac0b 100644 --- a/tests/test_acoustic_file.py +++ b/tests/test_acoustic_file.py @@ -4,15 +4,18 @@ from tests import skip_unless_with_plots import pathlib import matplotlib.pyplot as plt - +import numpy as np +import os plt.rcParams.update(plt.rcParamsDefault) +# get relative path +test_dir = os.path.dirname(__file__) # Hydrophone Setup # If Vpp is 2.0 then it means the wav is -1 to 1 directly related to V model = 'ST300HF' name = 'SoundTrap' serial_number = 67416073 -calibration_file = pathlib.Path("tests/test_data/calibration_data.xlsx") +calibration_file = pathlib.Path(f"{test_dir}/test_data/calibration_data.xlsx") soundtrap = pyhy.soundtrap.SoundTrap(name=name, model=model, serial_number=serial_number, calibration_file=calibration_file, val='sensitivity', freq_col_id=1, val_col_id=29, start_data_id=6) @@ -20,7 +23,7 @@ class TestAcuFile(unittest.TestCase): def setUp(self) -> None: - self.acu_file = AcuFile('tests/test_data/67416073.210610033655.wav', soundtrap, 1) + self.acu_file = AcuFile(f'{test_dir}/test_data/67416073.210610033655.wav', soundtrap, 1) @skip_unless_with_plots() def test_plots(self): @@ -39,3 +42,23 @@ def test_update_freq_cal(self): ds_psd_updated = self.acu_file.update_freq_cal(ds=ds_psd, data_var='band_density') print(ds_psd['band_density'].values) print(ds_psd_updated['band_density'].values) + + @skip_unless_with_plots() + def test_overlapping_bins(self): + binsize, bin_overlap = 1, 0.2 + ds_rms_overlap = self.acu_file.rms(binsize, bin_overlap) + ds_rms = self.acu_file.rms(binsize, 0) + fig,ax = plt.subplots() + ax.plot(ds_rms_overlap.datetime[0:100], ds_rms_overlap.rms[0:100], label='.50 overlap') + ax.plot(ds_rms.datetime[0:100], ds_rms.rms[0:100], label='no overlap') + ax.legend() + fig.show() + # compare output time step (dt) to expected time step + step = np.mean(np.diff(ds_rms_overlap.start_sample)) + dt = step/self.acu_file.fs + expected_dt = binsize*(1-bin_overlap) + error = np.abs(dt-expected_dt) + # error should be less than soundfile dt (if rounded) + assert error<=(1/self.acu_file.fs) + + diff --git a/tests/test_acoustic_indices.py b/tests/test_acoustic_indices.py index 8f66a77..1d3b775 100644 --- a/tests/test_acoustic_indices.py +++ b/tests/test_acoustic_indices.py @@ -4,7 +4,10 @@ import pypam.acoustic_indices import pyhydrophone as pyhy import numpy as np +import os +# get relative path +test_dir = os.path.dirname(__file__) # Hydrophone Setup # If Vpp is 2.0 then it means the wav is -1 to 1 directly related to V @@ -12,7 +15,7 @@ name = 'SoundTrap' serial_number = 67416073 soundtrap = pyhy.soundtrap.SoundTrap(name=name, model=model, serial_number=serial_number) -acu_file = AcuFile(sfile='tests/test_data/67416073.210610033655.wav', hydrophone=soundtrap, p_ref=1) +acu_file = AcuFile(sfile=f'{test_dir}/test_data/67416073.210610033655.wav', hydrophone=soundtrap, p_ref=1) class TestAcousticIndices(unittest.TestCase): diff --git a/tests/test_acoustic_survey.py b/tests/test_acoustic_survey.py index c4474d2..7d16cbd 100644 --- a/tests/test_acoustic_survey.py +++ b/tests/test_acoustic_survey.py @@ -2,6 +2,7 @@ import pathlib import matplotlib.pyplot as plt import numpy as np +import os from pypam.acoustic_survey import ASA import pyhydrophone as pyhy @@ -9,15 +10,18 @@ plt.rcParams.update(plt.rcParamsDefault) +# get relative path +test_dir = os.path.dirname(__file__) + # Data information -folder_path = pathlib.Path('tests/test_data') +folder_path = pathlib.Path(f'{test_dir}/test_data') # Hydrophone Setup # If Vpp is 2.0 then it means the wav is -1 to 1 directly related to V model = 'ST300HF' name = 'SoundTrap' serial_number = 67416073 -calibration_file = pathlib.Path("tests/test_data/calibration_data.xlsx") +calibration_file = pathlib.Path(f"{test_dir}/test_data/calibration_data.xlsx") soundtrap = pyhy.soundtrap.SoundTrap(name=name, model=model, serial_number=serial_number, calibration_file=calibration_file, val='sensitivity', freq_col_id=1, val_col_id=29, start_data_id=6) diff --git a/tests/test_data/impulsive_data/madsen_digitized_signal.csv b/tests/test_data/impulsive_data/madsen_digitized_signal.csv new file mode 100644 index 0000000..f1a5f13 --- /dev/null +++ b/tests/test_data/impulsive_data/madsen_digitized_signal.csv @@ -0,0 +1,417 @@ +-419.1446135985857, 5.6166382733781575 +-415.90459354634436, 5.6166382733781575 +-412.66457349410297, 5.6166382733781575 +-409.4245534418616, 5.6166382733781575 +-406.18453338962024, 3.8316403956068825 +-402.94451333737885, 2.0466425178356076 +-399.7044932851375, 2.0466425178356076 +-396.4644732328961, 2.0466425178356076 +-393.2244531806548, 2.0466425178356076 +-389.9844331284134, 2.0466425178356076 +-386.744413076172, 2.0466425178356076 +-383.5043930239307, 2.0466425178356076 +-380.26437297168934, 2.0466425178356076 +-377.02435291944795, 2.0466425178356076 +-373.78433286720656, 2.0466425178356076 +-370.5443128149652, 2.0466425178356076 +-367.3042927627239, 2.0466425178356076 +-364.0642727104825, 2.0466425178356076 +-360.8242526582411, 2.0466425178356076 +-357.5842326059998, 2.0466425178356076 +-354.3442125537584, 2.0466425178356076 +-351.104192501517, 4.72413933449252 +-347.86417244927566, 5.6166382733781575 +-344.6241523970343, 5.6166382733781575 +-341.38413234479293, 5.6166382733781575 +-338.14411229255154, 5.6166382733781575 +-334.9040922403102, 5.6166382733781575 +-331.6640721880689, 5.6166382733781575 +-328.4240521358275, 4.72413933449252 +-325.1840320835861, 5.6166382733781575 +-321.94401203134476, 2.939141456721245 +-318.7039919791034, 2.939141456721245 +-315.46397192686203, 0.2616446400647874 +-312.22395187462064, -3.3083511154777625 +-308.9839318223793, -5.0933489932490374 +-305.7439117701379, -5.0933489932490374 +-302.5038917178965, -7.77084580990595 +-299.2638716656552, -12.233340504334137 +-296.02385161341385, -12.233340504334137 +-292.78383156117246, -14.91083732099105 +-289.54381150893107, -22.05082883207615 +-286.30379145668974, -28.29832140427561 +-283.0637714044484, -30.975818220932524 +-279.823751352207, -33.65331503758944 +-276.5837312999656, -33.65331503758944 +-273.3437112477243, -30.975818220932524 +-270.1036911954829, -30.975818220932524 +-266.8636711432415, -27.405822465389974 +-263.62365109100017, -20.265830954304874 +-260.38363103875884, -19.373332015419237 +-257.14361098651744, -20.265830954304874 +-253.90359093427608, -26.513323526504337 +-250.66357088203472, -38.11580973201717 +-247.66655233371145, -53.64529126862726 +-244.4265322814701, -70.78127089523105 +-243.13052426057354, -92.91524457959486 +-240.3765072161684, -106.48122845065609 +-239.32350069918994, -125.58070574280873 +-236.08348064694857, -130.04320043723692 +-232.8434605947072, -126.47320468169437 +-229.6612980433987, -113.21322044682256 +-227.9024300150391, -81.4912581618587 +-226.36342049022448, -44.958301596806905 +-224.66240996279777, -7.235346446574567 +-223.1234004379831, 29.416609976995005 +-221.50339041186243, 68.09156399537233 +-219.9643808870478, 109.8605143352197 +-218.46587161288613, 142.1689759228791 +-215.83335532044003, 163.58895045613417 +-212.5933352681987, 158.23395682282035 +-210.89232474077193, 126.28249481071475 +-209.3533152159573, 80.5865491397708 +-208.54331020289698, 44.88659158434575 +-207.1663016806944, 10.614632331137727 +-206.5182976702461, -16.99333484505769 +-205.54629165457374, -50.07529551308471 +-204.5742856389013, -84.34725476629274 +-203.48077887126982, -125.58070574280873 +-202.4682726049444, -153.8431721408533 +-200.71326174331364, -194.89812332959218 +-199.6332550592332, -222.86309008134185 +-196.4742355082979, -218.5790951746908 +-194.7732249808712, -184.18813606296453 +-193.15321495475047, -124.09320751133282 +-193.96321996781086, -155.0331707260343 +-191.45220442732375, -39.365308246457516 +-191.93820743516, -69.35327259301448 +-192.34320994169013, -94.34324288181188 +-191.12820242209966, -6.283347578430039 +-190.31819740903927, 30.606608562176007 +-188.96818905393872, 102.60152296561637 +-189.3056911427139, 67.19906505648669 +-188.6981873829186, 144.846472739536 +-187.72618136724623, 189.11442010826295 +-187.07817735679794, 281.39881038903695 +-187.48317986332808, 244.80635389472627 +-187.88818236985827, 226.95637511701375 +-186.53817401475771, 324.536259101842 +-185.29616632806517, 429.7321340318281 +-185.8631698372074, 391.176179871969 +-185.8631698372074, 367.97120746094265 +-184.48616131500484, 520.4100262226075 +-185.05316482414707, 487.5660652716165 +-185.45816733067727, 469.71608649390396 +-183.25958229522774, 619.1459088330403 +-183.83815730455655, 582.7659520860834 +-184.24315981108674, 558.9659803824668 +-182.86615128888417, 669.6358488042843 +-181.73214427059963, 769.5957299594745 +-182.21814727843588, 737.465768159592 +-182.62314978496607, 712.4757978707944 +-181.40814226537555, 826.7156620481546 +-181.40814226537555, 798.1556960038145 +-180.43613624970317, 868.8416119635563 +-179.20955722992602, 969.0054928762058 +-179.78813223925488, 931.435537544068 +-179.78813223925488, 906.4455672552706 +-178.81612622358244, 1019.4954328474498 +-177.9656209598691, 1057.8728872195318 +-176.87211419223763, 1148.7292791980885 +-177.35811720007382, 1114.6953196619168 +-177.76311970660402, 1090.8953479583 +-176.5481121870135, 1181.3352404320435 +-175.15953216462435, 1248.995159989468 +-176.14310968048335, 1212.2752036467452 +-174.60410015566868, 1297.2411026286568 +-172.7295171254433, 1359.155029017637 +-173.7130946413023, 1322.9450720685627 +-171.20207910081524, 1398.6289820860638 +-168.98806539845032, 1389.5849928386897 +-167.63805704334976, 1355.0750338684454 +-167.8405582966148, 1323.8375710074483 +-166.82805203028943, 1295.5751046094038 +-165.856046014617, 1252.2591561088211 +-165.6130445106989, 1217.6301972800588 +-165.0055407509036, 1181.9302397246338 +-164.60053824437347, 1141.7677874747806 +-163.85803364906815, 1107.5553281508317 +-163.58803197804804, 1076.61536493613 +-163.58803197804804, 1048.05539889179 +-163.18302947151784, 1017.7104349696785 +-163.0480286360078, 994.5054625586524 +-162.7780269649877, 967.135495099493 +-162.9805282182528, 936.4930315310867 +-162.3730244584575, 905.2555686700898 +-161.96802195192737, 876.2989364306895 +-161.96802195192737, 848.1356365814097 +-161.96802195192737, 819.5756705370695 +-161.56301944539717, 792.8007023705009 +-160.99601593625493, 752.4597503328705 +-161.36051819213208, 712.4757978707944 +-160.61801359682676, 672.015845974646 +-160.55051317907174, 637.5058870044018 +-159.80800858376642, 602.9959280341575 +-159.5380069127463, 564.9159733083709 +-159.5380069127463, 536.356007264031 +-159.5380069127463, 507.7960412196908 +-159.37600591013427, 474.000081400555 +-158.72800189968598, 445.91611479028734 +-158.72800189968598, 417.35614874594717 +-158.93050315295108, 384.0361883608839 +-158.32299939315584, 359.0462180720863 +-158.32299939315584, 330.48625202774633 +-157.91799688662564, 300.7362873982254 +-157.91799688662564, 272.1763213538852 +-157.91799688662564, 243.61635530954527 +-157.51299438009545, 214.46138997261482 +-157.51299438009545, 186.79392286716052 +-157.1079918735653, 155.55646000616366 +-157.1079918735653, 126.99649396182349 +-157.1079918735653, 97.24652933230254 +-156.70298936703512, 69.8765618731436 +-156.29798686050498, 38.93659865844165 +-156.29798686050498, 11.566631199282256 +-155.89298435397478, -19.373332015419237 +-155.48798184744464, -51.50329381530173 +-155.48798184744464, -80.06325985964168 +-155.48798184744464, -108.62322590398162 +-155.48798184744464, -137.18319194832202 +-155.08297934091445, -163.9581601148907 +-154.4754755811192, -199.65811767031573 +-154.6779768343843, -232.3830787627885 +-154.88047808764935, -263.0255423311951 +-154.27297432785412, -294.26300519219194 +-153.86797182132392, -325.2029684068939 +-153.86797182132392, -353.76293445123383 +-153.86797182132392, -382.3229004955738 +-153.86797182132392, -410.8828665399137 +-153.86797182132392, -439.44283258425367 +-153.46296931479378, -472.7627929693176 +-153.59797015030387, -508.46275052474266 +-153.0579668082636, -529.8827250579975 +-153.0579668082636, -558.4426911023374 +-152.78796513724348, -596.522645828124 +-152.24796179520325, -622.7026147021024 +-151.84295928867311, -661.97256801307 +-151.84295928867311, -690.5325340574104 +-151.84295928867311, -719.0925001017504 +-151.43795678214292, -751.2224619016329 +-152.24796179520325, -761.9324491682605 +-151.03295427561272, -786.9224194570579 +-151.03295427561272, -815.4823855013979 +-151.03295427561272, -844.0423515457378 +-151.03295427561272, -872.6023175900782 +-150.83045302234768, -907.4097762066176 +-150.2229492625524, -933.2922454343006 +-150.2229492625524, -961.8522114786406 +-149.61544550275715, -992.4946750470472 +-149.81794675602225, -1024.9221364932246 +-149.41294424949206, -1051.1021053672034 +-148.80544048969682, -1086.8020629226285 +-149.21044299622696, -1121.6095215391679 +-148.19793672990153, -1160.58197520384 +-148.19793672990153, -1189.14194124818 +-148.03593572728948, -1221.0339033310265 +-147.3879317168412, -1251.0218676775835 +-147.3879317168412, -1279.5818337219234 +-146.57792670378086, -1309.3317983514448 +-145.97042294398562, -1342.0567594439176 +-145.1604179309253, -1370.6167254882575 +-144.01291082908978, -1402.1516879955498 +-142.122899131949, -1413.4566745547677 +-140.42188860452228, -1379.541714877114 +-139.44988258884985, -1345.9837547750144 +-138.31587557056542, -1290.291820988551 +-139.2878815862378, -1322.4217827884336 +-137.50587055750503, -1222.4619016332435 +-137.66787156011713, -1254.591863433126 +-137.26286905358694, -1179.6219525667334 +-136.31786320501652, -1140.3519992557658 +-135.07585551832403, -1044.6761130072268 +-135.64285902746627, -1083.232067167086 +-135.64285902746627, -1106.437039578112 +-133.84927649854694, -893.0022933360351 +-134.42785150787574, -934.4822440194816 +-134.42785150787574, -959.472214308279 +-134.83285401440594, -990.4121775229805 +-135.23785652093608, -1008.2621563006933 +-133.45584549220337, -832.6183651280016 +-134.42785150787574, -858.322334567908 +-132.64584047914303, -771.9284372837792 +-133.6178464948154, -794.062410968143 +-131.41926145936588, -638.0025965115706 +-131.99783646869474, -677.4425496204212 +-131.99783646869474, -706.0025156647612 +-131.99783646869474, -730.9924859535586 +-131.1878314556344, -594.1426486577625 +-129.70282226502377, -480.49778377299253 +-130.37782644257402, -513.2227448654658 +-130.37782644257402, -539.4027137394442 +-130.7828289491042, -565.5826826134225 +-129.40582042690164, -425.63884899615596 +-130.37782644257402, -451.3428184360623 +-128.5958154138413, -345.6709440720042 +-128.75781641645335, -382.3229004955738 +-127.27280722584277, -241.30806815164487 +-127.94781140339302, -275.22302782929864 +-127.94781140339302, -301.40299670327704 +-126.97580538772064, -184.30713592148322 +-127.94781140339302, -215.7230985702572 +-126.32780137727235, -131.8281983150082 +-124.93922135488316, -30.593318675695627 +-125.51779636421202, -70.54327117819503 +-125.92279887074216, -94.34324288181188 +-124.70779135115168, 16.326625540005807 +-123.49278383156116, 115.09650811001507 +-123.8977863380913, 77.01655338422825 +-124.30278884462149, 52.02658309543085 +-122.88528007176586, 159.12645576170598 +-122.11577530935858, 211.24839379262676 +-123.08778132503096, 184.1164260505036 +-121.14376929368615, 289.78830041456195 +-121.2652700456452, 252.83884434469678 +-120.65776628584996, 330.48625202774633 +-119.84776127278963, 403.6711650163677 +-120.25276377931976, 366.1862095831714 +-119.44275876625943, 441.156120449564 +-118.6327537531991, 471.50108437167523 +-117.25574523099652, 553.2539871735985 +-117.82274874013876, 519.6960270714992 +-117.82274874013876, 496.49105466047286 +-116.2027387140181, 603.590927326748 +-114.50172818659132, 647.5018751199209 +-113.77272367483704, 678.5608381931406 +-112.07171314741032, 706.7638046619263 +-109.47969710561722, 723.185785137422 +-107.09018231708922, 711.5832989319088 +-105.67267354423365, 683.9158318264545 +-104.94366903247936, 652.4998691776802 +-103.48566000897074, 616.7999116222552 +-102.18965198807416, 567.5339701957687 +-101.21764597240178, 530.4060143381266 +-100.40764095934139, 498.27605253824413 +-100.00263845281125, 469.71608649390396 +-99.19263343975092, 438.4786236329071 +-98.38262842669059, 409.0261586496815 +-97.81562491754835, 373.3262010942565 +-96.76261840056986, 341.19623929437375 +-96.19561489142768, 305.4962817389487 +-95.75011213424443, 272.4738210001806 +-94.33260336138886, 241.23635813918372 +-93.60359884963458, 202.68040397932486 +-93.92760085485867, 174.59643736905696 +-92.17258999322792, 135.3264840580896 +-91.70008706894276, 97.54402897859791 +-90.89008205588243, 67.19906505648669 +-89.64614578582547, 27.546612200282198 +-88.66256826996647, -9.555843687677225 +-87.85256325690614, -38.11580973201717 +-87.44756075037594, -65.78327683747193 +-86.63755573731561, -95.53324146699288 +-85.82755072425527, -124.09320751133282 +-84.20754069813461, -160.9831636519384 +-83.9375390271145, -183.59313677037426 +-83.07353367985013, -211.4391036636057 +-81.37252315242341, -246.6630617849587 +-79.6715126249967, -278.5550238678052 +-77.32249808712169, -306.1629910440006 +-74.08247803488035, -316.5754786643329 +-70.84245798263896, -308.54298821436214 +-68.00744043692777, -277.3055253533653 +-65.8088554014783, -241.22306825270334 +-64.09241620713607, -205.60811059621983 +-62.74240785203557, -167.52815587043324 +-61.041397324608795, -137.18319194832202 +-59.50238779979418, -97.31823934476415 +-57.708805270874905, -56.09328835814222 +-56.262367747552844, -17.588334137647962 +-54.64235772143212, 12.756629784463257 +-53.832352708371786, 43.10159370657448 +-51.807340175720924, 79.69405020088516 +-49.60875514027151, 119.34650305708965 +-46.54230759082873, 151.9864642506211 +-43.302287538587336, 168.05144515056236 +-40.062267486346, 168.05144515056236 +-36.82224743410461, 155.55646000616366 +-33.58222738186328, 128.78149183959476 +-31.69221568472244, 102.0065236730261 +-28.965198807419313, 86.29854234863888 +-27.66919078652279, 61.30857205984148 +-24.915173742117588, 44.88659158434575 +-23.86216722513916, 24.359115989976544 +-20.865148676815863, 7.758635726704142 +-17.382127120656435, -15.803336259876687 +-15.762117094535768, -35.43831291536026 +-12.76509854621247, -47.93329805975918 +-9.282076990053042, -63.998278959700656 +-6.042056937811651, -69.35327259301448 +-2.802036885570317, -71.13827047078576 +0.4379831666710743, -69.35327259301448 +3.6780032189124086, -64.8907778985863 +6.9180232711538, -54.180790631958644 +10.158043323395134, -45.25580124310227 +13.398063375636525, -34.545813976475074 +16.63808342787786, -21.158329893190512 +19.87810348011925, -12.233340504334137 +23.118123532360585, -4.2008500543634 +26.358143584602033, 2.939141456721245 +29.598163636843367, 7.401636151149432 +32.8381836890847, 19.00412235666272 +36.078203741326035, 24.359115989976544 +39.31822379356748, 31.499107501061644 +42.55824384580882, 36.85410113437547 +45.79826389805015, 37.746600073261106 +49.038283950291486, 36.85410113437547 +52.278304002532934, 30.606608562176007 +55.51832405477427, 24.359115989976544 +58.7583441070156, 18.111623417777082 +61.99836415925705, 6.509137212263795 +65.23838421149838, 0.2616446400647874 +68.47840426373972, -6.878346871020312 +71.71842431598105, -11.3408415654485 +74.9584443682225, -12.233340504334137 +78.19846442046384, -12.233340504334137 +81.43848447270517, -11.3408415654485 +84.6785045249465, -5.0933489932490374 +87.91852457718795, 2.0466425178356076 +91.15854462942929, 7.401636151149432 +94.39856468167062, 16.326625540005807 +97.63858473391196, 23.466617051090907 +100.8786047861534, 32.39160643994728 +104.11862483839474, 37.746600073261106 +107.35864489063607, 43.10159370657448 +110.59866494287752, 50.241585217659576 +113.83868499511885, 52.02658309543085 +117.07870504736019, 58.27407566763031 +120.31872509960152, 59.16657460651595 +123.55874515184297, 59.16657460651595 +126.7987652040843, 59.16657460651595 +130.03878525632564, 53.811580973202126 +133.27880530856697, 46.671589462117026 +136.51882536080842, 36.85410113437547 +139.75884541304976, 25.251614928862182 +142.9988654652911, 12.756629784463257 +146.23888551753254, -2.415852176592125 +149.47890556977387, -17.588334137647962 +151.90892060895493, -35.43831291536026 +155.14894066119626, -47.040799120873544 +158.3889607134376, -54.180790631958644 +161.62898076567893, -62.21328108192938 +164.86900081792038, -62.21328108192938 +168.10902087016171, -55.07328957084428 +171.34904092240305, -47.93329805975918 +174.58906097464438, -36.330811854245894 +177.82908102688583, -22.943327770961787 +181.06910107912717, -11.3408415654485 +184.3091211313685, 2.939141456721245 +187.54914118360983, 11.86413084557762 +190.78916123585128, 19.00412235666272 +194.02918128809262, 23.466617051090907 +197.26920134033395, 23.466617051090907 +200.5092213925754, 23.466617051090907 +203.74924144481673, 22.57411811220527 +206.98926149705807, 19.896621295548357 +210.2292815492994, 19.896621295548357 +213.46930160154085, 19.896621295548357 +215.8993166407218, 19.896621295548357 diff --git a/tests/test_data/impulsive_data/madsen_digitized_signal_2.csv b/tests/test_data/impulsive_data/madsen_digitized_signal_2.csv new file mode 100644 index 0000000..baafa7e --- /dev/null +++ b/tests/test_data/impulsive_data/madsen_digitized_signal_2.csv @@ -0,0 +1,251 @@ +-70.53873332452781, 7.879572209048092 +-69.62637036058645, 4.817510603759729 +-68.7140073966451, 4.817510603759729 +-67.80164443270374, 1.5002771980307443 +-66.88928146876239, 0.2244181958271838 +-65.97691850482103, 0.47958999626780496 +-65.06455554087968, 4.3071670028784865 +-64.15219257693832, 4.817510603759729 +-63.23982961299697, -2.0721280081388613 +-62.32746664905561, -19.934154038987344 +-61.41510368511426, -24.52724644691989 +-60.5027407211729, -2.8376434094611795 +-59.59037775723155, 22.42436483416759 +-58.67801479329019, 31.865721450473302 +-57.76565182934884, 29.31400344606618 +-56.85328886540748, 23.189880235489454 +-55.94092590146612, 12.472664616980637 +-55.02856293752477, -0.2859254050540585 +-54.11619997358341, -9.472110220918694 +-53.20383700964206, -9.216938420478073 +-52.2914740457007, -1.561784407257619 +-51.37911108175935, -5.389361413867846 +-50.46674811781799, -15.851405231936042 +-49.55438515387664, -17.89277963546192 +-48.64202218993528, -4.879017812986149 +-47.72965922599393, 4.562338803319108 +-46.81729626205257, 2.0106207989124414 +-45.90493329811122, -9.216938420478073 +-44.99257033416986, -12.789343626647678 +-44.08020737022851, -5.644533214308467 +-43.16784440628715, 7.36922860816685 +-42.2554814423458, 15.534726222268546 +-41.34311847840444, 8.134744009488713 +-40.43075551446309, -7.43073581739327 +-39.51839255052173, -6.9203922165120275 +-38.60602958658038, 6.603713206844986 +-37.69366662263902, 11.196805614777077 +-36.78130365869767, -1.3066126068165431 +-35.86894069475631, -7.941079418274512 +-34.95657773081495, 5.838197805522668 +-34.044214766873594, 17.831272426235046 +-33.13185180293224, 6.093369605963289 +-32.219488838990884, -17.6376078350213 +-31.30712587504953, -33.20308766190328 +-30.394762911108174, -38.30652367071707 +-29.48239994716682, -28.354823453530116 +-28.570036983225464, -9.98245382180039 +-27.65767401928411, 12.472664616980637 +-26.745311055342754, 29.569175246506802 +-25.8329480914014, 31.610549650032226 +-24.920585127460043, 19.107131428438606 +-24.00822216351869, -3.0928152099018007 +-23.095859199577333, -18.658295036783784 +-22.183496235635978, -20.444497639868587 +-21.271133271694623, -12.534171826207057 +-20.35877030775326, -2.0721280081388613 +-19.446407343811913, -5.134189613427225 +-18.53404437987055, -2.0721280081388613 +-17.621681415929203, 30.589862448269287 +-16.70931845198784, 27.527800842981378 +-16.173486235069902, -18.476029465040483 +-15.898329150706644, -71.22368592756584 +-15.530849623563597, -120.91839406339068 +-14.866160949076018, -129.0085000091808 +-14.47909787346454, -65.8012851682015 +-14.276350548144237, -18.30105451616646 +-14.174976885484085, 38.117430561269884 +-14.022916391493851, 139.4525318112794 +-14.141185664597359, 92.85178175579813 +-13.887751507946987, 197.72739173692207 +-13.72893276977942, 296.01956926667617 +-13.972229560163782, 255.14104683607752 +-13.566734909523177, 432.38520207789884 +-13.61742174085326, 372.2649032383547 +-13.76948223484348, 342.40980258679383 +-13.414674415532957, 551.969643698711 +-13.516048078193108, 491.6853058445979 +-13.282888654074767, 617.9953470627399 +-13.123225135385013, 748.0372758623269 +-13.211927090212654, 692.0589621406505 +-13.313300752872806, 654.7400863261994 +-12.958492933562269, 859.592007719986 +-13.05986659622242, 810.905228195902 +-12.840223660458776, 975.1082817794868 +-12.9078061022322, 925.732538394213 +-12.958492933562269, 893.580891538686 +-12.772641218685322, 1051.5832703715619 +-12.9078061022322, 1017.5943865528618 +-12.552998282921678, 1141.9906392676985 +-12.654371945581829, 1100.2700498956456 +-12.400937788931444, 1245.8136655720045 +-12.552998282921678, 1198.256021264871 +-12.248877294941224, 1318.4419392724362 +-12.09681680095099, 1380.8314444801852 +-11.578251526574064, 1448.6102471649938 +-11.032393343019407, 1412.6003336350511 +-11.012118610487377, 1366.6694095557268 +-10.880332849029188, 1331.6470799452418 +-10.694481134152241, 1276.9947482579983 +-10.576211861048733, 1236.9145490316355 +-10.606623959846772, 1193.9691350174671 +-10.37346453572843, 1162.2767974027333 +-10.403876634526469, 1115.8865640826157 +-10.241678774270241, 1071.7928769664645 +-10.192440138121015, 1023.7810008166075 +-10.018656716417908, 973.5006994367104 +-9.917283053757757, 908.6360277646868 +-9.79901378065425, 846.1189366567176 +-9.663848897107385, 788.7052815575621 +-9.694260995905424, 732.8226572610508 +-9.511788403117151, 693.7813717936251 +-9.461101571787083, 639.429778299758 +-9.352486933222636, 577.8292226382696 +-9.135257656093742, 515.6350019716742 +-9.140084973363273, 458.0026281864268 +-9.055606921146477, 391.4984776965716 +-8.84561861992188, 323.38127689678777 +-8.802172764496106, 270.4513548625189 +-8.781898031964062, 227.1231831476896 +-8.657353246410167, 173.9964142959377 +-8.624768854840838, 112.75518219017204 +-8.413573724298857, 63.76219650555936 +-8.477777043983608, 10.32922149327851 +-8.345991282525418, -30.778955557716472 +-8.376403381323456, -76.93953425743757 +-8.193930788535198, -114.60289200248371 +-8.109452736318403, -162.4476045851129 +-8.041870294544964, -229.14313392529857 +-7.901073540850319, -294.83924038042414 +-7.7884361378945925, -369.5195206427338 +-7.768161405362562, -432.90419587220094 +-7.58568881257429, -469.6489351356604 +-7.545139347510229, -518.3357146597446 +-7.349150266367275, -587.6914100195245 +-7.230880993263767, -648.549884424629 +-7.213985382820411, -695.6290816059363 +-7.139644696869638, -747.0717165747801 +-7.064338547464956, -795.3648024638978 +-6.9571721040813514, -840.4645955360725 +-6.8557984414212, -892.2134366654445 +-6.673325848632942, -932.6326498552503 +-6.653051116100897, -981.319429379334 +-6.521265354642708, -1019.4420963651733 +-6.5043697441993515, -1068.4350820497857 +-6.369204860652488, -1120.4901293396865 +-6.2678311979923365, -1171.4734550677367 +-6.166457535332185, -1214.189214461508 +-6.053820132376458, -1272.8276942027792 +-5.896127768238458, -1328.3275607986293 +-5.717517029265807, -1381.3121625044218 +-5.17806432439572, -1418.8497570049644 +-4.645852595429929, -1353.5895690422576 +-4.4532426363756485, -1278.4925081725623 +-4.696539426759998, -1400.6687662235654 +-4.3924184387795435, -1219.2416161102342 +-4.217830464198187, -1138.6073271709756 +-4.291044776119392, -1183.6451499487575 +-4.015083138877884, -1003.7308040808966 +-4.138984282129172, -1061.5454434378871 +-4.240357944789324, -1090.635028688126 +-3.974252080306428, -876.3098542029784 +-3.9565116893409, -938.1443607447691 +-3.791417438722945, -726.468416344911 +-3.885550125478801, -777.1564718467371 +-3.885550125478801, -818.4943035181291 +-3.6610798724456117, -666.7582150417898 +-3.518070598335754, -528.2682769918983 +-3.581429137498347, -588.8396831215073 +-3.581429137498347, -607.212052753237 +-3.3279949808479614, -397.0780750903282 +-3.378681812178044, -451.04691088353457 +-3.4293686435081128, -479.7537384331122 +-3.1928300973010977, -243.84740892569334 +-3.277308149517893, -306.3645000336628 +-3.277308149517893, -347.70233170505435 +-3.0528378964847036, -173.98501527646704 +-2.8718134988772874, -61.20819276026896 +-3.0238739928675216, -110.77531499587303 +-2.7197530048870675, 47.01654710163916 +-2.770439836217136, -12.406585925986747 +-2.5676925108968334, 149.21285317813567 +-2.685961784000341, 102.03796657166322 +-2.4156320169066134, 210.35839585873623 +-1.8918680931625005, 249.97381787715358 +-1.387413438496523, 196.41507962037008 +-1.24983489631488, 142.99304054239383 +-1.09777440232466, 97.59797724399505 +-0.9457139083344259, 59.5518617982882 +-0.793653414344206, 13.544386178831246 +-0.6488338962582674, -34.879930921942105 +-0.3447129082778275, -91.96550799195938 +0.19111930864011129, -115.91520411903548 +0.8283251882182014, -91.38225816238082 +1.1493417866420117, -43.027201978869925 +1.7406881521595636, 8.389915809929335 +2.6530511161009116, 21.91402123328635 +3.565414080042274, 3.031308000674926 +4.477777043983622, 4.817510603759729 +5.390140007924984, -1.051440806375922 +6.302502971866332, -38.81686727159831 +7.214865935807694, -71.98920132888816 +8.127228899749042, -63.82370371478601 +8.938218201030253, -24.053355960386853 +9.749207502311464, 20.89333403152341 +10.661570466252812, 54.065668088813254 +11.573933430194174, 56.61738609321992 +12.486296394135522, 32.631236851795165 +13.347972526746801, -5.8040155895837415 +14.20964865935808, -39.07203907203893 +15.122011623299443, -54.89269069936199 +16.03437458724079, -42.1341006773273 +16.946737551182153, -18.14795143590254 +17.8591005151235, 0.7347617967084261 +18.771463479064863, -2.5824716090201036 +19.68382644300621, -23.50655924515695 +20.596189406947573, -49.789254690548205 +21.50855237088892, -48.513395688344644 +22.420915334830283, -21.720356642072147 +23.33327829877163, 1.7554489984713655 +24.245641262712994, 4.817510603759729 +25.15800422665434, 8.389915809929335 +26.070367190595704, 30.845034248710363 +26.98273015453705, 49.72774748132133 +27.895093118478414, 41.56224986721918 +28.807456082419762, 18.341616027116288 +29.719819046361124, 2.2657925993530625 +30.632182010302486, 0.2244181958271838 +31.544544974243834, 0.2244181958271838 +32.456907938185196, 0.2244181958271838 +33.369270902126544, -1.051440806375922 +34.28163386606791, -8.196251218715133 +35.193996830009254, -4.113502411664285 +36.10635979395062, 3.286479801115547 +37.018722757891965, 14.769210820946682 +37.93108572183333, 22.16919303372697 +38.843448685774675, 17.065757024913182 +39.75581164971604, 3.5416516015561683 +40.668174613657385, -7.941079418274512 +41.58053757759875, -6.410048615630785 +42.492900541540095, 5.838197805522668 +43.40526350548146, 19.107131428438606 +44.317626469422805, 17.831272426235046 +45.22998943336415, -2.5824716090201036 +46.14235239730553, -27.84447985264842 +47.05471536124688, -28.354823453530116 +47.967078325188226, 0.989933597149502 +48.87944128912957, 31.865721450473302 +49.79180425307095, 37.989844661049574 +50.7041672170123, 21.91402123328635 +51.616530180953646, 1.7554489984713655 +52.42751948223486, -8.63368859089951 diff --git a/tests/test_data/impulsive_data/pileDriving_excerpt.wav b/tests/test_data/impulsive_data/pileDriving_excerpt.wav new file mode 100644 index 0000000..118fda8 Binary files /dev/null and b/tests/test_data/impulsive_data/pileDriving_excerpt.wav differ diff --git a/tests/test_data/impulsive_data/pileDriving_results_benchmark.mat b/tests/test_data/impulsive_data/pileDriving_results_benchmark.mat new file mode 100644 index 0000000..cfe3c7a Binary files /dev/null and b/tests/test_data/impulsive_data/pileDriving_results_benchmark.mat differ diff --git a/tests/test_data/impulsive_data/pileDriving_results_pypam.csv b/tests/test_data/impulsive_data/pileDriving_results_pypam.csv new file mode 100644 index 0000000..e95f272 --- /dev/null +++ b/tests/test_data/impulsive_data/pileDriving_results_pypam.csv @@ -0,0 +1,40 @@ +,startTime,peak,rms90,sel,tau,kurtosis +0,0.554140625,163.86682478956513,153.06171297885498,141.8665748496793,0.06840625,68.53767250500586 +1,2.012671875,163.25975011637348,152.52362051693575,141.37740082324757,0.06921875,70.23873115097281 +2,3.51503125,162.99259442024064,152.62616925512964,141.4802952331525,0.069265625,66.47487711599088 +3,4.98946875,163.9044598789948,152.9048360584307,141.7538344805649,0.069203125,68.12455094304848 +4,6.45809375,162.25750936602628,152.6403402132329,141.47595855972912,0.068921875,69.81664316328656 +5,8.005078125,163.31718845000725,153.17355802110444,142.12778805547788,0.070921875,65.80219122081797 +6,9.5246875,163.74358799933424,153.53948699912542,142.38245660209483,0.069078125,66.04432388421074 +7,11.047734375,163.38778939039696,153.49967063975558,142.36107422910175,0.06940625,64.10614679831171 +8,12.551671875,164.21114071234285,153.4554843475733,142.11011535525617,0.066203125,67.67715367064457 +9,14.03325,163.2737854541844,153.5054232916613,141.9291608552555,0.062734375,65.56873732646227 +10,15.55096875,163.54809172191298,153.89636575705526,142.41428035802772,0.064125,67.12161088431702 +11,17.06571875,163.02771657271396,153.70246279968867,142.2215225695333,0.064078125,65.65713543994529 +12,18.592140625,164.1179129247255,153.80872734632422,142.2661884622113,0.06321875,69.11830727033723 +13,20.14465625,164.33236620268406,153.8472369816507,142.631511507328,0.068125,69.0393211057525 +14,21.659046875,163.99412177780007,153.97559253907087,142.5798022975438,0.06540625,68.51273445635763 +15,23.14425,163.2510089408061,153.7289579792561,142.22350986709313,0.063796875,65.04510156706253 +16,24.6599375,164.23027020907043,154.0789669519488,142.3386909883788,0.060453125,68.26117445175527 +17,26.195,164.33089538044246,153.79918412795655,142.48915749513074,0.066765625,67.75271601901109 +18,27.690046875,163.60759388551168,153.48949701827985,142.21849094691575,0.067296875,65.87758328707811 +19,29.155109375,162.7936771285904,153.41183043424425,141.9564923729882,0.064453125,64.18447004206804 +20,30.65571875,163.45927797102797,154.00817209383789,142.32987979095623,0.06125,67.88419388567098 +21,32.233625,164.7321267823662,154.0563196075609,142.89749422146625,0.069046875,69.98266319156922 +22,33.75134375,164.69220337864374,153.95847175803706,142.76039335583494,0.0684375,68.06686819970088 +23,35.225265625,164.68655877563975,153.7709145134915,142.36716407743793,0.065359375,66.35812316665427 +24,36.707109375,162.5165333652794,153.3998691872979,141.9651861898449,0.06478125,62.65081604441006 +25,38.190375,163.66202076635426,153.8440154335243,142.35135813758995,0.06396875,64.2511479298105 +26,39.676,164.13975189875538,153.57553203680436,142.22385840421902,0.06603125,63.155989951905866 +27,41.16859375,164.0572474154764,153.95583964289207,142.44723546875557,0.063671875,64.64677928327488 +28,42.683140625,164.47227512231905,153.84496501624042,142.65027931363687,0.06846875,64.82798210744251 +29,44.207671875,164.0340158236108,153.99779660062293,142.8423019856209,0.069078125,65.200307832363 +30,45.730515625,164.87902234475737,154.09259836857282,142.89021162122413,0.068421875,70.25554848755985 +31,47.264078125,165.337991297418,154.1515559886589,142.93020463601178,0.0680625,68.9840914020643 +32,48.809453125,164.96143151602723,154.53608580076826,143.18399016941865,0.066015625,69.0390658175563 +33,50.31140625,166.0084430240319,154.2732630777047,143.00541990683277,0.067359375,68.48906236427868 +34,51.823390625,164.17999113753396,154.23281200417227,142.9251653012766,0.06671875,66.31527670221281 +35,53.342515625,164.56006015525065,154.41708658100902,143.14845899550036,0.067375,65.17940513633454 +36,54.82996875,164.81352231484462,154.10007978278622,142.78356205823752,0.066546875,65.54717770679378 +37,56.33903125,165.1357840089982,154.10482454330867,142.81448967884262,0.067,68.73425291447666 +38,57.842046875,164.96155905702614,154.2571993705797,143.05001562322312,0.068265625,70.07594929140504 diff --git a/tests/test_dataset.py b/tests/test_dataset.py index fcff7ed..7cefb53 100644 --- a/tests/test_dataset.py +++ b/tests/test_dataset.py @@ -1,12 +1,15 @@ import unittest import pathlib +import os from pypam import dataset import pyhydrophone as pyhy +# get relative path +test_dir = os.path.dirname(__file__) # Acoustic Data -summary_path = pathlib.Path('tests/test_data/data_summary.csv') +summary_path = pathlib.Path(f'{test_dir}/test_data/data_summary.csv') include_dirs = False # Output folder diff --git a/tests/test_impulsive_metrics.py b/tests/test_impulsive_metrics.py new file mode 100644 index 0000000..e1f027d --- /dev/null +++ b/tests/test_impulsive_metrics.py @@ -0,0 +1,179 @@ +import numpy as np +import scipy +import pandas as pd +import os +import pyhydrophone as pyhy +import pypam +import xarray as xr + +from pypam._event import Event +import matplotlib.pyplot as plt + +from tests import skip_unless_with_plots + +test_dir = os.path.dirname(__file__) +pile_driving_dir = f"{test_dir}\\test_data\\impulsive_data" +plt.rcParams.update(plt.rcParamsDefault) + +name = "AMAR 1" +model = "Geospectrum" +serial_number = 247 +sensitivity = -166.6 +preamp_gain = 0 +Vpp = 2 + +AMAR = pyhy.amar.AmarG3( + name, model, serial_number, sensitivity, preamp_gain, Vpp +) + +wav_file = os.path.join(pile_driving_dir, 'pileDriving_excerpt.wav') +acu_file = pypam.AcuFile(wav_file, AMAR, 1.0) + +def load_benchmark_data(): + """load benchmark data, which was calculated in matlab independently, to a dataframe.""" + mat = scipy.io.loadmat(os.path.join(pile_driving_dir, 'pileDriving_results_benchmark')) + + df_val = pd.DataFrame( + { + "startTime": [], + "peak": [], + "rms90": [], + "sel": [], + "tau": [], + "kurtosis": [], + } + ) + for result in mat["BrdBnd_Results"]: + # print(result) + results = { + "startTime": result[0], + "peak": result[1], + f"rms90": result[3] + 10 * np.log10(0.9), # correct slight expected difference (non-ISO definition) + f"sel": result[2], + "tau": result[4], + "kurtosis": 0, + } + df_val.loc[len(df_val)] = results + + return df_val + +def simplePeaks( + acu_file: pypam.AcuFile, + threshold, + eventSeparation_s, + buffer_s, + units="Pa", +): + """very simple detection algorithm""" + eventSeparation_samples = acu_file.fs * eventSeparation_s + sig = acu_file.signal(units=units) + peaks, properties = scipy.signal.find_peaks( + sig, height=threshold, distance=eventSeparation_samples + ) + + # apply buffer + peaks = peaks - int(buffer_s * acu_file.fs) + + return peaks + + +def test_do_analysis(): + """perform analysis on pile driving data, save metrics""" + event_separation_s = 1.0 + buffer_s = 0.2 + locations = simplePeaks(acu_file, 25, event_separation_s, buffer_s) + + events = [] + signal,fs = acu_file.signal(units='upa'), acu_file.fs + for i in range(len(locations) - 1): + events.append(Event(signal, fs, start=locations[i], end=locations[i + 1])) + + results_df = pd.DataFrame( + { + "startTime": [], + "peak": [], + "rms90": [], + "sel": [], + "tau": [], + "kurtosis": [], + } + ) + + for event in events: + + results = event.analyze(impulsive=True) + results_df.loc[len(results_df)] = results + + results_df.to_csv(os.path.join(pile_driving_dir ,'pileDriving_results_pypam.csv')) + assert isinstance(results_df, pd.DataFrame) + + +def test_verify_results(): + """compare results here with benchmark""" + + def calc_diff(df1, df2, key): + max_diff = np.max(np.abs(df1[key].values - df2[key].values[0:39])) + median_diff = np.abs(np.median(df1[key].values)-np.median(df2[key].values[0:39])) + return max_diff, median_diff + + # accept 0.1, 0.5 dB median and maximum differences, respectively + tol_median = 0.1 + tol_max = 0.5 + tol_pulse_width = 0.01 # s + # read data calculated here and from matlab benchmark + df = pd.read_csv(os.path.join(pile_driving_dir ,'pileDriving_results_pypam.csv')) + df_bm = load_benchmark_data() + + peak_diff = calc_diff(df, df_bm, "peak") + rms_diff = calc_diff(df, df_bm, "rms90") + sel_diff = calc_diff(df, df_bm, "sel") + tau_diff = calc_diff(df,df_bm, "tau") + + assert peak_diff[0] None: - self.ds = xarray.open_dataset('tests/test_data/test_day.nc') + self.ds = xarray.open_dataset(f'{test_dir}/test_data/test_day.nc') self.ds = self.ds.where(self.ds.frequency_bins > 10, drop=True) - self.acu_file = AcuFile('tests/test_data/67416073.210610033655.wav', soundtrap, 1) + self.acu_file = AcuFile(f'{test_dir}/test_data/67416073.210610033655.wav', soundtrap, 1) self.asa = ASA(hydrophone=soundtrap, folder_path=folder_path, binsize=binsize, nfft=nfft, timezone='UTC', include_dirs=include_dirs, zipped=zipped_files, dc_subtract=dc_subtract) @@ -79,12 +83,12 @@ def test_summary_plot(self): pypam.plots.plot_summary_dataset(ds=self.ds, percentiles=pctlev, data_var='millidecade_bands', min_val=40, max_val=130, location=[112.186, 36.713], show=True, freq_coord='frequency_bins', - save_path='tests/test_data/data_exploration/img/data_overview/' + save_path=f'{test_dir}/test_data/data_exploration/img/data_overview/' 'summary_plot_test1.png') pypam.plots.plot_summary_dataset(ds=self.ds, percentiles=pctlev, data_var='millidecade_bands', min_val=40, max_val=130, location=None, show=True, freq_coord='frequency_bins', - save_path='tests/test_data/data_exploration/img/data_overview/' + save_path=f'{test_dir}/test_data/data_exploration/img/data_overview/' 'summary_plot_test2.png') @skip_unless_with_plots() diff --git a/tests/test_utils.py b/tests/test_utils.py index ae2799c..8d2fb67 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ import pytest +import os import numpy as np import pandas as pd import xarray @@ -7,6 +8,9 @@ from tests import with_plots from pypam import utils +plt.rcParams.update(plt.rcParamsDefault) +# get relative path +test_dir = os.path.dirname(__file__) # Create artificial data of 1 second @pytest.fixture @@ -16,7 +20,7 @@ def artificial_data(): samples = fs noise_amp = 100 signal_amp = 100 - data = pd.read_csv('tests/test_data/signal_data.csv', header=None)[0].values + data = pd.read_csv(f'{test_dir}/test_data/signal_data.csv', header=None)[0].values t = np.linspace(0, 1 - 1 / fs, samples) phase = 2 * np.pi * t for test_freq in test_freqs: @@ -30,7 +34,7 @@ def artificial_data(): def test_get_millidecade_bands(artificial_data): _, nfft, fs = artificial_data bands_limits, bands_c = utils.get_hybrid_millidecade_limits(band=[0, fs/2], nfft=nfft) - mdec_bands_test = pd.read_csv('tests/test_data/mdec_bands_test.csv', header=None) + mdec_bands_test = pd.read_csv(f'{test_dir}//test_data/mdec_bands_test.csv', header=None) assert ((mdec_bands_test.iloc[:, 0] - bands_limits[:-1]) > 5e-5).sum() == 0 assert ((mdec_bands_test.iloc[:, 2] - bands_limits[1:]) > 5e-5).sum() == 0 assert ((mdec_bands_test.iloc[:, 1] - bands_c) > 5e-5).sum() == 0 @@ -51,7 +55,7 @@ def test_psd_to_millidecades(artificial_data): fbands = scipy.fft.rfftfreq(nfft, 1/fs) # Load the spectrum used for MANTA - spectra_manta = pd.read_csv('tests/test_data/spectra.csv', header=None) + spectra_manta = pd.read_csv(f'{test_dir}//test_data/spectra.csv', header=None) # Check if they are the same assert (abs(spectra_manta[0].values - spectra) > 1e-5).sum() == 0 @@ -64,7 +68,7 @@ def test_psd_to_millidecades(artificial_data): bandwidths = milli_psd.upper_frequency - milli_psd.lower_frequency milli_psd_power = milli_psd * bandwidths # Read MANTA's output - mdec_power_test = pd.read_csv('tests/test_data/mdec_power_test.csv') + mdec_power_test = pd.read_csv(f'{test_dir}//test_data/mdec_power_test.csv') if with_plots(): # Plot the two outputs for comparison @@ -85,7 +89,7 @@ def test_psd_to_millidecades(artificial_data): def test_hmb_to_decidecade(): - daily_ds = xarray.load_dataset('tests/test_data/test_day.nc') + daily_ds = xarray.load_dataset(f'{test_dir}//test_data/test_day.nc') daily_ds_deci = utils.hmb_to_decidecade(daily_ds, 'millidecade_bands', freq_coord='frequency_bins') if with_plots(): @@ -100,3 +104,54 @@ def test_hmb_to_decidecade(): plt.xlim(left=10) plt.legend() plt.show() + +def test_kurtosis(): + # build test data and calculate kurtosis + n = 1000 + normally_distributed_data = scipy.stats.norm.rvs(size=n) + + result_utils = utils.kurtosis(normally_distributed_data) + result_scipy = scipy.stats.kurtosis(normally_distributed_data, fisher=False) + + # account for slight difference in the method here + expected_ratio = ((n - 1) / n)**2 + result_scipy = result_scipy * expected_ratio + + assert np.isclose(result_scipy, result_utils) + # kurtosis should be near 3 for random gaussian distribution + assert np.round(result_utils) == 3 + +def test_energy_window(): + """Check energy window method against examples in Madsen 2005. + """ + Madsen_tau_1 = {'90':81,'97':125} #fig 1 + Madsen_tau_2 = {'90': 9, '97': 10} # fig 3a + tol = 7 # us + plot=True + def load_and_window_data(filename, plot=False): + raw_data = np.loadtxt(f'{test_dir}\\test_data\\impulsive_data\\{filename}',delimiter=',') + t, P = raw_data[:,0], raw_data[:,1] + t = t+np.abs(np.min(t)) + t_interp = np.linspace(0,np.max(t),num=500) + P_interp = np.interp(t_interp,t,P) + start,end = utils.energy_window(P_interp,.97) + tau_97 = t_interp[end]-t_interp[start] + start,end = utils.energy_window(P_interp,.90) + tau_90 = t_interp[end]-t_interp[start] + if plot: + fig, ax = plt.subplots() + ax.plot(t_interp, P_interp) + ax.plot(t_interp[start:end], P_interp[start:end], color='r', linestyle='--') + fig.suptitle(f'energy window test, Madsen 2005, tau_90={tau_90:.2f} us') + plt.show() + return tau_90, tau_97 + + tau_90_1,tau_97_1 = load_and_window_data('madsen_digitized_signal.csv') + tau_90_2, tau_97_2 = load_and_window_data('madsen_digitized_signal_2.csv') + err90_1 = np.abs(Madsen_tau_1['90']-tau_90_1)/Madsen_tau_1['90'] + err97_1 = np.abs(Madsen_tau_1['97'] - tau_97_1) / Madsen_tau_1['97'] + err90_2 = np.abs(Madsen_tau_2['90']-tau_90_2)/Madsen_tau_2['90'] + err97_2 = np.abs(Madsen_tau_2['97'] - tau_97_2) / Madsen_tau_2['97'] + mean_error = np.mean([err90_1,err97_2,err90_2,err97_1]) + assert mean_error < 0.05 # accept 5% digitization error +