Upload files to ''
This commit is contained in:
		
							parent
							
								
									d0d2690f96
								
							
						
					
					
						commit
						f464823801
					
				
							
								
								
									
										94
									
								
								plot_running_std.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								plot_running_std.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,94 @@ | |||||||
|  | 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__': | ||||||
|  | 
 | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load data | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load all the data of one day | ||||||
|  |     filename = sorted(os.listdir('../../../data/'))[1] | ||||||
|  |     aifl = np.load('../data/'+filename+'/aifl2.npy', allow_pickle=True) | ||||||
|  | 
 | ||||||
|  |     # all_max_ch_means = np.load('../data/' + filename + '/all_max_ch_means.npy', allow_pickle=True) | ||||||
|  |     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) | ||||||
|  |     ipp = np.load('../data/' + filename + '/all_ipp.npy', allow_pickle=True) | ||||||
|  |     power_means = np.load('../data/' + filename + '/power_means.npy', allow_pickle=True) | ||||||
|  | 
 | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # parameter and variables | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # plot params | ||||||
|  |     # variables | ||||||
|  |     sampling_rate = 1/np.diff(all_Ctime_v[0])[0]  # in sec | ||||||
|  | 
 | ||||||
|  |     # lists | ||||||
|  |     fish_in_aifl = list(np.unique(np.where(~np.isnan(aifl[:, :, 0]))[1])) | ||||||
|  |     thresholds = np.full(3, np.nan) | ||||||
|  |     all_run_std = [] | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # analysis | ||||||
|  |     ################################################################################################################### | ||||||
|  |     fig = plt.figure(figsize=(16, 14)) | ||||||
|  |     spec = gridspec.GridSpec(ncols=2, nrows=2, figure=fig) | ||||||
|  |     ax1 = fig.add_subplot(spec[0, 0]) | ||||||
|  |     ax2 = fig.add_subplot(spec[0, 1]) | ||||||
|  |     ax3 = fig.add_subplot(spec[1, 0]) | ||||||
|  | 
 | ||||||
|  |     for fish in range(len(fish_in_aifl)): | ||||||
|  | 
 | ||||||
|  |         run_mean, run_std = hf.running_3binsizes(ipp[fish], sampling_rate) | ||||||
|  |         all_run_std.append(run_std) | ||||||
|  | 
 | ||||||
|  |         if len(np.arange(len(run_mean[2]))[~np.isnan(run_mean[2])]) < 10: | ||||||
|  |             continue | ||||||
|  | 
 | ||||||
|  |         ########################################################################################################### | ||||||
|  |         # plot | ||||||
|  |         # hf.plot_running(all_xticks, run_mean, run_std, threshold, fish, color_vec, fs, fs_ticks, lw) | ||||||
|  |         # plt.show() | ||||||
|  | 
 | ||||||
|  |         for ax_cntr ,ax in enumerate([ax1, ax2, ax3]): | ||||||
|  |             non_nan = np.arange(len(run_mean[ax_cntr]))[~np.isnan(run_mean[ax_cntr])] | ||||||
|  |             ax.plot(all_xticks[fish][non_nan], run_std[ax_cntr][non_nan], '.', color=color_vec[fish]) | ||||||
|  |             ax.timeaxis() | ||||||
|  |             ax.make_nice_ax() | ||||||
|  | 
 | ||||||
|  |         ax1.set_xlabel('Time [h]', fontsize=fs) | ||||||
|  | 
 | ||||||
|  |     rs = np.array(all_run_std) | ||||||
|  | 
 | ||||||
|  |     for idx in range(3): | ||||||
|  |         rs1 = np.hstack(rs[:, idx]) | ||||||
|  |         rs1 = rs1[~np.isnan(rs1)] | ||||||
|  |         rs1 = rs1[rs1>0] | ||||||
|  |         print(np.percentile(rs1, [5, 95, 50])) | ||||||
|  |         thresholds[idx] = np.percentile(rs1, 50) | ||||||
|  | 
 | ||||||
|  |     if filename not in os.listdir('../data/'): | ||||||
|  |         os.mkdir('../data/'+filename) | ||||||
|  | 
 | ||||||
|  |     np.save('../data/' + filename + '/thresholds.npy', thresholds) | ||||||
|  | 
 | ||||||
