diff --git a/create_ethogram.py b/create_ethogram.py index 832cb87..12e0fdd 100644 --- a/create_ethogram.py +++ b/create_ethogram.py @@ -1,66 +1,100 @@ from matplotlib import pyplot as plt from matplotlib import patches as mpatches import numpy as np #enter the names of the csv files used to create the ethogram csv_files = ['test_animals/test1.csv', 'test_animals/test2.csv', 'test_animals/test3.csv', 'test_animals/test4.csv', 'test_animals/test5.csv', 'test_animals/test6.csv'] labels = ['fly 1\n13A', 'fly 1\n7.5A', 'fly 2\n7.5A', 'fly 2\n13A', 'fly 3\n13A', 'fly 3\n7.5A'] +csv_files = ['test_animals/test2.csv'] +labels = [''] inter_frame_interval = 1./30. N = len(csv_files) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) fig = plt.figure() ax1 = fig.add_subplot(111) +signals = np.zeros((N,3,9000)) +event_index = np.zeros((N,4)) #index for signals that separate the stimulation events + #plot individual animals for i in range(N): a = np.genfromtxt(csv_files[i]).astype(np.int_) if a[1,2]==-1: a[2:,:2] = a[2:,:2] - np.ones(a[2:,:2].shape)*a[1,1] else: print('Cannot determine off-set. The two initial blinks of the LED should be in the first two rows.') index0=np.where(a[:,2]==0) index1=np.where(a[:,2]==1) index2=np.where(a[:,2]==2) - data0 = np.empty(sum((a[index0,1]-a[index0,0])[0])) - data1 = np.empty(sum((a[index1,1]-a[index1,0])[0])) - data2 = np.empty(sum((a[index2,1]-a[index2,0])[0])) + data0 = np.empty(sum((a[index0,1]-a[index0,0])[0]),dtype=np.int_) + data1 = np.empty(sum((a[index1,1]-a[index1,0])[0]),dtype=np.int_) + data2 = np.empty(sum((a[index2,1]-a[index2,0])[0]),dtype=np.int_) l0 = 0 l1 = 0 l2 = 0 for j in range(len(a)): if a[j,2]==0: #print('difference',a[j,1]-a[j,0]) #print(a[j,0]) #print(a[j,1]) data0[l0:l0+a[j,1]-a[j,0]]=np.arange(a[j,0],a[j,1]) l0 = l0+a[j,1]-a[j,0] elif a[j,2]==1: data1[l1:l1+a[j,1]-a[j,0]]=np.arange(a[j,0],a[j,1]) l1 = l1+a[j,1]-a[j,0] elif a[j,2]==2: data2[l2:l2+a[j,1]-a[j,0]]=np.arange(a[j,0],a[j,1]) l2 = l2+a[j,1]-a[j,0] ax1.eventplot(data0*inter_frame_interval, colors=[colors[0]], lineoffsets=[i+1], linelengths=[1]) ax1.eventplot(data1*inter_frame_interval, colors=[colors[1]], lineoffsets=[i+1], linelengths=[0.8]) ax1.eventplot(data2*inter_frame_interval, colors=[colors[2]], lineoffsets=[i+1], linelengths=[0.8]) + signals[i,0,data0]=1 + signals[i,1,data1]=1 + signals[i,2,data2]=1 + plt.rcParams.update({'font.size': 20}) ax1.set_title('Grooming behaviour') ax1.set_xlabel('time in seconds') plt.yticks(range(1,N+1),labels) ax1.set_xlim(-5,300) ax1.set_ylim(0.5,N+1) patch0 = mpatches.Patch(color=colors[0], label='Magnet on') patch1 = mpatches.Patch(color=colors[1], label='foreleg grooming') patch2 = mpatches.Patch(color=colors[2], label='head related grooming') plt.legend(handles=[patch0, patch1, patch2],prop={'size': 12}) #only works in python 3 +plt.savefig('ethogram.pdf') +#plt.show() + +fig2 = plt.figure() +ax21 = fig2.add_subplot(141) +ax22 = fig2.add_subplot(142) +ax23 = fig2.add_subplot(143) +ax24 = fig2.add_subplot(144) +#ax25 = fig2.add_subplot(155) + +for i in range(N): + #ax2.plot(np.arange(9000)*inter_frame_interval, np.correlate(signals[i,0,:], signals[i,1,:],'same'), label="foreleg grooming") + ax21.plot(np.arange(2098)*inter_frame_interval, np.correlate(signals[i,0,0:2098], signals[i,2,0:2098],'same'), label="head grooming") + ax22.plot(np.arange(2098)*inter_frame_interval, np.correlate(signals[i,0,2099:4197], signals[i,2,2099:4197],'same'), label="head grooming") + ax23.plot(np.arange(2098)*inter_frame_interval, np.correlate(signals[i,0,4198:6296], signals[i,2,4198:6296],'same'), label="head grooming") + ax24.plot(np.arange(2098)*inter_frame_interval, np.correlate(signals[i,0,6297:8395], signals[i,2,6297:8395],'same'), label="head grooming") +#plt.legend() + +#for ji in range(N): +# ax25.plot(np.arange(2098)*inter_frame_interval, signals[ji,0,0:2098]) +# ax25.plot(np.arange(2098)*inter_frame_interval, signals[ji,0,2099:4197]) +# ax25.plot(np.arange(2098)*inter_frame_interval, signals[ji,0,4198:6296]) +# ax25.plot(np.arange(2098)*inter_frame_interval, signals[ji,0,6297:8395]) + +plt.savefig('correlation.pdf') plt.show()