175 lines
7.8 KiB
Python
175 lines
7.8 KiB
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
import matplotlib.dates as mdates
|
|
import matplotlib.colors as mcolors
|
|
import matplotlib.gridspec as gridspec
|
|
from IPython import embed
|
|
from scipy import stats
|
|
import math
|
|
import os
|
|
from IPython import embed
|
|
import helper_functions as hf
|
|
from params import *
|
|
|
|
if __name__ == '__main__':
|
|
|
|
###################################################################################################################
|
|
# parameter and variables
|
|
###################################################################################################################
|
|
# plot params
|
|
inch = 2.45
|
|
save_path = '../../thesis/Figures/Results/'
|
|
|
|
all_begins = []
|
|
all_ends = []
|
|
begins = []
|
|
ends = []
|
|
durations = []
|
|
all_durations = []
|
|
start = []
|
|
stop = []
|
|
|
|
# plot
|
|
fig2, ax2 = plt.subplots(1, 1, figsize=(16 / inch, 6 / inch))
|
|
fig2.subplots_adjust(left=0.12, bottom=0.2, right=0.95, top=0.97)
|
|
|
|
c = 0
|
|
###################################################################################################################
|
|
# load data
|
|
###################################################################################################################
|
|
# load all the data of one day
|
|
for index, filename_idx in enumerate([0, 1, 2, 3]):
|
|
filename = sorted(os.listdir('../data/'))[filename_idx]
|
|
all_xticks = np.load('../data/' + filename + '/all_xtickses.npy', allow_pickle=True)
|
|
all_Ctime_v = np.load('../data/' + filename + '/all_Ctime_v.npy', allow_pickle=True)
|
|
power_means = np.load('../data/' + filename + '/power_means.npy', allow_pickle=True)
|
|
names = np.load('../data/' + filename + '/fish_species.npy', allow_pickle=True)
|
|
|
|
# variables
|
|
sampling_rate = 1 / np.diff(all_Ctime_v[0])[0] # in sec
|
|
first = np.min(np.unique(np.hstack(all_xticks)))
|
|
last = np.max(np.unique(np.hstack(all_xticks)))
|
|
start15 = mdates.date2num(mdates.num2date(first) + datetime.timedelta(seconds=15 * 60))
|
|
stop15 = mdates.date2num(mdates.num2date(last) - datetime.timedelta(seconds=15 * 60))
|
|
trial_dur = (np.max(np.unique(np.hstack(all_Ctime_v))) - np.min(np.unique(np.hstack(all_Ctime_v)))) / 60
|
|
|
|
start.extend([first])
|
|
stop.extend([last])
|
|
|
|
# plot
|
|
ax2.plot(trial_dur, 90, 'o', ms=ms, color=color_diffdays[index])
|
|
print(trial_dur)
|
|
|
|
###############################################################################################################
|
|
# analysis
|
|
###############################################################################################################
|
|
for fish in range(len(all_xticks)):
|
|
if power_means[fish] >= -90 and names[fish] != 'unknown':
|
|
c += 1
|
|
if np.any(all_xticks[fish] <= start15) or np.any(all_xticks[fish] >= stop15):
|
|
all_durations.append((all_Ctime_v[fish][-1] - all_Ctime_v[fish][0]) / 60)
|
|
|
|
else:
|
|
durations.append((all_Ctime_v[fish][-1] - all_Ctime_v[fish][0]) / 60)
|
|
all_durations.append((all_Ctime_v[fish][-1] - all_Ctime_v[fish][0]) / 60)
|
|
|
|
|
|
###################################################################################################################
|
|
# plotting figure 2
|
|
dur = np.array(durations)
|
|
all_dur = np.array(all_durations)
|
|
|
|
n3, bin_edges3 = np.histogram(dur, bins=np.linspace(0, 950, 20))
|
|
n4, bin_edges4 = np.histogram(all_dur, bins=np.linspace(0, 950, 20))
|
|
# n3 = n3 / np.sum(n3) / (bin_edges3[1] - bin_edges3[0])
|
|
|
|
ax2.bar(bin_edges4[:-1] + (bin_edges4[1] - bin_edges4[0]) / 2, n4,
|
|
width=0.9 * (bin_edges4[1] - bin_edges4[0]), label='all', color=color2[5])
|
|
ax2.bar(bin_edges3[:-1] + (bin_edges3[1] - bin_edges3[0]) / 2, n3,
|
|
width=0.9 * (bin_edges3[1] - bin_edges3[0]), label='corrected', color=color2[4])
|
|
|
|
ax2.set_xlabel('Presence duration [min]', fontsize=fs)
|
|
ax2.set_ylabel('n', fontsize=fs)
|
|
ax2.make_nice_ax()
|
|
# ax2.set_ylim([0, 10**2])
|
|
ax2.set_yscale('symlog')
|
|
fig2.legend(loc='center right')
|
|
# fig2.savefig(save_path+'appearance_dur.png')
|
|
fig2.savefig(save_path+'duration.pdf')
|
|
plt.show()
|
|
|
|
embed()
|
|
quit()
|
|
|
|
# ###################################################################################################################
|
|
# # plotting figure 1
|
|
# fig1, ax1 = plt.subplots(1, 1, figsize=(16 / inch, 8 / inch))
|
|
# fig1.subplots_adjust(left=0.12, bottom=0.3, right=0.95, top=0.97)
|
|
|
|
# n1, bin_edges1 = np.histogram(begins, bins=35)
|
|
# n2, bin_edges2 = np.histogram(ends, bins=bin_edges1)
|
|
# n11, bin_edges2 = np.histogram(all_begins, bins=bin_edges1)
|
|
# n21, bin_edges2 = np.histogram(all_ends, bins=bin_edges1)
|
|
# n1 = n1 / np.sum(n1) / (bin_edges1[1] - bin_edges1[0])
|
|
# n2 = n2 / np.sum(n2) / (bin_edges1[1] - bin_edges1[0])
|
|
# # n11 = n11 / np.sum(n11) / (bin_edges1[1] - bin_edges1[0])
|
|
# # n21 = n21 / np.sum(n21) / (bin_edges1[1] - bin_edges1[0])
|
|
#
|
|
# ax1.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n11,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[2])
|
|
# ax1.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n1,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[0], label='appearance')
|
|
#
|
|
# ax1.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n21 * -1,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[3])
|
|
# ax1.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n2 * -1,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[1], label='disappearance')
|
|
# ax1.axhline(y=0.0, xmin=0.0, xmax=1.0, color='k', linewidth=lw)
|
|
#
|
|
# ax1.set_xlabel('Time', fontsize=fs)
|
|
# ax1.set_ylabel('n', fontsize=fs)
|
|
# ax1.timeaxis()
|
|
# ax1.set_yscale('symlog')
|
|
# fig1.autofmt_xdate()
|
|
# ax1.make_nice_ax()
|
|
# fig1.legend(loc='upper right')
|
|
|
|
# fig1.savefig(save_path+'appearance_disappearance.png')
|
|
# fig1.savefig(save_path+'appearance_disappearance.pdf')
|
|
###################################################################################################################
|
|
# plotting figure 3
|
|
# fig3 = plt.figure(figsize=[16 / inch, 12 / inch])
|
|
# spec = gridspec.GridSpec(ncols=1, nrows=2, figure=fig3, hspace=0.3, wspace=0.15,
|
|
# height_ratios=[1, 1], left=0.1, bottom=0.15, right=0.99, top=0.98)
|
|
# ax3 = fig3.add_subplot(spec[0, 0])
|
|
# ax4 = fig3.add_subplot(spec[1, 0])
|
|
# ax3.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n1,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[0], label='appearance')
|
|
# ax3.bar(bin_edges1[:-1] + (bin_edges1[1] - bin_edges1[0]) / 2, n2 * -1,
|
|
# width=0.9 * (bin_edges1[1] - bin_edges1[0]), color=color2[1], label='disappearance')
|
|
# ax3.axhline(y=0.0, xmin=0.0, xmax=1.0, color='k', linewidth=lw)
|
|
#
|
|
# ax3.set_xlabel('Time', fontsize=fs)
|
|
# ax3.set_ylabel('n', fontsize=fs)
|
|
# ax3.timeaxis()
|
|
# fig3.autofmt_xdate()
|
|
# ax3.make_nice_ax()
|
|
# # fig3.legend(loc='upper right')
|
|
#
|
|
# ax4.bar(bin_edges4[:-1] + (bin_edges4[1] - bin_edges4[0]) / 2, n4,
|
|
# width=0.9 * (bin_edges4[1] - bin_edges4[0]), label='all', color=color2[2])
|
|
# ax4.bar(bin_edges3[:-1] + (bin_edges3[1] - bin_edges3[0]) / 2, n3,
|
|
# width=0.9 * (bin_edges3[1] - bin_edges3[0]), label='corrected', color=color2[0])
|
|
#
|
|
# ax4.set_xlabel('Presence duration [min]', fontsize=fs)
|
|
# ax4.set_ylabel('n', fontsize=fs)
|
|
# ax4.make_nice_ax()
|
|
# fig3.legend(loc='upper right')
|
|
#
|
|
# fig3.savefig(save_path+'appearance_all.pdf')
|
|
# exit()
|
|
# if filename not in os.listdir('../data/'):
|
|
# os.mkdir('../data/'+filename)
|
|
#
|
|
# np.save('../data/' + filename + '/direction.npy', directs)
|