|  |     fig2, ax2 = plt.subplots() | ||||||
|  | 
 | ||||||
|  |     ax2.hist(np.hstack(rs[:,0]), bins=200) | ||||||
|  |     ax2.hist(np.hstack(rs[:,1]), bins=200) | ||||||
|  |     ax2.hist(np.hstack(rs[:,2]), bins=200) | ||||||
|  |     plt.show() | ||||||
|  | 
 | ||||||
|  |     embed() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
							
								
								
									
										74
									
								
								plot_trajec_5_47.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								plot_trajec_5_47.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,74 @@ | |||||||
|  | import numpy as np | ||||||
|  | import matplotlib.pyplot as plt | ||||||
|  | import matplotlib.dates as mdates | ||||||
|  | import matplotlib.gridspec as gridspec | ||||||
|  | 
 | ||||||
|  | from IPython import embed | ||||||
|  | import helper_functions as hf | ||||||
|  | from params import * | ||||||
|  | import os | ||||||
|  | import datetime | ||||||
|  | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # parameter and variables | ||||||
|  |     # plot params | ||||||
|  |     inch = 2.45 | ||||||
|  |     save_path = '../../thesis/Figures/Results/' | ||||||
|  |     kernel_size = 100 | ||||||
|  | 
 | ||||||
|  |     fig = plt.figure(constrained_layout=True, figsize=[13 / inch, 15 / inch]) | ||||||
|  |     gs = gridspec.GridSpec(ncols=1, nrows=2, figure=fig, hspace=0.05, wspace=0.0, | ||||||
|  |                            left=0.1, bottom=0.15, right=0.95, top=0.98) | ||||||
|  | 
 | ||||||
|  |     ax1 = fig.add_subplot(gs[0, 0]) | ||||||
|  |     ax2 = fig.add_subplot(gs[1, 0]) | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load all the data of one day | ||||||
|  | 
 | ||||||
|  |     for filename_idx in [0]: | ||||||
|  |         filename = sorted(os.listdir('../data/'))[filename_idx] | ||||||
|  | 
 | ||||||
|  |         all_max_ch_means = np.load('../data/' + filename + '/all_max_ch.npy', allow_pickle=True) | ||||||
|  |         all_xticks = np.load('../data/' + filename + '/all_xtickses.npy', allow_pickle=True) | ||||||
|  |         all_ipp = np.load('../data/' + filename + '/all_ipp.npy', allow_pickle=True) | ||||||
|  |         power_means = np.load('../data/' + filename + '/power_means.npy', allow_pickle=True) | ||||||
|  |         freq = np.load('../data/' + filename + '/fish_freq_q10.npy', allow_pickle=True) | ||||||
|  |         ############################################################################################################### | ||||||
|  |         # get fish | ||||||
|  |         for fish_number, ax, ax_idx in zip([5,47], [ax1,ax2], [0, 1]): | ||||||
|  |             if power_means[fish_number] >= -90.0: | ||||||
|  |                 ipp = all_ipp[fish_number] | ||||||
|  |                 x_tickses = all_xticks[fish_number] | ||||||
|  |                 max_ch_mean = all_max_ch_means[fish_number] | ||||||
|  | 
 | ||||||
|  |                 # smoothing of max channel mean | ||||||
|  |                 kernel = np.ones(kernel_size) / kernel_size | ||||||
|  |                 smooth_mcm = np.convolve(max_ch_mean, kernel, 'valid') | ||||||
|  | 
 | ||||||
|  |                 try: | ||||||
|  |                     smooth_x = x_tickses[int(np.ceil(kernel_size/2)):-int(np.floor(kernel_size/2))] | ||||||
|  |                 except: | ||||||
|  |                     embed() | ||||||
|  |                     quit() | ||||||
|  | 
 | ||||||
|  |                 ##################################################################################################### | ||||||
|  |                 # plot traces | ||||||
|  |                 ax.imshow(ipp[::20].T[::-1], vmin=-100, vmax=-50, aspect='auto', interpolation='gaussian', | ||||||
|  |                            extent=[x_tickses[0], x_tickses[-1], -0.5, 15.5]) | ||||||
|  |                 try: | ||||||
|  |                     ax.plot(smooth_x[::20], smooth_mcm[::20], '.', color=color2[4]) | ||||||
|  |                 except: | ||||||
|  |                     continue | ||||||
|  | 
 | ||||||
