def make_histograms(config, data, colors, savename='histogram.pdf'): print data fig = plt.figure(figsize=(5,4)) ax = fig.add_subplot(111) bins = np.linspace(-.5,.5,150) fpl.histogram(ax, data.values(), bins=bins, bin_width_ratio=1, colors=colors.values(), edgecolor='none', bar_alpha=1, curve_fill_alpha=0.2, curve_line_alpha=1, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, smoothing_bins_to_exclude=[74,75,76]) xticks = [-.5, 0, .5] fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) #ax.set_xticklabels(xticklabels) ax.set_xlabel('altitudes') ax.set_ylabel('occurences, normalized') path = config.path figure_path = os.path.join(config.path, config.figure_path) save_figure_path=os.path.join(figure_path, 'odor_traces/') figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') fig_name_with_path = os.path.join(save_figure_path, savename) print 'SAVING TO: ', fig_name_with_path fig.savefig(fig_name_with_path, format='pdf')
def plot_digits_distribution(n): fig = plt.figure() ax = fig.add_subplot(111) bins = np.arange(-.5, 10.5, 1) npages = [30, 60, 400, 1500] colors = ['black', 'blue', 'green', 'red'] digits = [] for npage in npages: d = get_digits(n, npage) digits.append(np.array(d)) xticks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] fpl.histogram(ax, digits, bins=bins, colors=colors, normed=True, show_smoothed=False) fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_ylim(0, 0.15) ax.set_xlim(-1, 10) ax.set_xlabel('digit') ax.set_ylabel('probability')
def make_histograms(config, data, colors, savename='orientation_histogram.pdf'): print data fig = plt.figure(figsize=(5,4)) ax = fig.add_subplot(111) bins = np.linspace(-np.pi,np.pi,50) fpl.histogram(ax, data.values(), bins=bins, bin_width_ratio=1, colors=colors.values(), edgecolor='none', bar_alpha=1, curve_fill_alpha=0.2, curve_line_alpha=1, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, smoothing_bins_to_exclude=[]) xticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi] ax.set_xlim(xticks[0], xticks[-1]) fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_xlabel('heading') xticklabels = ['-180', '-90', 'upwind', '90', '180'] ax.set_xticklabels(xticklabels) ax.set_ylabel('occurences, normalized') path = config.path figure_path = os.path.join(config.path, config.figure_path) save_figure_path=os.path.join(figure_path, 'odor_traces/') figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') fig_name_with_path = os.path.join(save_figure_path, savename) print 'SAVING TO: ', fig_name_with_path fig.savefig(fig_name_with_path, format='pdf')
def plot_trajectory_lengths(dataset): lengths = [] for key, trajec in dataset.trajecs.items(): lengths.append(trajec.length) fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, [np.array(lengths)], bins=50, show_smoothed=False)
def plot_residency_time_histogram(config, dataset, save_figure_path=''): odor_stimulus = 'on' threshold_distance_min = 0.05 # no odor keys_odor_off = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=10, threshold_distance=-1, odor_stimulus='none', upwind_only=True, threshold_distance_min=0.1, odor=True, post_behavior='landing') residency_time_odor_off = [] for key in keys_odor_off: trajec = dataset.trajecs[key] if trajec.residency_time is not None: residency_time_odor_off.append(trajec.residency_time) # odor on, odor experienced keys_odor_on_true = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=10, threshold_distance=-1, odor_stimulus='on', upwind_only=True, threshold_distance_min=0.1, odor=True, post_behavior='landing') residency_time_odor_on_true = [] for key in keys_odor_on_true: trajec = dataset.trajecs[key] if trajec.residency_time is not None: residency_time_odor_on_true.append(trajec.residency_time) # odor on, odor not experienced keys_odor_on_false = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=10, threshold_distance=-1, odor_stimulus='on', upwind_only=False, threshold_distance_min=0.1, odor=False, post_behavior='landing') residency_time_odor_on_false = [] for key in keys_odor_on_false: trajec = dataset.trajecs[key] if trajec.residency_time is not None: residency_time_odor_on_false.append(trajec.residency_time) data = [np.array(residency_time_odor_off), np.array(residency_time_odor_on_true), np.array(residency_time_odor_on_false)] colors = ['black', 'red', 'blue'] nbins = 30 # note: if show_smoothed=True with default butter filter, nbins needs to be > ~15 fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, data, bins=nbins, bin_width_ratio=0.8, colors=colors, edgecolor='none', bar_alpha=1, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, bootstrap_std=False, exponential_histogram=False) #xticks = [0,.02,.04,.06,.08,.15] fpl.adjust_spines(ax, ['left', 'bottom']) #ax.set_xlim(xticks[0], xticks[-1]) ax.set_xlabel('residency time, frames') ax.set_ylabel('Occurences, normalized') ax.set_title('Residency time') if save_figure_path == '': save_figure_path = os.path.join(config.path, config.figure_path, 'activity/') fig.set_size_inches(8,8) figname = save_figure_path + 'residency_time_on_post_histogram' + '.pdf' fig.savefig(figname, format='pdf')
def plot_distance_histogram(config, dataset, save_figure_path=''): # no odor keys_no_odor = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=10, odor_stimulus='none', threshold_distance_min=0.1, odor=True) data_no_odor = [] for key in keys_no_odor: trajec = dataset.trajecs[key] if np.max(trajec.distance_to_post) > 0.1: for f, d in enumerate(trajec.distance_to_post): if trajec.positions[f,0] > 0: data_no_odor.append(d) # odor on, odor experienced keys_odor_on_true = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=10, odor_stimulus='on', threshold_distance_min=0.1, odor=True) data_odor_on_true = [] for key in keys_odor_on_true: trajec = dataset.trajecs[key] if np.max(trajec.distance_to_post) > 0.1: for f, d in enumerate(trajec.distance_to_post): if trajec.positions[f,0] > 0: data_odor_on_true.append(d) print len(data_no_odor) print len(data_odor_on_true) data = [np.array(data_no_odor), np.array(data_odor_on_true)] colors = ['black', 'red'] nbins = 30 bins = np.linspace(0,0.1,nbins) fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, data, bins=bins, bin_width_ratio=0.8, colors=colors, edgecolor='none', bar_alpha=1, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, bootstrap_std=True, exponential_histogram=False, n_bootstrap_samples=10000, smoothing_range=[0.005,0.1]) xticks = [0,.02,.04,.06,.08,.1] fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_xlim(xticks[0], xticks[-1]) ax.set_xlabel('Distance to post, m') ax.set_ylabel('Occurences, normalized') title_text = 'Distance to post. red (upwind, odor) N = ' + str(len(keys_odor_on_true)) + '; black (upwind, no odor) N = ' + str(len(keys_no_odor)) ax.set_title(title_text) if save_figure_path == '': save_figure_path = os.path.join(config.path, config.figure_path, 'activity/') fig.set_size_inches(8,8) figname = save_figure_path + 'distance_to_post_histogram' + '.pdf' fig.savefig(figname, format='pdf')
def plot_activity_histogram(dataset, save_figure_path=''): keys = get_keys(dataset) print 'number of keys: ', len(keys) if len(keys) < 1: print 'No data' return odor_local_time = [] no_odor_local_time = [] for i, key in enumerate(keys): trajec = dataset.trajecs[key] if trajec.odor is not False: odor_local_time.append( trajec.timestamp_local_float ) else: no_odor_local_time.append( trajec.timestamp_local_float ) odor_local_time = np.array(odor_local_time) no_odor_local_time = np.array(no_odor_local_time) fig = plt.figure() ax = fig.add_subplot(111) nbins = 24 # note: if show_smoothed=True with default butter filter, nbins needs to be > ~15 bins = np.linspace(0,24,nbins) data = [] colors = [] if len(odor_local_time) > 0: data.append(odor_local_time) colors.append('red') if len(no_odor_local_time) > 0: data.append(no_odor_local_time) colors.append('blue') fpl.histogram(ax, data, bins=bins, bin_width_ratio=0.8, colors=colors, edgecolor='none', bar_alpha=1, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=False, normed_occurences=False, bootstrap_std=False, exponential_histogram=False) xticks = np.linspace(bins[0], bins[-1], 5, endpoint=True) fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_xlabel('Time of day, hours') ax.set_ylabel('Occurences, normalized') ax.set_title('Activity, as measured by number of trajectories: odor=red, no odor=blue') fig.set_size_inches(8,8) figname = save_figure_path + 'activity_histogram' + '.pdf' fig.savefig(figname, format='pdf')
def plot_slipangles(dataset, config, visual_stimulus='none', odor_stimulus='on', odor=True): orientations, airheadings, groundheadings, eccentricities, speeds, airspeeds = get_orientation_data(dataset, config, visual_stimulus='none', odor_stimulus=odor_stimulus, odor=odor, eccentricity_threshold=0.8) airslip = airheadings - orientations groundslip = groundheadings - orientations data = {'airslip': airslip, 'groundslip': groundslip} #data = {'orientation': orientations-airheadings, 'airheadings': orientations-groundheadings, 'groundheadings': groundheadings} color = {'airslip': 'green', 'groundslip': 'red'} savename = 'slipangle_histogram.pdf' fig = plt.figure(figsize=(5,4)) ax = fig.add_subplot(111) bins = np.linspace(-np.pi,np.pi,50) fpl.histogram(ax, data.values(), bins=bins, bin_width_ratio=1, colors=color.values(), edgecolor='none', bar_alpha=1, curve_fill_alpha=0.2, curve_line_alpha=1, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, smoothing_bins_to_exclude=[]) xticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi] ax.set_xlim(xticks[0], xticks[-1]) fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_xlabel('slip angle') xticklabels = ['-180', '-90', '0', '90', '180'] ax.set_xticklabels(xticklabels) ax.set_ylabel('occurences, normalized') path = config.path figure_path = os.path.join(config.path, config.figure_path) save_figure_path=os.path.join(figure_path, 'odor_traces/') figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') fig_name_with_path = os.path.join(save_figure_path, savename) print 'SAVING TO: ', fig_name_with_path fig.savefig(fig_name_with_path, format='pdf')
def make_histograms(config, data, colors, axis, savename='histogram.pdf'): for key, item in data.items(): print key, len(item) fig = plt.figure(figsize=(5,4)) ax = fig.add_subplot(111) if axis=='z': bins = np.linspace(-0.5,0.5,50,endpoint=True) bins_to_exclude = [24] elif axis=='xy': bins = np.linspace(0.05,1,50,endpoint=True) bins_to_exclude = [] fpl.histogram(ax, data.values(), bins=bins, bin_width_ratio=1, colors=colors.values(), edgecolor='none', bar_alpha=1, curve_fill_alpha=0.2, curve_line_alpha=1, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, smoothing_bins_to_exclude=bins_to_exclude) if axis=='z': xticks = [-0.5, -.25, 0, .25, .5] elif axis == 'xy': xticks = [0,.2,.4,.6,.8,1.] fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) #ax.set_xticklabels(xticklabels) ax.set_xlabel('speed in ' + axis) ax.set_ylabel('occurences, normalized') ax.set_xlim(xticks[0], xticks[-1]) path = config.path figure_path = os.path.join(config.path, config.figure_path) save_figure_path=os.path.join(figure_path, 'odor_traces/') figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') fig_name_with_path = os.path.join(save_figure_path, savename) print 'SAVING TO: ', fig_name_with_path fig.savefig(fig_name_with_path, format='pdf')
def plot_digits_distribution(n): fig = plt.figure() ax = fig.add_subplot(111) bins = np.arange(-.5,10.5,1) npages = [30,60,400,1500] colors = ['black', 'blue', 'green', 'red'] digits = [] for npage in npages: d = get_digits(n, npage) digits.append(np.array(d)) xticks = [0,1,2,3,4,5,6,7,8,9] fpl.histogram(ax, digits, bins=bins, colors=colors, normed=True, show_smoothed=False) fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_ylim(0,0.15) ax.set_xlim(-1,10) ax.set_xlabel('digit') ax.set_ylabel('probability')
print 'control odor on: ', len(keys_ok) time_to_saccade_odor_on_false = get_time_to_saccade(dataset, keys_ok, threshold_odor=0.001) data = [np.array(time_to_saccade_odor_off), np.array(time_to_saccade_odor_on_true)] print [len(d) for d in data] colors = ['black', 'red'] nbins = 25 # note: if show_smoothed=True with default butter filter, nbins needs to be > ~15 bins = np.linspace(0,1,nbins) fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, data, bins=bins, bin_width_ratio=0.8, colors=colors, edgecolor='none', bar_alpha=1, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False, bootstrap_std=True, exponential_histogram=False) xticks = [0,0.2,0.4,0.5, 1.] fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) ax.set_xlim(xticks[0], xticks[-1]) ax.set_xlabel('Time to saccade after leaving odor, secs') ax.set_ylabel('Occurences, normalized') ax.set_title('Time to saccade') if save_figure_path == '': save_figure_path = os.path.join(config.path, config.figure_path, 'activity/') fig.set_size_inches(8,8) figname = save_figure_path + 'time_to_saccade_histogram' + '.pdf' fig.savefig(figname, format='pdf')
for h in heading_smooth_real: if h < 0: heading_flipped_real.append(h+np.pi) else: heading_flipped_real.append(h-np.pi) heading_flipped_real = np.array(heading_flipped_real) data = [heading_flipped_real, heading_flipped_drift_downwind, heading_flipped_drift_upwind] fig = plt.figure(figsize=(5,4)) ax = fig.add_subplot(111) bins = 100 fpl.histogram(ax, data, bins=bins, bin_width_ratio=1, colors=['black', 'green', 'red'], edgecolor='none', bar_alpha=1, curve_fill_alpha=0.2, curve_line_alpha=1, curve_butter_filter=[3,0.3], return_vals=False, show_smoothed=True, normed=True, normed_occurences=False) xticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi] fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks) xticklabels = ['-180', '-90', 'upwind', '90', '180'] ax.set_xticklabels(xticklabels) ax.set_xlabel('heading') ax.set_ylabel('occurences, normalized') path = config.path figure_path = os.path.join(config.path, config.figure_path) save_figure_path=os.path.join(figure_path, 'odor_traces/') figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') fig_name_with_path = os.path.join(save_figure_path, 'heading_histogram_drifting.pdf')
def calc_statistical_significance_through_resampling_nested( data1, data2, iterations=1000, analysis='median', pval_for_power_calc=0.05, levels=2): ''' two tailed only ''' assert levels == 2, "levels must be 2" measured_difference = get_meandian_from_nested_data( data1, levels, analysis) - get_meandian_from_nested_data( data2, levels, analysis) data_mixture = [] data_mixture.extend(data1) data_mixture.extend(data2) resampled_differences = [] for i in range(iterations): sample_data1 = get_nested_resampling(data_mixture, len(data1)) sample_data2 = get_nested_resampling(data_mixture, len(data2)) d = get_meandian_from_nested_data( sample_data1, levels, analysis) - get_meandian_from_nested_data( sample_data2, levels, analysis) resampled_differences.append(d) resampled_differences.sort() index = np.argmin(np.abs(resampled_differences - measured_difference)) raw_pval = index / float(len(resampled_differences)) pval = 1 - 2 * np.abs(raw_pval - .5) resampled_data1_differences = [] for i in range(iterations): sample_data1 = get_nested_resampling(data_mixture, len(data_mixture)) sample_data2 = get_nested_resampling(data1, len(data1)) d = get_meandian_from_nested_data( sample_data1, levels, analysis) - get_meandian_from_nested_data( sample_data2, levels, analysis) resampled_data1_differences.append(d) resampled_data1_differences.sort() resampled_data2_differences = [] for i in range(iterations): sample_data1 = get_nested_resampling(data_mixture, len(data_mixture)) sample_data2 = get_nested_resampling(data2, len(data2)) d = get_meandian_from_nested_data( sample_data1, levels, analysis) - get_meandian_from_nested_data( sample_data2, levels, analysis) resampled_data2_differences.append(d) resampled_data2_differences.sort() i_p_lo = resampled_differences[int(pval_for_power_calc / 2. * len(resampled_differences))] i_p_hi = resampled_differences[1 - int(pval_for_power_calc / 2. * len(resampled_differences))] data1_indices_above_p_hi = len( np.where(resampled_data1_differences > i_p_hi)[0]) data1_indices_below_p_lo = len( np.where(resampled_data1_differences < i_p_lo)[0]) data1_power = (data1_indices_above_p_hi + data1_indices_below_p_lo) / float( len(resampled_data1_differences)) data2_indices_above_p_hi = len( np.where(resampled_data2_differences > i_p_hi)[0]) data2_indices_below_p_lo = len( np.where(resampled_data2_differences < i_p_lo)[0]) data2_power = (data2_indices_above_p_hi + data2_indices_below_p_lo) / float( len(resampled_data2_differences)) fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, [ resampled_differences, resampled_data1_differences, resampled_data2_differences ], bins=20, bin_width_ratio=0.6, colors=['black', 'red', 'green'], edgecolor='none', bar_alpha=0.7, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3, 0.3], return_vals=False, show_smoothed=False, normed=True, peak_trace_alpha=0, show_peak_curve=True) return pval, data1_power, data2_power
def plot_cast_surge(cast_speeds, surge_speeds): fig = plt.figure() ax = fig.add_subplot(111) fpl.histogram(ax, [np.array(cast_speeds),np.array(surge_speeds)], bins=50, colors=['red','green'], normed=False)
def analyze_statistical_exploration(): ndatapoints = [5, 10, 20, 50, 100, 200, 500, 1000, 10000] medians = [] stdevs = [] for n in ndatapoints: stats = explore_statistical_measures_across_repetitions(iterations=20, ndatapoints=n) medians.append(np.mean(stats, axis=0)) stdevs.append(np.std(stats, axis=0)) medians = np.array(medians) stdevs = np.array(stdevs) fig = plt.figure() ax = fig.add_subplot(111) ax.semilogx() ax.plot(ndatapoints, medians[:, 0], color='black', linewidth=4) ax.vlines(ndatapoints, medians[:, 0] - stdevs[:, 0], medians[:, 0] + stdevs[:, 0], color='black', linewidth=2) ax.plot(np.array(ndatapoints) + 0.1 * np.array(ndatapoints), medians[:, 1], color='red', linewidth=4) ax.vlines(np.array(ndatapoints) + 0.1 * np.array(ndatapoints), medians[:, 1] - stdevs[:, 1], medians[:, 1] + stdevs[:, 1], color='red', linewidth=2) ax.plot(np.array(ndatapoints) - 0.1 * np.array(ndatapoints), medians[:, 2], color='green', linewidth=4) ax.vlines(np.array(ndatapoints) - 0.1 * np.array(ndatapoints), medians[:, 2] - stdevs[:, 2], medians[:, 2] + stdevs[:, 2], color='green', linewidth=2) ax.set_xlim(0, 1000) fpl.adjust_spines(ax, ['left', 'bottom']) ax.set_xlabel('number of data points') ax.set_ylabel('statistical measure') fig.savefig('stats.pdf', format='pdf') fig = plt.figure(figsize=(10, 8)) bins = np.linspace(0, 30, 30) for i, n in enumerate(ndatapoints): ax = fig.add_subplot(1, len(ndatapoints), i + 1) data1, data2 = get_two_datasets(n) fpl.histogram(ax, [data1, data2], bins=bins, colors=['blue', 'orange'], show_smoothed=False, normed=True, bin_width_ratio=0.9) ax.set_xlim(bins[0], bins[-1]) fpl.adjust_spines(ax, ['bottom'], xticks=[0, 30]) fig.savefig('distributions.pdf', format='pdf')
def calc_statistical_significance_through_resampling(data1, data2, iterations=1000, analysis='median', pval_for_power_calc=0.05, ax=None): ''' two tailed only ''' if type(data1) is not list: data1 = data1.tolist() if type(data2) is not list: data2 = data2.tolist() if analysis == 'median': measured_difference = np.median(data1) - np.median(data2) elif analysis == 'mean': measured_difference = np.mean(data1) - np.mean(data2) data_mixture = [] data_mixture.extend(data1) data_mixture.extend(data2) data_mixture = np.array(data_mixture) resampled_differences = [] for i in range(iterations): indices1 = np.random.randint(0, len(data_mixture), len(data1)) indices2 = np.random.randint(0, len(data_mixture), len(data2)) sample_data1 = data_mixture[indices1] sample_data2 = data_mixture[indices2] if analysis == 'median': median1 = np.median(sample_data1) median2 = np.median(sample_data2) resampled_differences.append(median1 - median2) elif analysis == 'mean': mean1 = np.mean(sample_data1) mean2 = np.mean(sample_data2) resampled_differences.append(mean1 - mean2) resampled_differences.sort() index = np.argmin(np.abs(resampled_differences - measured_difference)) raw_pval = index / float(len(resampled_differences)) pval = 1 - 2 * np.abs(raw_pval - .5) resampled_data1_differences = [] for i in range(iterations): indices1 = np.random.randint(0, len(data_mixture), len(data_mixture)) indices2 = np.random.randint(0, len(data1), len(data1)) sample_data1 = data_mixture[indices1] sample_data2 = np.array(data1)[indices2] if analysis == 'median': median1 = np.median(sample_data1) median2 = np.median(sample_data2) resampled_data1_differences.append(median1 - median2) elif analysis == 'mean': mean1 = np.mean(sample_data1) mean2 = np.mean(sample_data2) resampled_data1_differences.append(mean1 - mean2) resampled_data2_differences = [] for i in range(iterations): indices1 = np.random.randint(0, len(data_mixture), len(data_mixture)) indices2 = np.random.randint(0, len(data2), len(data2)) sample_data1 = data_mixture[indices1] sample_data2 = np.array(data2)[indices2] if analysis == 'median': median1 = np.median(sample_data1) median2 = np.median(sample_data2) resampled_data2_differences.append(median1 - median2) elif analysis == 'mean': mean1 = np.mean(sample_data1) mean2 = np.mean(sample_data2) resampled_data2_differences.append(mean1 - mean2) i_p_lo = resampled_differences[int(pval_for_power_calc / 2. * len(resampled_differences))] i_p_hi = resampled_differences[1 - int(pval_for_power_calc / 2. * len(resampled_differences))] data1_indices_above_p_hi = len( np.where(resampled_data1_differences > i_p_hi)[0]) data1_indices_below_p_lo = len( np.where(resampled_data1_differences < i_p_lo)[0]) data1_power = (data1_indices_above_p_hi + data1_indices_below_p_lo) / float( len(resampled_data1_differences)) data2_indices_above_p_hi = len( np.where(resampled_data2_differences > i_p_hi)[0]) data2_indices_below_p_lo = len( np.where(resampled_data2_differences < i_p_lo)[0]) data2_power = (data2_indices_above_p_hi + data2_indices_below_p_lo) / float( len(resampled_data2_differences)) if ax is not None: fpl.histogram(ax, [ resampled_differences, resampled_data1_differences, resampled_data2_differences ], bins=20, bin_width_ratio=0.6, colors=['black', 'red', 'blue'], edgecolor='none', bar_alpha=0.7, curve_fill_alpha=0.4, curve_line_alpha=0, curve_butter_filter=[3, 0.3], return_vals=False, show_smoothed=False, normed=True, peak_trace_alpha=0, show_peak_curve=True) return pval, data1_power, data2_power
''' mean_accels_in_odor.extend((np.diff(trajec.speed[frames_in_odor])*trajec.fps).tolist()) mean_accels_not_in_odor.extend((np.diff(trajec.speed[frames_not_in_odor])*trajec.fps).tolist()) data_in_odor.append(np.array(mean_accels_in_odor)) data_not_in_odor.append(np.array(mean_accels_not_in_odor)) print odor_stimulus, ': ', np.mean(mean_accels), ' +/- ', np.std(mean_accels) # in odor fig = plt.figure(figsize=(4,2)) ax = fig.add_subplot(111) nbins = 75 bins = np.linspace(-.05,.05,nbins)*100 fpl.histogram(ax, data_in_odor, bins=bins, bin_width_ratio=0.8, colors=['black', 'red'], edgecolor='none', normed=True, show_smoothed=True, bar_alpha=1, curve_line_alpha=0) ax.set_xlim(bins[0], bins[-1]) fpl.adjust_spines(ax, ['left', 'bottom']) ax.set_xlabel('Acceleration, m/s2') ax.set_ylabel('Occurences, normalized') save_figure_path = os.path.join(config.path, config.figure_path, 'activity/') figname = save_figure_path + 'accceleration_histogram_in_odor' + '.pdf' fig.savefig(figname, format='pdf') # not in odor fig = plt.figure(figsize=(4,2)) ax = fig.add_subplot(111) nbins = 75 bins = np.linspace(-.05,.05,nbins)*100 fpl.histogram(ax, data_not_in_odor, bins=bins, bin_width_ratio=0.8, colors=['black', 'blue'], edgecolor='none', normed=True, show_smoothed=True, bar_alpha=1, curve_line_alpha=0)
import pickle import fly_plot_lib.plot as fpl import fly_plot_lib.text as flytext import matplotlib.pyplot as plt import numpy as np if __name__ == '__main__': f = open('sim_results.pickle') results = pickle.load(f) f.close() fig = plt.figure(figsize=(3.3,2)) ax = fig.add_axes([0.05,0.25,0.9,0.65]) print len(results) colors = ['black', 'orange', 'purple'] fpl.histogram(ax, results, colors=colors[0:len(results)], bins=20, normed=True, show_smoothed=False, bar_alpha=1, bin_width_ratio=1) xticks = np.linspace(0,20000,11) xticklabels = [str(int(tick/1000.)) for tick in xticks] fpl.adjust_spines(ax, ['bottom'], xticks=xticks) ax.set_xticklabels(xticklabels) ax.set_xlabel('Time to localization, sec') flytext.set_fontsize(fig, 8) fig.savefig('results_plot.pdf', format='pdf')