This commit is contained in:
weygoldt 2023-01-26 12:45:18 +01:00
commit e0d319d825
11 changed files with 169 additions and 122 deletions

2
.gitignore vendored
View File

@ -14,7 +14,7 @@ output
__pycache__/
*.py[cod]
*$py.class
poster/main.pdf
/poster/main.pdf
# C extensions
*.so

View File

@ -1,24 +1,37 @@
from modules.filters import create_chirp, bandpass_filter
import matplotlib.pyplot as plt
from chirpdetection import instantaneos_frequency
import numpy as np
from IPython import embed
# create chirp
import matplotlib.pyplot as plt
from thunderfish import fakefish
time, signal, ampl, freq = create_chirp(chirptimes=[0.05, 0.2501, 0.38734, 0.48332, 0.73434, 0.823424], )
from modules.filters import bandpass_filter
from modules.datahandling import instantaneous_frequency
from modules.simulations import create_chirp
# filter signal with bandpass_filter
signal = bandpass_filter(signal, 1/0.00001, 495, 505)
# trying thunderfish fakefish chirp simulation ---------------------------------
samplerate = 44100
freq, ampl = fakefish.chirps(eodf=500, chirp_contrast=0.2)
data = fakefish.wavefish_eods(fish='Alepto', frequency=freq, phase0=3, samplerate=samplerate)
# filter signal with bandpass_filter
data_filterd = bandpass_filter(data*ampl+1, samplerate, 0.01, 1.99)
embed()
exit()
fig, axs = plt.subplots(2, 1, figsize=(10, 10))
axs[0].plot(time, signal)
data_freq_time, data_freq = instantaneous_frequency(data, samplerate, 5)
# plot instatneous frequency
baseline_freq_time, baseline_freq = instantaneos_frequency(signal, 1/0.00001)
axs[1].plot(baseline_freq_time[1:], baseline_freq[1:])
fig, ax = plt.subplots(4, 1, figsize=(20 / 2.54, 12 / 2.54), sharex=True)
ax[0].plot(np.arange(len(data))/samplerate, data*ampl)
#ax[0].scatter(true_zero, np.zeros_like(true_zero), color='red')
ax[1].plot(np.arange(len(data_filterd))/samplerate, data_filterd)
ax[2].plot(np.arange(len(freq))/samplerate, freq)
ax[3].plot(data_freq_time, data_freq)
plt.show()
embed()

View File

@ -110,7 +110,7 @@ def PlotStyle() -> None:
plt.setp(bp["boxes"], color=color)
plt.setp(bp["whiskers"], color=white)
plt.setp(bp["caps"], color=white)
plt.setp(bp["medians"], color=white)
plt.setp(bp["medians"], color=black)
@classmethod
@ -255,10 +255,10 @@ def PlotStyle() -> None:
plt.rcParams["boxplot.boxprops.color"] = gray
plt.rcParams["boxplot.whiskerprops.color"] = gray
plt.rcParams["boxplot.capprops.color"] = gray
plt.rcParams["boxplot.medianprops.color"] = gray
plt.rcParams["boxplot.medianprops.color"] = black
plt.rcParams["text.color"] = white
plt.rcParams["axes.facecolor"] = black # axes background color
plt.rcParams["axes.edgecolor"] = gray # axes edge color
plt.rcParams["axes.edgecolor"] = white # axes edge color
# plt.rcParams["axes.grid"] = True # display grid or not
# plt.rcParams["axes.grid.axis"] = "y" # which axis the grid is applied to
plt.rcParams["axes.labelcolor"] = white
@ -284,9 +284,9 @@ def PlotStyle() -> None:
"#f5c2e7",
],
)
plt.rcParams["xtick.color"] = gray # color of the ticks
plt.rcParams["ytick.color"] = gray # color of the ticks
plt.rcParams["grid.color"] = dark_gray # grid color
plt.rcParams["xtick.color"] = white # color of the ticks
plt.rcParams["ytick.color"] = white # color of the ticks
plt.rcParams["grid.color"] = white # grid color
plt.rcParams["figure.facecolor"] = black # figure face color
plt.rcParams["figure.edgecolor"] = black # figure edge color
plt.rcParams["savefig.facecolor"] = black # figure face color when saving

View File