|  |                 ax.beautimechannelaxis() | ||||||
|  |                 ax.timeaxis() | ||||||
|  |                 ax.text(-0.12, 0.95, chr(ord('A') + ax_idx), transform=ax.transAxes, fontsize='large') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     fig.savefig(save_path + 'trajectory_5_47.pdf') | ||||||
|  |     # fig.savefig('../../../goettingen2021_poster/pictures/trajectory_5_47.pdf') | ||||||
|  |     plt.show() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
							
								
								
									
										267
									
								
								plot_transit_fish.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										267
									
								
								plot_transit_fish.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,267 @@ | |||||||
|  | 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 os | ||||||
|  | from IPython import embed | ||||||
|  | import helper_functions as hf | ||||||
|  | from params import * | ||||||
|  | import itertools | ||||||
|  | from statisitic_functions import * | ||||||
|  | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # parameter and variables | ||||||
|  |     # plot params | ||||||
|  |     inch = 2.45 | ||||||
|  |     save_path = '../../thesis/Figures/Results/' | ||||||
|  | 
 | ||||||
|  |     # kernel | ||||||
|  |     kernel_size = 120 | ||||||
|  |     kernel = np.ones(kernel_size) / kernel_size | ||||||
|  | 
 | ||||||
|  |     # counter | ||||||
|  |     stl_counter = 0 | ||||||
|  |     ax0_counter = 0 | ||||||
|  | 
 | ||||||
|  |     # transit: start, stop, dur | ||||||
|  |     transit_data = [] | ||||||
|  |     # transit: time, trajectory | ||||||
|  |     xy_transit = [] | ||||||
|  |     # transit: metadata: name, freq | ||||||
|  |     transit_meta = [] | ||||||
|  | 
 | ||||||
|  |     # average speed | ||||||
|  |     speed = [] | ||||||
|  | 
 | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load data | ||||||
|  |     ################################################################################################################### | ||||||
|  | 
 | ||||||
|  |     for day_idx in [0, 1, 2, 3]: | ||||||
|  | 
 | ||||||
|  |         filename = sorted(os.listdir('../data/'))[day_idx] | ||||||
|  |         aifl = np.load('../data/' + filename + '/aifl2.npy', allow_pickle=True) | ||||||
|  | 
 | ||||||
|  |         all_xticks = np.load('../data/' + filename + '/all_xtickses.npy', allow_pickle=True) | ||||||
|  |         all_max_ch_means = np.load('../data/' + filename + '/all_max_ch.npy', allow_pickle=True) | ||||||
|  |         power_means = np.load('../data/' + filename + '/power_means.npy', allow_pickle=True) | ||||||
|  |         all_hms = np.load('../data/' + filename + '/all_hms.npy', allow_pickle=True) | ||||||
|  |         freq = np.load('../data/' + filename + '/fish_freq_q10.npy', allow_pickle=True) | ||||||
|  |         names = np.load('../data/' + filename + '/fish_species.npy', allow_pickle=True) | ||||||
|  |         ############################################################################################################### | ||||||
|  |         # lists | ||||||
|  |         fish_in_aifl = list(np.unique(np.where(~np.isnan(aifl[:, :, 0]))[1])) | ||||||
|  |         # directs = [] | ||||||
|  |         flat_x = np.unique(np.hstack(all_xticks)) | ||||||
|  | 
 | ||||||
|  |         ############################################################################################################### | ||||||
|  |         # analysis of the changes and trajectories | ||||||
|  |         for fish_number in range(len(power_means)): | ||||||
|  |             if power_means[fish_number] >= -90.0: | ||||||
|  | 
 | ||||||
|  |                 x_tickses = all_xticks[fish_number] | ||||||
|  |                 max_ch_mean = all_max_ch_means[fish_number] | ||||||
|  | 
 | ||||||
|  |                 # smoothing of max channel mean | ||||||
|  |                 kernel = np.ones(kernel_size) / kernel_size | ||||||
|  |                 smooth_mcm = np.convolve(max_ch_mean, kernel, 'valid') | ||||||
|  | 
 | ||||||
|  |                 smooth_x = x_tickses[int(np.ceil(kernel_size / 2)):-int(np.floor(kernel_size / 2) - 1)] | ||||||
|  | 
 | ||||||
