Example #1
0
from Auxiliary import *

if __name__ == '__main__':

    if not 3 >= len(sys.argv) >= 2:  # only if len(sys.argv) == 2 or 3, the codes continues running.
        print("\nI need an audiofile as first argument. Please give me the path + filename as argument! "
              "Then you can tell me the folder name you wish me to save the figures in, as a second argument "
              "(don't use any '/'). Only of you like though.\n")
        sys.exit(2)
    # Load, convert and process the audiofile
    audio_file = sys.argv[1]
    modfile = conv_to_single_ch_audio(audio_file)
    fish = FishRecording(modfile)

    # detect best window
    w_start, w_width = fish.detect_best_window()

    # define save path and create the plots with the best window
    if len(sys.argv) == 3:
        folder_name = sys.argv[2]
        savepath = './control_figures/best_window_detection/' + folder_name + '/'
    else:
        savepath = './control_figures/best_window_detection/'

    if not os.path.exists(savepath):
        os.mkdir(savepath)

    recording_name = '_'.join(modfile.split('.')[0].split('_')[:2]) + '.pdf'

    fig, ax = plt.subplots(figsize=(12, 8))
    fish.plot_wavenvelope(ax, w_start, w_start+w_width)
Example #2
0
        else:
            print '%%% File No. ' + fish_file_number\
                  + ' was not analyzed, because the length of the recording was less than 10 seconds. %%%'
            exit()

        print '\n'
        print 'Analyzing Fish No. ' + fish_file_number + ' ...'
        current_fish = "fish" + fish_file_number
        fund_freq = fish.fund_freq
        s.append(odml.Section(current_fish, "subject"))
        s[current_fish].append(odml.Property("Audio_file", new_mod_filename))
        s[current_fish].append(odml.Property("EOD_frequency", odml.Value(fund_freq, unit="Hz")))
        print 'Fundamental Frequency of Fish No.' + fish_file_number + ' is %.1f Hz...' % fund_freq
        print '\n'

        w_start, w_width = fish.detect_best_window(plot_debug=True)

        pt, _, _, _ = fish.w_pt  # pt stands for peak-troughs...
        if len(pt) <= 5:
            print '%%%%% Warning! No or few peaks detected! Aborting Analysis! %%%%%'
            exit()

        b_win_inxs = [i for i, elem in enumerate(fish._time == w_start, 1) if elem]
        inx = b_win_inxs[0]  # Get inx where the analyze window starts.
        max_inx = inx + int(fish._sample_rate / 2.)  # Get inx where the analyze window ends.
        window_edges = (fish._time[inx], fish._time[max_inx])
        bwin_time = fish._time[inx:max_inx]
        bwin_eod = fish._eod[inx:max_inx]

        fish_type = fish.type_detector()
        print 'Fish No. ' + fish_file_number + ' is ' + fish_type + ' type!'