@ -133,41 +133,45 @@ def get_chirp_freq(folder_name, Behavior, order_meta_df):
Behavior.freq[Behavior.ident == fish2_freq])
if winner == fish1:
if chirp_freq_fish1 > chirp_freq_fish2:
freq_diff_higher = chirp_freq_fish1 - chirp_freq_fish2
freq_diff_lower = chirp_freq_fish2 - chirp_freq_fish1
elif chirp_freq_fish1 < chirp_freq_fish2:
freq_diff_higher = chirp_freq_fish1 - chirp_freq_fish2
freq_diff_lower = chirp_freq_fish2 - chirp_freq_fish1
else:
freq_diff_higher = np.nan
freq_diff_lower = np.nan
winner_fish_id = np.nan
loser_fish_id = np.nan
# if chirp_freq_fish1 > chirp_freq_fish2:
# freq_diff_higher = chirp_freq_fish1 - chirp_freq_fish2
# freq_diff_lower = chirp_freq_fish2 - chirp_freq_fish1
# elif chirp_freq_fish1 < chirp_freq_fish2:
# freq_diff_higher = chirp_freq_fish1 - chirp_freq_fish2
# freq_diff_lower = chirp_freq_fish2 - chirp_freq_fish1
# else:
# freq_diff_higher = np.nan
# freq_diff_lower = np.nan
# winner_fish_id = np.nan
# loser_fish_id = np.nan
winner_fish_id = folder_row['rec_id1'].values[0]
winner_fish_freq = chirp_freq_fish1
loser_fish_id = folder_row['rec_id2'].values[0]
loser_fish_freq = chirp_freq_fish2
elif winner == fish2:
if chirp_freq_fish2 > chirp_freq_fish1:
freq_diff_higher = chirp_freq_fish2 - chirp_freq_fish1
freq_diff_lower = chirp_freq_fish1 - chirp_freq_fish2
elif chirp_freq_fish2 < chirp_freq_fish1:
freq_diff_higher = chirp_freq_fish2 - chirp_freq_fish1
freq_diff_lower = chirp_freq_fish1 - chirp_freq_fish2
else:
freq_diff_higher = np.nan
freq_diff_lower = np.nan
winner_fish_id = np.nan
loser_fish_id = np.nan
# if chirp_freq_fish2 > chirp_freq_fish1:
# freq_diff_higher = chirp_freq_fish2 - chirp_freq_fish1
# freq_diff_lower = chirp_freq_fish1 - chirp_freq_fish2
# elif chirp_freq_fish2 < chirp_freq_fish1:
# freq_diff_higher = chirp_freq_fish2 - chirp_freq_fish1
# freq_diff_lower = chirp_freq_fish1 - chirp_freq_fish2
# else:
# freq_diff_higher = np.nan
# freq_diff_lower = np.nan
# winner_fish_id = np.nan
# loser_fish_id = np.nan
winner_fish_id = folder_row['rec_id2'].values[0]
winner_fish_freq = chirp_freq_fish2
loser_fish_id = folder_row['rec_id1'].values[0]
loser_fish_freq = chirp_freq_fish1
else:
freq_diff_higher = np.nan
freq_diff_lower = np.nan
winner_fish_freq = np.nan
loser_fish_freq = np.nan
winner_fish_id = np.nan
loser_fish_id = np.nan
@ -176,7 +180,7 @@ def get_chirp_freq(folder_name, Behavior, order_meta_df):
chirp_loser = len(
Behavior.chirps[Behavior.chirps_ids == loser_fish_id])
return freq_diff_higher, chirp_winner, freq_diff_lower, chirp_loser
return winner_fish_freq, chirp_winner, loser_fish_freq, chirp_loser
def main(datapath: str):
@ -229,11 +233,11 @@ def main(datapath: str):
size_diff_bigger, chirp_winner, size_diff_smaller, chirp_loser = get_chirp_size(
foldername, bh, order_meta_df, id_meta_df)
freq_diff_higher, chirp_freq_winner, freq_diff_lower, chirp_freq_loser = get_chirp_freq(
freq_winner, chirp_freq_winner, freq_loser, chirp_freq_loser = get_chirp_freq(
foldername, bh, order_meta_df)
freq_diffs_higher.append(freq_diff_higher)
freq_diffs_lower.append(freq_diff_lower)
freq_diffs_higher.append(freq_winner)
freq_diffs_lower.append(freq_loser)
freq_chirps_winner.append(chirp_freq_winner)
freq_chirps_loser.append(chirp_freq_loser)
@ -247,9 +251,10 @@ def main(datapath: str):
size_winner_pearsonr = pearsonr(size_diffs_winner, size_chirps_winner)
size_loser_pearsonr = pearsonr(size_diffs_loser, size_chirps_loser)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(
13*ps.cm, 10*ps.cm), sharey=True)
plt.subplots_adjust(left=0.098, right=0.945, top=0.94, wspace=0.343)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(
21*ps.cm, 7*ps.cm), width_ratios=[1, 0.8, 0.8], sharey=True)
plt.subplots_adjust(left=0.11, right=0.948, top=0.86,
wspace=0.343, bottom=0.198)
scatterwinner = 1.15
scatterloser = 1.85
chirps_winner = np.asarray(chirps_winner)[~np.isnan(chirps_winner)]
@ -257,43 +262,54 @@ def main(datapath: str):
stat = wilcoxon(chirps_winner, chirps_loser)
print(stat)
winner_color = ps.gblue3
loser_color = ps.gblue1
bplot1 = ax1.boxplot(chirps_winner, positions=[
0.9], showfliers=False, patch_artist=True)
bplot2 = ax1.boxplot(chirps_loser, positions=[
2.1], showfliers=False, patch_artist=True)
ax1.scatter(np.ones(len(chirps_winner)) *
scatterwinner, chirps_winner, color=ps.red)
scatterwinner, chirps_winner, color=winner_color)
ax1.scatter(np.ones(len(chirps_loser)) *
scatterloser, chirps_loser, color=ps.orange)
ax1.set_xticklabels(['winner', 'loser'])
ax1.text(0.1, 0.9, f'n = {len(chirps_winner)}',
scatterloser, chirps_loser, color=loser_color)
ax1.set_xticklabels(['Winner', 'Loser'])
ax1.text(0.1, 0.95, f'n={len(chirps_winner)}',
transform=ax1.transAxes, color=ps.white)
for w, l in zip(chirps_winner, chirps_loser):
ax1.plot([scatterwinner, scatterloser], [w, l],
color=ps.white, alpha=1, linewidth=0.5)
ax1.set_ylabel('chirps [n]', color=ps.white)
ax1.set_xlabel('outcome', color=ps.white)
color=ps.white, alpha=0.6, linewidth=1, zorder=-1)
ax1.set_ylabel('Chirp counts', color=ps.white)
ax1.set_xlabel('Competition outcome', color=ps.white)
colors1 = ps.red
ps.set_boxplot_color(bplot1, colors1)
colors1 = ps.orange
ps.set_boxplot_color(bplot2, colors1)
ps.set_boxplot_color(bplot1, winner_color)
ps.set_boxplot_color(bplot2, loser_color)
ax2.scatter(size_diffs_winner, size_chirps_winner,
color=ps.red, label='winner')
color=winner_color, label=f'Winner')
ax2.scatter(size_diffs_loser, size_chirps_loser,
color=ps.orange, label='loser')
color=loser_color, label='Loser')
ax2.text(0.05, 0.95, f'n={len(size_chirps_winner)}',
transform=ax2.transAxes, color=ps.white)
ax2.set_xlabel('size difference [cm]')
ax2.set_xlabel('Size difference [cm]')
# ax2.set_xticks(np.arange(-10, 10.1, 2))
handles, labels = ax2.get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center', ncol=2)
plt.subplots_adjust(left=0.162, right=0.97, top=0.85, bottom=0.176)
ax3.scatter(freq_diffs_higher, freq_chirps_winner, color=winner_color)
ax3.scatter(freq_diffs_lower, freq_chirps_loser, color=loser_color)
ax3.text(0.1, 0.95, f'n={len(freq_chirps_loser)}',
transform=ax3.transAxes, color=ps.white)
ax3.set_xlabel('EODf [Hz]')
handles, labels = ax2.get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center',
ncol=2, bbox_to_anchor=(0.5, 1.04))
# pearson r
plt.savefig('../poster/figs/chirps_winner_loser.pdf')
plt.show()