|  |                 # interpolate | ||||||
|  |                 fish_x = flat_x[np.where(flat_x == x_tickses[0])[0][0]:np.where(flat_x == x_tickses[-1])[0][0] + 1] | ||||||
|  |                 try: | ||||||
|  |                     trajectory = np.round(np.interp(fish_x, smooth_x, smooth_mcm)) | ||||||
|  |                 except: | ||||||
|  |                     continue | ||||||
|  | 
 | ||||||
|  |                 # trial duration | ||||||
|  |                 t_s = datetime.timedelta(np.diff([fish_x[0], fish_x[-1]])[0]) | ||||||
|  |                 trial_dur = t_s.total_seconds() / 60 | ||||||
|  | 
 | ||||||
|  |                 # average speed | ||||||
|  |                 speed.append(np.sum(np.abs(np.diff(trajectory))) / trial_dur) | ||||||
|  | 
 | ||||||
|  |                 # activity vs. time | ||||||
|  |                 t = np.array(all_hms[fish_number] / 60 / 60) | ||||||
|  | 
 | ||||||
|  |                 # swim through | ||||||
|  |                 first = fish_x[0] | ||||||
|  |                 last = fish_x[-1] | ||||||
|  | 
 | ||||||
|  |                 start15 = mdates.date2num(mdates.num2date(first) + datetime.timedelta(seconds=2 * 60)) | ||||||
|  |                 stop15 = mdates.date2num(mdates.num2date(last) - datetime.timedelta(seconds=2 * 60)) | ||||||
|  | 
 | ||||||
|  |                 y = trajectory | ||||||
|  |                 # t = np.roll(t, int(len(np.unique(np.hstack(all_hms)))/2)) | ||||||
|  | 
 | ||||||
|  |                 if np.any(trajectory[fish_x < start15] >= 13) and np.any(trajectory[fish_x > stop15] <= 2): | ||||||
|  | 
 | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 elif np.any(trajectory[fish_x < start15] <= 2) and np.any(trajectory[fish_x > stop15] >= 13): | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 elif np.any(trajectory[fish_x < start15] <= 1) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] >= 6) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] <= 7): | ||||||
|  | 
 | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 elif np.any(trajectory[fish_x < start15] >= 6) \ | ||||||
|  |                         and np.any(trajectory[fish_x < start15] <= 7) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] <= 1): | ||||||
|  | 
 | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 elif np.any(trajectory[fish_x < start15] >= 14) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] >= 8) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] <= 9): | ||||||
|  | 
 | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 elif np.any(trajectory[fish_x < start15] >= 8) \ | ||||||
|  |                         and np.any(trajectory[fish_x < start15] <= 9) \ | ||||||
|  |                         and np.any(trajectory[fish_x > stop15] >= 14): | ||||||
|  | 
 | ||||||
|  |                     xy_transit.append(np.array([t, y])) | ||||||
|  |                     transit_data.append(np.array([t[0], t[-1], trial_dur, day_idx])) | ||||||
|  |                     transit_meta.append([names[fish_number], freq[fish_number,2]]) | ||||||
|  | 
 | ||||||
|  |                 else: | ||||||
|  |                     continue | ||||||
|  | 
 | ||||||
|  |     transit_data = np.array(transit_data) | ||||||
|  | 
 | ||||||
|  |     ############################################################################################################### | ||||||
|  |     # figure 1: time points of transit fish and trajectories | ||||||
|  |     fig = plt.figure(constrained_layout=True, figsize=[15 / inch, 12 / inch]) | ||||||
|  |     gs = gridspec.GridSpec(ncols=2, nrows=3, figure=fig, hspace=0.05, wspace=0.0, | ||||||
|  |                            height_ratios=[1, 1, 1], left=0.1, bottom=0.15, right=0.95, top=0.95) | ||||||
|  | 
 | ||||||
|  |     ax0 = fig.add_subplot(gs[0, :]) | ||||||
|  |     ax1 = fig.add_subplot(gs[1, 0]) | ||||||
|  |     ax2 = fig.add_subplot(gs[1, 1]) | ||||||
|  |     ax3 = fig.add_subplot(gs[2, 0]) | ||||||
|  |     ax4 = fig.add_subplot(gs[2, 1]) | ||||||
|  | 
 | ||||||
