Skip to content

Commit

Permalink
Merge d3b4ef1 into 2c1ca56
Browse files Browse the repository at this point in the history
  • Loading branch information
janscience committed Nov 11, 2018
2 parents 2c1ca56 + d3b4ef1 commit e9d4a46
Show file tree
Hide file tree
Showing 10 changed files with 1,036 additions and 353 deletions.
24 changes: 23 additions & 1 deletion tests/test_bestwindow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from nose.tools import assert_true, assert_equal, assert_almost_equal
import os
import numpy as np
import matplotlib.pyplot as plt
import thunderfish.bestwindow as bw


Expand All @@ -22,7 +24,7 @@ def test_best_window():
# compute best window:
print("call bestwindow() function...")
idx0, idx1, clipped = bw.best_window_indices(data, rate, single=False,
win_size=1.0, win_shift=0.1, thresh_ampl_fac=2.0,
win_size=1.0, win_shift=0.1,
min_clip=-clip, max_clip=clip,
w_cv_ampl=10.0, tolerance=0.5)

Expand All @@ -40,3 +42,23 @@ def test_best_window():
'clip_amplitudes() failed to detect minimum clip amplitude')
assert_true(max_clip >= 0.8 * clip and max_clip <= clip,
'clip_amplitudes() failed to detect maximum clip amplitude')

# plotting 1:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
bw.plot_best_data(data, rate, 'a.u.', idx0, idx1, clipped, ax)
fig.savefig('bestwindow.png')
assert_true(os.path.exists('bestwindow.png'), 'plotting failed')
os.remove('bestwindow.png')

# plotting 2:
fig, ax = plt.subplots(5, sharex=True)
bw.best_window_indices(data, rate, single=False,
win_size=1.0, win_shift=0.1,
min_clip=-clip, max_clip=clip,
w_cv_ampl=10.0, tolerance=0.5,
plot_data_func=bw.plot_best_window, ax=ax)
fig.savefig('bestdata.png')
assert_true(os.path.exists('bestdata.png'), 'plotting failed')
os.remove('bestdata.png')

31 changes: 31 additions & 0 deletions tests/test_eodanalysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from nose.tools import assert_true, assert_equal, assert_almost_equal
import os
import numpy as np
import matplotlib.pyplot as plt
import thunderfish.fakefish as ff
import thunderfish.eodanalysis as ea


def test_pulsefish():
samplerate = 44100.0
data = ff.generate_biphasic_pulses(200.0, samplerate, 5.0, noise_std=0.02)
mean_eod, eod_times = ea.eod_waveform(data, samplerate)
mean_eod, props, peaks, power, intervals = ea.analyze_pulse(mean_eod, eod_times)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ea.pulse_spectrum_plot(power, props, ax)
fig.savefig('pulse.png')
assert_true(os.path.exists('pulse.png'), 'plotting failed')
os.remove('pulse.png')

def test_wavefish():
samplerate = 44100.0
data = ff.generate_alepto(800.0, samplerate, duration=10.0, noise_std=0.01)
mean_eod, eod_times = ea.eod_waveform(data, samplerate)
mean_eod, props, power = ea.analyze_wave(mean_eod, 800.0)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ea.eod_waveform_plot(mean_eod, [], ax)
fig.savefig('wave.png')
assert_true(os.path.exists('wave.png'), 'plotting failed')
os.remove('wave.png')
395 changes: 262 additions & 133 deletions thunderfish/bestwindow.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions thunderfish/checkpulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
pass


def check_pulse_width(data, samplerate, th_factor=2.0, percentile=25.0,
def check_pulse_width(data, samplerate, th_factor=0.8, percentile=1.0,
pulse_thresh=0.1, verbose=0, plot_data_func=None, **kwargs):
"""Detects if a fish is pulse- or wave-type based on the proportion of the time distance
between a peak and its following trough, relative to the time between consecutive peaks.
Expand Down Expand Up @@ -272,7 +272,7 @@ def plot_peak_trough_hist(vals, ax, hist_color, plot_label, label_size):
# Cosmetics
ax[0].set_title('Raw-data with peak detection', fontsize=fs + 2)
ax[0].set_xlabel('Time [sec]', fontsize=fs)
ax[0].set_ylabel('Amplitude [a.u.]', fontsize=fs)
ax[0].set_ylabel('Amplitude', fontsize=fs)
ax[0].tick_params(axis='both', which='major', labelsize=fs - 2)

# Second Plot: Window inset
Expand All @@ -282,7 +282,7 @@ def plot_peak_trough_hist(vals, ax, hist_color, plot_label, label_size):
f_type = 'pulse' if pulse_fish else 'wave'
ax[1].set_title('Inset of plot above. Suggested fish-type is %s' % f_type, fontsize=fs + 2)
ax[1].set_xlabel('Time [sec]', fontsize=fs)
ax[1].set_ylabel('Amplitude [a.u.]', fontsize=fs)
ax[1].set_ylabel('Amplitude', fontsize=fs)
ax[1].tick_params(axis='both', which='major', labelsize=fs - 2)
ax[1].legend(frameon=False, loc='best')

Expand Down Expand Up @@ -339,7 +339,7 @@ def plot_psd_proportion(freqs, power, proportions, percentiles, pulse_fish,
ax.set_ylabel('Power [dB]', fontsize=fs)


def add_check_pulse_width_config(cfg, th_factor=2.0, percentile=25.0, pulse_thresh=0.1):
def add_check_pulse_width_config(cfg, th_factor=0.8, percentile=1.0, pulse_thresh=0.1):
""" Add parameter needed for check_pulse_width() as
a new section to a configuration.
Expand Down
Loading

0 comments on commit e9d4a46

Please sign in to comment.