View File

@ -45,30 +45,46 @@ def main(datapath: str):
chirps_in_chasings = []
for onset, offset in zip(chasing_onset, chasing_offset):
chirps_in_chasing = [c for c in bh.chirps if (c > onset) & (c < offset)]
chirps_in_chasing = [
c for c in bh.chirps if (c > onset) & (c < offset)]
chirps_in_chasings.append(chirps_in_chasing)
try:
time_chasing = np.sum(chasing_offset[chasing_offset<3*60*60] - chasing_onset[chasing_onset<3*60*60])
time_chasing = np.sum(
chasing_offset[chasing_offset < 3*60*60] - chasing_onset[chasing_onset < 3*60*60])
except:
time_chasing = np.sum(chasing_offset[chasing_offset<3*60*60] - chasing_onset[chasing_onset<3*60*60][:-1])
time_chasing = np.sum(
chasing_offset[chasing_offset < 3*60*60] - chasing_onset[chasing_onset < 3*60*60][:-1])
time_chasing_percent = (time_chasing/(3*60*60))*100
chirps_chasing = np.asarray(flatten(chirps_in_chasings))
chirps_chasing_new = chirps_chasing[chirps_chasing<3*60*60]
chirps_percent = (len(chirps_chasing_new)/len(bh.chirps))*100
chirps_chasing_new = chirps_chasing[chirps_chasing < 3*60*60]
chirps_percent = (len(chirps_chasing_new) /
len(bh.chirps[bh.chirps < 3*60*60]))*100
time_precents.append(time_chasing_percent)
chirps_percents.append(chirps_percent)
fig, ax = plt.subplots(1, 1, figsize=(14*ps.cm, 10*ps.cm))
ax.boxplot([time_precents, chirps_percents])
ax.set_xticklabels(['Time Chasing', 'Chirps in Chasing'])
fig, ax = plt.subplots(1, 1, figsize=(7*ps.cm, 7*ps.cm))
scatter_time = 1.20
scatter_chirps = 1.80
size = 10
bplot1 = ax.boxplot([time_precents, chirps_percents],
showfliers=False, patch_artist=True)
ps.set_boxplot_color(bplot1, ps.gray)
ax.set_xticklabels(['Time \nChasing', 'Chirps \nin Chasing'])
ax.set_ylabel('Percent')
ax.scatter(np.ones(len(time_precents))*1.25, time_precents, color=ps.white)
ax.scatter(np.ones(len(chirps_percents))*1.75, chirps_percents, color=ps.white)
ax.scatter(np.ones(len(time_precents))*scatter_time, time_precents,
facecolor=ps.white, s=size)
ax.scatter(np.ones(len(chirps_percents))*scatter_chirps, chirps_percents,
facecolor=ps.white, s=size)
for i in range(len(time_precents)):
ax.plot([scatter_time, scatter_chirps], [time_precents[i],
chirps_percents[i]], alpha=0.6, linewidth=1, color=ps.white)
ax.text(0.1, 0.9, f'n={len(time_precents)}', transform=ax.transAxes)
plt.subplots_adjust(left=0.221, bottom=0.186, right=0.97, top=0.967)
plt.savefig('../poster/figs/chirps_in_chasing.pdf')
plt.show()
@ -77,5 +93,3 @@ if __name__ == '__main__':
# Path to the data
datapath = '../data/mount_data/'
main(datapath)