|  |     ############################################################################################################### | ||||||
|  |     # plotting | ||||||
|  |     color_list = [0, 1, 4, 6] | ||||||
|  |     for ploti in range(len(transit_data)): | ||||||
|  |         if transit_data[ploti, 2] < 3 * 60: | ||||||
|  |             # colori = color_list[int(transit_data[ploti, 3])] | ||||||
|  | 
 | ||||||
|  |             if transit_meta[ploti][0] == 'Eigenmannia': | ||||||
|  |                 colori = 0 | ||||||
|  |             elif transit_meta[ploti][1] < 750: | ||||||
|  |                 colori = 1 | ||||||
|  |             else: | ||||||
|  |                 colori = 2 | ||||||
|  | 
 | ||||||
|  |             # plot time when fish is there | ||||||
|  |             if transit_data[ploti, 0]<12: | ||||||
|  |                 roll_factor = 12 | ||||||
|  |             else: | ||||||
|  |                 roll_factor = -12 | ||||||
|  |             ax0.plot(transit_data[ploti, :2] + roll_factor, [ax0_counter, ax0_counter], color=color_efm[colori], lw=3, | ||||||
|  |                      label=labels[colori]) | ||||||
|  |             ax0_counter += 1 | ||||||
|  |             if transit_data[ploti + 1, 3] != transit_data[ploti, 3]: | ||||||
|  |                 ax0.plot([0, 24], [ax0_counter, ax0_counter], color=color_diffdays[0], lw=1, linestyle='dashed') | ||||||
|  |                 print(ax0_counter, transit_data[ploti, 3], transit_data[ploti+1, 3]) | ||||||
|  |                 ax0_counter += 1 | ||||||
|  | 
 | ||||||
|  |             # plot trajectories | ||||||
|  |             if transit_data[ploti, 0] > 1 and transit_data[ploti, 1] <= 3.5: | ||||||
|  |                 ax2.plot(xy_transit[ploti][0], xy_transit[ploti][1], color=color_efm[colori]) | ||||||
|  |                 ax2.set_xlim([1, 3.1]) | ||||||
|  |                 ax2.set_xticks([1,2,3]) | ||||||
|  |                 ax2.set_xticklabels(['01:00', '02:00', '03:00']) | ||||||
|  | 
 | ||||||
|  |             elif transit_data[ploti, 0] > 2.5 and transit_data[ploti, 1] <= 5: | ||||||
|  |                 ax4.plot(xy_transit[ploti][0], xy_transit[ploti][1], color=color_efm[colori]) | ||||||
|  |                 ax4.set_xlim([3, 5]) | ||||||
|  |                 ax4.set_xticks([3,4,5]) | ||||||
|  |                 ax4.set_xticklabels(['03:00', '04:00', '05:00']) | ||||||
|  | 
 | ||||||
|  |             elif transit_data[ploti, 0] > 18 and transit_data[ploti, 1] <= 20: | ||||||
|  |                 ax1.plot(xy_transit[ploti][0], xy_transit[ploti][1], color=color_efm[colori]) | ||||||
|  |                 ax1.set_xlim([18, 20]) | ||||||
|  |                 ax1.set_xticks([18,19,20]) | ||||||
|  |                 ax1.set_xticklabels(['18:00', '19:00', '20:00']) | ||||||
|  | 
 | ||||||
|  |             elif transit_data[ploti, 0] > 20 and transit_data[ploti, 1] <= 22: | ||||||
|  |                 ax3.plot(xy_transit[ploti][0], xy_transit[ploti][1], color=color_efm[colori]) | ||||||
|  |                 ax3.set_xlim([20, 22]) | ||||||
|  |                 ax3.set_xticks([20,21,22]) | ||||||
|  |                 ax3.set_xticklabels(['20:00', '21:00', '22:00']) | ||||||
|  | 
 | ||||||
