def plot_odor_plume(config, gm): fig = plt.figure() ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes(fig) # get static plume static_time = 12. gm_static = gm.get_gaussian_model_at_time_t(static_time) # set x axis to be huge gm_static.parameters['mean_0'] = 0 gm_static.parameters['std_0'] = 10000000000000000 #xlim, ylim, resolution, axis=2, axis_slice=0) odor_image_xy, extent_xy = gm_static.get_array_2d_slice([-.2,1], [-.15,.15], .001, axis=2, axis_slice=.04) odor_image_xz, extent_xz = gm_static.get_array_2d_slice([-.2,1], [-.15,.15], .001, axis=1, axis_slice=.01) odor_image_yz, extent_yz = gm_static.get_array_2d_slice([-.15,.15], [-.15,.15], .001, axis=0, axis_slice=0) ax_xy.imshow(odor_image_xy, extent=extent_xy, origin='lower') ax_xz.imshow(odor_image_xz, extent=extent_xz, origin='lower') ax_yz.imshow(odor_image_yz, extent=extent_yz, origin='lower') xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) figure_path = os.path.join(config.path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') pdf_name_with_path = os.path.join(save_figure_path, 'odor_plume_model.pdf') fig.savefig(pdf_name_with_path, format='pdf')
def plot_post_traces(path, config, dataset, keys=None, save=True): if keys is None: keys = dataset.trajecs.keys() ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() for key in keys: trajec = dataset.trajecs[key] if trajec.post_behavior != 'landing': if trajec.odor_stimulus != 'none': if trajec.distance_to_post[-1] < 0.01: print key plot_odor_trace_on_ax(path, config, dataset, keys=[key], axis='xy', ax=ax_xy, show_post=config.post) plot_odor_trace_on_ax(path, config, dataset, keys=[key], axis='xz', ax=ax_xz, show_post=config.post) plot_odor_trace_on_ax(path, config, dataset, keys=[key], axis='yz', ax=ax_yz, show_post=config.post) xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) if save: figname = None figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') if figname is None: figname = save_figure_path + 'trajec_ending_near_post' + '.pdf' else: figname = os.path.join(save_figure_path, figname) plt.savefig(figname, format='pdf')
def plot_all_heatmaps( config, dataset, save_figure_path="", figname=None, keys=None, frames=None, title=None, save=False ): ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() plot_heatmap( config, dataset, axis="xy", save_figure_path="", figname=None, keys=keys, frames=frames, ax=ax_xy, save=False ) plot_heatmap( config, dataset, axis="xz", save_figure_path="", figname=None, keys=keys, frames=frames, ax=ax_xz, save=False ) plot_heatmap( config, dataset, axis="yz", save_figure_path="", figname=None, keys=keys, frames=frames, ax=ax_yz, save=False ) xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) if title is not None: plt.suptitle(title) if save: if figname is None: figname = save_figure_path + "heatmap_" + "all_axes" + ".pdf" else: figname = save_figure_path + figname plt.savefig(figname, format="pdf")
def plot_trace_ends(path, config, dataset, keys=None, show_saccades=False, save=True): if keys is None: keys = dataset.trajecs.keys() ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() if config.post: height = config.post_center[2]-config.ticks['z'][0] post = patches.Circle(config.post_center[0:2], config.post_radius, color='black') ax_xy.add_artist(post) post = patches.Rectangle([config.post_center[0]-1*config.post_radius, config.ticks['z'][0]], config.post_radius*2, height, color='black') ax_xz.add_artist(post) post = patches.Rectangle([config.post_center[1]-1*config.post_radius, config.ticks['z'][0]], config.post_radius*2, height, color='black') ax_yz.add_artist(post) for key in keys: trajec = dataset.trajecs[key] if trajec.post_behavior == 'landing': color = 'green' else: color = 'red' if np.max(trajec.distance_to_post) > 0.05: if trajec.positions[-1][2] < 0.0: ax_xy.plot(trajec.positions[-1][0],trajec.positions[-1][1],'.', color=color, markersize=1, alpha=0.7) if np.abs(trajec.positions[-1][1]) < 0.03: ax_xz.plot(trajec.positions[-1][0],trajec.positions[-1][2],'.', color=color, markersize=1, alpha=0.7) if np.abs(trajec.positions[-1][0]) < 0.05: ax_yz.plot(trajec.positions[-1][1],trajec.positions[-1][2],'.', color=color, markersize=1, alpha=0.7) xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) if save: figname = None figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') if figname is None: figname = save_figure_path + 'trajec_ends' + '.pdf' else: figname = os.path.join(save_figure_path, figname) plt.savefig(figname, format='pdf')
def plot_all_heatmaps(config, dataset, save_figure_path='', figname=None, keys=None, frames=None, title=None, save=False): ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() plot_heatmap(config, dataset, axis='xy', save_figure_path='', figname=None, keys=keys, frames=frames, ax=ax_xy, save=False) plot_heatmap(config, dataset, axis='xz', save_figure_path='', figname=None, keys=keys, frames=frames, ax=ax_xz, save=False) plot_heatmap(config, dataset, axis='yz', save_figure_path='', figname=None, keys=keys, frames=frames, ax=ax_yz, save=False) xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) if title is not None: plt.suptitle(title) if save: if figname is None: figname = save_figure_path + 'heatmap_' + 'all_axes' + '.pdf' else: figname = save_figure_path + figname plt.savefig(figname, format='pdf')
def plot_odor_traces(path, config, dataset, keys=None, show_saccades=False, frames_to_show_before_odor='all', frames_to_show_after_odor='all', save=False, odor_multiplier=1, frameranges=None): ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() plot_odor_trace_on_ax(path, config, dataset, keys=keys, axis='xy', show_saccades=show_saccades, frames_to_show_before_odor=frames_to_show_before_odor, frames_to_show_after_odor=frames_to_show_after_odor, ax=ax_xy, odor_multiplier=odor_multiplier, show_post=config.post, frameranges=frameranges) plot_odor_trace_on_ax(path, config, dataset, keys=keys, axis='xz', show_saccades=show_saccades, frames_to_show_before_odor=frames_to_show_before_odor, frames_to_show_after_odor=frames_to_show_after_odor, ax=ax_xz, odor_multiplier=odor_multiplier, show_post=config.post, frameranges=frameranges) plot_odor_trace_on_ax(path, config, dataset, keys=keys, axis='yz', show_saccades=show_saccades, frames_to_show_before_odor=frames_to_show_before_odor, frames_to_show_after_odor=frames_to_show_after_odor, ax=ax_yz, odor_multiplier=odor_multiplier, show_post=config.post, frameranges=frameranges) xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) if save: figname = None figure_path = os.path.join(path, config.figure_path) save_figure_path = os.path.join(figure_path, 'odor_traces/') if figname is None: figname = save_figure_path + 'odor_trace' + '.pdf' else: figname = os.path.join(save_figure_path, figname) plt.savefig(figname, format='pdf')
def plot_saccade_positions(pp, threshold_odor, path, config, dataset, odor_stimulus, keys=None): ax_xy, ax_xz, ax_yz = xyz_axis_grid.get_axes() if odor_stimulus is 'on': n = 0 for key in keys: if n > 1000: break trajec = dataset.trajecs[key] frames_in_odor = np.where(trajec.odor > threshold_odor)[0] odor_blocks = hf.find_continuous_blocks(frames_in_odor, 5, return_longest_only=False) for block in odor_blocks: if len(block) < 5: continue first_sac = None for sac in trajec.saccades: if trajec.positions[sac[0],0] < -0.1 or trajec.positions[sac[0],0] > 0.9: continue if np.abs(trajec.positions[sac[0],1]) > 0.05: continue if trajec.positions[sac[0],2] > 0.05 or trajec.positions[sac[0],2] < -0.01: continue if sac[0] > block[0]: if first_sac is None: first_sac = sac break if first_sac is not None: sac = first_sac n += 1 f = np.argmax(np.abs(trajec.heading_smooth_diff[sac])) + sac[0] ax_xy.plot(trajec.positions[f,0], trajec.positions[f,1], '.', color='black') ax_xz.plot(trajec.positions[f,0], trajec.positions[f,2], '.', color='black') ax_yz.plot(trajec.positions[f,1], trajec.positions[f,2], '.', color='black') if odor_stimulus is 'none': n = 0 for key in keys: if n > 1000: break trajec = dataset.trajecs[key] for sac in trajec.saccades: if trajec.positions[sac[0],0] < -0.1 or trajec.positions[sac[0],0] > 0.9: continue if np.abs(trajec.positions[sac[0],1]) > 0.05: continue if trajec.positions[sac[0],2] > 0.05 or trajec.positions[sac[0],2] < -0.01: continue n += 1 f = np.argmax(np.abs(trajec.heading_smooth_diff[sac])) + sac[0] ax_xy.plot(trajec.positions[f,0], trajec.positions[f,1], '.', color='black') ax_xz.plot(trajec.positions[f,0], trajec.positions[f,2], '.', color='black') ax_yz.plot(trajec.positions[f,1], trajec.positions[f,2], '.', color='black') xyz_axis_grid.set_spines_and_labels(ax_xy, ax_xz, ax_yz) pp.savefig() plt.close('all')