fish_names = helpers.get_all_fish(helpers.RECORDING_PATH16) # CHANGE TO RECORDING_PATH8 for 8 bits files
indexes = []
fish = fish_names[1]

levels = 3
mat_files = np.array(helpers.get_mat_files(fish, helpers.RECORDING_PATH16))
fft_files = helpers.get_npy_files(fish, helpers.SAVE_PATH, 'fft')
counter = 0
shift = 0
set = 1

for ind in range(len(fft_files)):
    if counter <= levels:
        counter += 1
        file_name = helpers.path_to_name(fft_files[0])
        xf, power = helpers.load_npy(fft_files[0])
        plt.plot(xf, shift + power / np.max(power))
        shift = shift + 1.2
        fft_files.pop(0)

    if counter == levels:
        shift = 0
        counter = 0
        plt.title('FFT ' + fish + str(set))
        plt.grid()
        plt.xlim(0, 6000)
        plt.ylabel('Amplitude')
        plt.xlabel('Frequency ')
        helpers.save_figure(join(helpers.SAVE_PATH, fish), 'FFT for set ' + str(set), fish, file_name, 'FFT_graphs')
        plt.close()
Example #2
0
        threshold = 0
        f_estimate = 800

        frequencies = calculate_frequency(EOD,
                                          sampling_frequency,
                                          estimated_frequency=f_estimate,
                                          crossing_threshold=threshold,
                                          temporal_threshold=0.05,
                                          method='median',
                                          ascending=False)
        cv = '{:.2e}'.format(np.std(frequencies) / np.mean(frequencies))
        print(cv)
        print(np.mean(frequencies))

        file_name = helpers.path_to_name(file)

        frequency_info = [frequencies, cv, threshold]
        helpers.save_results(frequency_info, fish, file_name, 'frequency')

npy_files = helpers.get_npy_files(fish, helpers.SAVE_PATH, 'frequency')

frequencies = []

for i in range(len(npy_files)):
    [frequency, cv, threshold] = helpers.load_npy(npy_files[i])
    frequency = frequency.tolist()
    frequencies.extend(frequency)

size = np.size(frequencies) / len(npy_files)
Example #3
0
frequencies = []


npy_files = helpers.get_npy_files(fish, helpers.SAVE_PATH, 'frequency')
fft_files = helpers.get_npy_files(fish, helpers.SAVE_PATH, 'fft')
mat_files = helpers.get_mat_files(fish, helpers.RECORDING_PATH16)
[lowrez_index, highrez_index] = helpers.sort_files(mat_files)
file_number = highrez_index

for numb in file_number:
    index = file_number.index(numb)
    raw_data = helpers.load_mat(mat_files[numb])
    data = np.array(raw_data)
    data = data[np.isfinite(data)]
    EOD = data - np.mean(data)
    file_name = helpers.path_to_name(mat_files[numb])
    [frequency, cv, threshold] = helpers.load_npy(npy_files[numb])

    time_array = helpers.create_time(len(raw_data)-1, style='MAT')
    cycle_time = np.cumsum(1. / frequency)

    [xf, power] = helpers.load_npy(fft_files[index])
    fft_main = 2*power.argmax()

    fig = plt.figure('Explore V1 ' + file_name )
    ax1 = fig.add_subplot(221)
    ax1.plot(time_array[::50] , EOD[1::50])
    ax1.set_title('Full data')

    ax2 = fig.add_subplot(222)
    ax2.plot(time_array[0:675000] , EOD[0:675000]) # shows 5 cycles
marker_ind = []
lowrez_index = []
highrez_index = []


mat_files = helpers.get_mat_files(fish, helpers.RECORDING_PATH16)
[lowrez_index ,highrez_index ] = helpers.sort_files(mat_files)

if lowrez is True:
    file_number = lowrez_index
else:
file_number = highrez_index

for index in file_number:
    npy_files = helpers.get_npy_files(fish, helpers.SAVE_PATH, 'frequency')
    file_name = helpers.path_to_name(npy_files[index])
    [frequency, cv, threshold] = helpers.load_npy(npy_files[index])
    cycle_time = np.cumsum(1. / frequency)
    plt.figure('Frequency with time')
    plt.plot(cycle_time, frequency, '.')
    plt.ylabel('Frequency [Hz]')
    plt.xlabel('Time [s]')
    plt.title('Frequency variation in time for ' + file_name + ' CV = ' + str(cv))
    helpers.save_figure(join(helpers.SAVE_PATH, fish), 'Frequency in time for ', fish, file_name, 'Frequency_graphs')
    plt.close()

    if lowrez is False:
        plt.figure('Histogram of frequency')
        plt.hist(frequency, bins = 35)
        plt.xlabel('Frequency [Hz]')
        plt.ylabel('Occurrence')