|  |     ################################################################################################################# | ||||||
|  |     # nice axis | ||||||
|  |     tagx = [-0.07, -0.17, -0.07, -0.17, -0.07] | ||||||
|  |     tagy = [0.95,1.05,1.05,1.05,1.05] | ||||||
|  |     for ax_idx, axis in enumerate([ax0,ax1,ax2,ax3,ax4]): | ||||||
|  |         axis.text(tagx[ax_idx], tagy[ax_idx], chr(ord('A') + ax_idx), transform=axis.transAxes, fontsize='large') | ||||||
|  |         axis.make_nice_ax() | ||||||
|  |         axis.invert_yaxis() | ||||||
|  |         if axis != ax0: | ||||||
|  |             axis.axhline(7.5, xmin=0, xmax=15, color='white', lw=2) | ||||||
|  |             # ax.set_yticklabels([1, 3, 5, 7, 14, 16, 18, 20]) | ||||||
|  |             axis.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 7.5, 8, 9, 10, 11, 12, 13, 14, 15]) | ||||||
|  |             axis.set_yticklabels([]) | ||||||
|  |             if axis == ax1 or axis == ax3: | ||||||
|  |                 axis.set_yticklabels(['1', '', '', '', '5', '', '', '', 'gap', '', '', '', '12', '', '', '', '16']) | ||||||
|  |                 axis.set_ylabel('Electrode', fontsize=11) | ||||||
|  | 
 | ||||||
|  |             if axis == ax3 or axis == ax4: | ||||||
|  |                 axis.set_xlabel('Time', fontsize=11) | ||||||
|  | 
 | ||||||
|  |     daytagy = [0.1, 0.5, 0.9] | ||||||
|  |     for dayi in [0,1,2]: | ||||||
|  |         ax0.text(0.02, daytagy[dayi], 'Day '+ str(dayi), transform=ax0.transAxes, fontsize='small', va='center', ha='left') | ||||||
|  | 
 | ||||||
|  |     ax0.set_ylabel('Fish') | ||||||
|  |     ax0.set_yticks([]) | ||||||
|  |     ax0.set_xlim([-0.1, 24.1]) | ||||||
|  |     ax0.set_xticks(np.arange(0, 25, 3)) | ||||||
|  |     ax0.set_xticklabels(['12:00', '15:00', '18:00', '21:00', '00:00', '03:00', '06:00', '09:00', '12:00']) | ||||||
|  | 
 | ||||||
|  |     fig.align_ylabels() | ||||||
|  |     # handles, labels = ax0.get_legend_handles_labels() | ||||||
|  |     # unique = [(h, l) for lwdl_idx, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:lwdl_idx]] | ||||||
|  |     # ax0.legend(*zip(*unique), bbox_to_anchor=(1, 1), loc="upper right", bbox_transform=fig.transFigure, ncol=1) | ||||||
|  |     # fig.legend() | ||||||
|  |     fig.savefig(save_path + 'transit.pdf') | ||||||
|  |     plt.show() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     ############################################################################################################### | ||||||
|  |     # speed | ||||||
|  |     c = np.load('../data/all_changes.npy', allow_pickle=True) | ||||||
|  |     stl = np.load('../data/stl.npy', allow_pickle=True) | ||||||
|  | 
 | ||||||
|  |     speeds = [] | ||||||
|  |     for ploti in range(len(transit_data)): | ||||||
|  |         if transit_data[ploti, 2] < 3 * 60: | ||||||
|  |             speeds.append((np.max(xy_transit[ploti][1])-np.min(xy_transit[ploti][1]))/transit_data[ploti, 2]) | ||||||
|  | 
 | ||||||
|  |     min =(np.mean(speeds)-np.std(speeds))*60*12 | ||||||
|  |     max =(np.mean(speeds)+np.std(speeds))*60*12/1000 | ||||||
|  |     embed() | ||||||
							
								
								
									
										174
									
								
								plot_when_are_you.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								plot_when_are_you.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,174 @@ | |||||||
|  | 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) | ||||||
							
								
								
									
										24
									
								
								replace_channel.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								replace_channel.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | 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__': | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load data | ||||||
|  |     ################################################################################################################### | ||||||
|  |     # load all the data of one day | ||||||
|  | 
 | ||||||
|  |     to_be_changed_ident = np.load('../../../Desktop/2019-10-08-18_07/all_ident_v.npy', allow_pickle=True) | ||||||
|  |     correct_ident = np.load('../../../Desktop/2019-10-08-18_07_old/all_ident_v.npy', allow_pickle=True) | ||||||
|  | 
 | ||||||
|  |     embed() | ||||||
|  |     quit() | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user