View File

@ -47,17 +47,17 @@ def main(datapath: str):
# Associate chirps to inidividual fish
fish1 = (bh.chirps[bh.chirps_ids == fish1_id] / 60) / 60
fish2 = (bh.chirps[bh.chirps_ids == fish2_id] / 60) / 60
fish1_color = ps.purple
fish2_color = ps.lavender
fish1_color = ps.gblue1
fish2_color = ps.gblue3
fig, ax = plt.subplots(5, 1, figsize=(
21*ps.cm, 10*ps.cm), height_ratios=[0.5, 0.5, 0.5, 0.2, 6], sharex=True)
# marker size
s = 80
ax[0].scatter(physical_contact, np.ones(
len(physical_contact)), color=ps.maroon, marker='|', s=s)
len(physical_contact)), color=ps.red, marker='|', s=s)
ax[1].scatter(chasing_onset, np.ones(len(chasing_onset)),
color=ps.orange, marker='|', s=s)
color=ps.purple, marker='|', s=s)
ax[2].scatter(fish1, np.ones(len(fish1))-0.25,
color=fish1_color, marker='|', s=s)
ax[2].scatter(fish2, np.zeros(len(fish2))+0.25,
@ -79,7 +79,6 @@ def main(datapath: str):
ax[0].set_xticks([])
ax[0].set_yticks([])
ps.hide_ax(ax[0])
ax[0].yaxis.set_label_coords(-0.1, 0.5)
ax[1].grid(False)
ax[1].set_frame_on(False)
@ -99,19 +98,23 @@ def main(datapath: str):
labelpad = 30
fsize = 12
ax[0].set_ylabel('contact', rotation=0,
ax[0].set_ylabel('Contact', rotation=0,
labelpad=labelpad, fontsize=fsize)
ax[1].set_ylabel('chasing', rotation=0,
ax[0].yaxis.set_label_coords(-0.062, -0.08)
ax[1].set_ylabel('Chasing', rotation=0,
labelpad=labelpad, fontsize=fsize)
ax[2].set_ylabel('chirps', rotation=0,
ax[1].yaxis.set_label_coords(-0.06, -0.08)
ax[2].set_ylabel('Chirps', rotation=0,
labelpad=labelpad, fontsize=fsize)
ax[2].yaxis.set_label_coords(-0.07, -0.08)
ax[4].set_ylabel('EODf')
ax[4].set_xlabel('time [h]')
ax[4].set_xlabel('Time [h]')
# ax[0].set_title(foldername.split('/')[-2])
# 2020-03-31-9_59
plt.subplots_adjust(left=0.158, right=0.987, top=0.918)
# plt.savefig('../poster/figs/timeline.pdf')
plt.subplots_adjust(left=0.158, right=0.987, top=0.918, bottom=0.136)
plt.savefig('../poster/figs/timeline.pdf')
plt.show()
# plot chirps

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -22,20 +22,20 @@ blockverticalspace=2mm, colspace=20mm, subcolspace=0mm]{tikzposter} %Default val
weakly electric fish impossible. This profoundly limits our current
understanding of chirps to experiments
with single - or physically separated - individuals.
% \begin{tikzfigure}[]
% \label{griddrawing}
% \includegraphics[width=0.8\linewidth]{figs/introplot}
% \end{tikzfigure}
\begin{tikzfigure}[]
\label{griddrawing}
\includegraphics[width=0.6\linewidth]{figs/introplot}
\end{tikzfigure}
}
\myblock[TranspBlock]{Chirp detection}{
\begin{tikzfigure}[]
\label{fig:alg1}
\includegraphics[width=0.9\linewidth]{figs/algorithm1}
\includegraphics[width=0.6\linewidth]{figs/algorithm1}
\end{tikzfigure}
\vspace{2cm}
\begin{tikzfigure}[]
\label{fig:alg2}
\includegraphics[width=1\linewidth]{figs/algorithm}
\includegraphics[width=0.9\linewidth]{figs/algorithm}
\end{tikzfigure}
\vspace{0cm}
}
@ -49,34 +49,35 @@ blockverticalspace=2mm, colspace=20mm, subcolspace=0mm]{tikzposter} %Default val
\noindent
\begin{itemize}
\setlength\itemsep{0.5em}
\item Two fish compete for one hidding place in one tank,
\item Two fish compete for one hidding place in one tank.
\item Experiment had a 3 hour long darkphase and a 3 hour long light phase.
\end{itemize}
\noindent
\begin{minipage}[c]{0.7\linewidth}
\begin{tikzfigure}[]
\label{fig:example_b}
\includegraphics[width=\linewidth]{figs/chirps_winner_loser.pdf}
\end{tikzfigure}
\end{minipage} % no space if you would like to put them side by side
\begin{minipage}[c]{0.2\linewidth}
\begin{itemize}
\setlength\itemsep{0.5em}
\item Fish who won the competition chirped more often than the fish who lost.
\item
\end{itemize}
\end{minipage}
}
\myblock[TranspBlock]{Interactions at modulations}{
\vspace{-1.2cm}
\begin{tikzfigure}[]
\label{fig:example_c}
\includegraphics[width=0.5\linewidth]{example-image-c}
\label{fig:example_b}
\includegraphics[width=\linewidth]{figs/chirps_winner_loser.pdf}
\end{tikzfigure}
\noindent
\begin{itemize}
\item Fish who lost the competition chirped more often than the fish who lost.
\item Size has an effect on the Competition outcome, and the chirp count.
\item Frequency of the fish has no effect on the competition outcome.
\end{itemize}
}
\myblock[TranspBlock]{Are Chirps coding for onset or offset of physical interaction?}{
\vspace{-1.2cm}
\begin{minipage}{0.6666\linewidth}
\begin{tikzfigure}[]
\includegraphics[width=0.3\linewidth]{figs/chirps_in_chasing.pdf}
\end{tikzfigure}
\end{minipage}
\begin{minipage}{0.3333\linewidth}
\begin{tikzfigure}[]
\includegraphics[width=\linewidth]{figs/chirps_in_chasing.pdf}
\end{tikzfigure}
\end{minipage}
}
\myblock[GrayBlock]{Conclusion}{