def plot_chemotaxis_experiment(data, field_config, out_dir): # multigen agents plot plot_settings = { 'agents_key': 'agents', 'max_rows': 30, 'skip_paths': [ ('boundary', 'mass'), ('boundary', 'length'), ('boundary', 'width'), ('boundary', 'location'), ] } plot_agents_multigen(data, plot_settings, out_dir, 'agents') # trajectory and motility agents_timeseries = timeseries_from_data(data) field = make_field(field_config) trajectory_config = { 'bounds': field_config['bounds'], 'field': field, 'rotate_90': True } plot_temporal_trajectory(copy.deepcopy(agents_timeseries), trajectory_config, out_dir, 'temporal') plot_agent_trajectory(agents_timeseries, trajectory_config, out_dir, 'trajectory') try: plot_motility(agents_timeseries, out_dir, 'motility_analysis') except: print('plot_motility failed')
def run_jitter(config={}, out_dir='out', filename='jitter'): total_time = config.get('total_time', 30) timestep = config.get('timestep', 0.05) motility_config = get_baseline_config({ 'animate': False, 'jitter_force': 1e0, 'bounds': [50, 50], 'n_agents': 8, }) # make the process multibody = Multibody(motility_config) experiment = process_in_experiment(multibody) experiment.state.update_subschema(('agents', ), { 'cell': { 'motor_state': { '_value': 0, '_updater': 'set', '_emit': True, } } }) experiment.state.apply_subschemas() time = 0 while time < total_time: experiment.update(timestep) time += timestep data = experiment.emitter.get_data() # make trajectory plot timeseries = timeseries_from_data(data) plot_temporal_trajectory(timeseries, motility_config, out_dir, filename + '_trajectory')
def main(): if not os.path.exists(OUT_DIR): os.makedirs(OUT_DIR) data, experiment_config = run_experiment(start_locations=[[0.3, 0.3], [0.5, 0.5]], ) # extract data multibody_config = experiment_config['environment']['multibody'] agents = {time: time_data['agents'] for time, time_data in data.items()} fields = {time: time_data['fields'] for time, time_data in data.items()} # agents plot agents_settings = {'agents_key': 'agents'} plot_agents_multigen(data, agents_settings, OUT_DIR, 'agents') # snapshot plot snapshot_data = { 'agents': agents, 'fields': fields, 'config': multibody_config, } snapshot_config = { 'out_dir': OUT_DIR, 'filename': 'agents_snapshots', } plot_snapshots(snapshot_data, snapshot_config) # Colony Metrics Plot embedded_ts = timeseries_from_data(data) colony_metrics_ts = embedded_ts['colony_global'] colony_metrics_ts['time'] = embedded_ts['time'] path_ts = path_timeseries_from_embedded_timeseries(colony_metrics_ts) fig = plot_colony_metrics(path_ts) fig.savefig(os.path.join(OUT_DIR, 'colonies'))
def plot_colony_metrics(self, data, out_dir): embedded_ts = timeseries_from_data(data) colony_metrics_ts = embedded_ts['colony_global'] colony_metrics_ts['time'] = embedded_ts['time'] path_ts = path_timeseries_from_embedded_timeseries(colony_metrics_ts) fig = plot_colony_metrics(path_ts) fig.savefig(os.path.join(out_dir, 'colonies'))
def main(): test_experiment() data = run_experiment() agents_plot_settings = { 'agents_key': 'agents', } plot_simulation_output( timeseries_from_data(data), agents_plot_settings, OUT_DIR, 'simulation', )
def run_motility(config={}, out_dir='out', filename='motility'): total_time = config.get('total_time', 30) timestep = config.get('timestep', 0.05) config['initial_location'] = [0.5, 0.5] motility_config = get_baseline_config(config) # simulation settings motility_sim_settings = {'timestep': timestep, 'total_time': total_time} # run motility sim motility_data = simulate_motility(motility_config, motility_sim_settings) motility_timeseries = timeseries_from_data(motility_data) plot_temporal_trajectory(motility_timeseries, motility_config, out_dir, filename + '_trajectory')
def format_data_for_colony_metrics(data): embedded_ts = timeseries_from_data(data) colony_metrics_ts = embedded_ts['colony_global'] colony_metrics_ts['time'] = embedded_ts['time'] path_ts = path_timeseries_from_embedded_timeseries(colony_metrics_ts) return path_ts
def plot_activity(data, out_dir='out', filename='motor_control'): timeseries = timeseries_from_data(data) CheY_vec = timeseries['internal']['CheY'] CheY_P_vec = timeseries['internal']['CheY_P'] cw_bias_vec = timeseries['internal']['cw_bias'] motile_state_vec = timeseries['internal']['motile_state'] thrust_vec = timeseries['boundary']['thrust'] flagella_activity = timeseries.get('flagella', {}) time_vec = timeseries['time'] # make flagella activity grid flagella_ids = list(flagella_activity.keys()) flagella_indexes = {} next_index = 0 activity_grid = np.zeros((len(flagella_ids), len(time_vec))) total_CW = np.zeros((len(time_vec))) for time_index, (time, time_data) in enumerate(data.items()): time_flagella = time_data.get('flagella', {}) for flagella_id, rotation_states in time_flagella.items(): # get flagella_index by order of appearance if flagella_id not in flagella_indexes: flagella_indexes[flagella_id] = next_index next_index += 1 flagella_index = flagella_indexes[flagella_id] modified_rotation_state = 0 CW_rotation_state = 0 if rotation_states == -1: modified_rotation_state = 1 elif rotation_states == 1: modified_rotation_state = 2 CW_rotation_state = 1 activity_grid[flagella_index, time_index] = modified_rotation_state total_CW += np.array(CW_rotation_state) # grid for cell state motile_state_grid = np.zeros((1, len(time_vec))) motile_state_grid[0, :] = motile_state_vec # set up colormaps # cell motile state cmap1 = colors.ListedColormap(['steelblue', 'lightgray', 'darkorange']) bounds1 = [-1, -1/3, 1/3, 1] norm1 = colors.BoundaryNorm(bounds1, cmap1.N) motile_legend_elements = [ Patch(facecolor='steelblue', edgecolor='k', label='Run'), Patch(facecolor='darkorange', edgecolor='k', label='Tumble'), Patch(facecolor='lightgray', edgecolor='k', label='N/A')] # rotational state cmap2 = colors.ListedColormap(['lightgray', 'steelblue', 'darkorange']) bounds2 = [0, 0.5, 1.5, 2] norm2 = colors.BoundaryNorm(bounds2, cmap2.N) rotational_legend_elements = [ Patch(facecolor='steelblue', edgecolor='k', label='CCW'), Patch(facecolor='darkorange', edgecolor='k', label='CW'), Patch(facecolor='lightgray', edgecolor='k', label='N/A')] # plot results cols = 1 rows = 5 plt.figure(figsize=(4 * cols, 1.5 * rows)) # define subplots ax1 = plt.subplot(rows, cols, 1) ax2 = plt.subplot(rows, cols, 2) ax3 = plt.subplot(rows, cols, 3) ax4 = plt.subplot(rows, cols, 4) ax5 = plt.subplot(rows, cols, 5) # plot Che-P state ax1.plot(time_vec, CheY_vec, label='CheY') ax1.plot(time_vec, CheY_P_vec, label='CheY_P') ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5)) ax1.set_xticks([]) ax1.set_xlim(time_vec[0], time_vec[-1]) ax1.set_ylabel('concentration \n (uM)') # plot CW bias ax2.plot(time_vec, cw_bias_vec) ax2.set_xticks([]) ax2.set_xlim(time_vec[0], time_vec[-1]) ax2.set_ylabel('CW bias') # plot flagella states in a grid if len(activity_grid) > 0: ax3.imshow(activity_grid, interpolation='nearest', aspect='auto', cmap=cmap2, norm=norm2, # extent=[-1,1,-1,1] extent=[time_vec[0], time_vec[-1], len(flagella_ids)+0.5, 0.5] ) plt.locator_params(axis='y', nbins=len(flagella_ids)) ax3.set_yticks(list(range(1, len(flagella_ids) + 1))) ax3.set_xticks([]) ax3.set_ylabel('flagella #') # legend ax3.legend( handles=rotational_legend_elements, loc='center left', bbox_to_anchor=(1, 0.5)) else: # no flagella ax3.set_axis_off() # plot cell motile state ax4.imshow(motile_state_grid, interpolation='nearest', aspect='auto', cmap=cmap1, norm=norm1, extent=[time_vec[0], time_vec[-1], 0, 1]) ax4.set_yticks([]) ax4.set_xticks([]) ax4.set_ylabel('cell motile state') # legend ax4.legend( handles=motile_legend_elements, loc='center left', bbox_to_anchor=(1, 0.5)) # plot motor thrust ax5.plot(time_vec, thrust_vec) ax5.set_xlim(time_vec[0], time_vec[-1]) ax5.set_ylabel('total motor thrust (pN)') ax5.set_xlabel('time (sec)') # save figure fig_path = os.path.join(out_dir, filename) plt.subplots_adjust(wspace=0.7, hspace=0.3) plt.savefig(fig_path + '.png', bbox_inches='tight')