def run_mother_machine(time=5, out_dir='out'): mother_machine_config = get_mother_machine_config() experiment = mother_machine_experiment(mother_machine_config) # simulate settings = { 'emit_step': 5, 'total_time': time, 'return_raw_data': True} data = simulate_experiment(experiment, settings) # agents plot plot_settings = { 'agents_key': 'agents'} plot_agents_multigen(data, plot_settings, out_dir) # snapshot plot multibody_config = mother_machine_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()} snapshot_data = { 'agents': agents, 'fields': fields, 'config': multibody_config} plot_config = { 'out_dir': out_dir, 'filename': 'snapshots'} plot_snapshots(snapshot_data, plot_config)
def inclusion_plots_suite(data=None, out_dir=EXPERIMENT_OUT_DIR): n_snapshots = 5 tagged_molecules = [('inclusion_body', ), ( 'front', 'aggregate', ), ( 'back', 'aggregate', )] # multigen plot plot_settings = {} plot_agents_multigen(data, plot_settings, out_dir) # extract data for snapshots bounds = LATTICE_CONFIG['multibody']['bounds'] agents, fields = format_snapshot_data(data) # snapshots plot plot_snapshots(bounds=bounds, agents=agents, fields=fields, n_snapshots=n_snapshots, out_dir=out_dir, filename='inclusion_snapshots') # tags plot plot_tags( data=data, bounds=bounds, tagged_molecules=tagged_molecules, n_snapshots=n_snapshots, convert_to_concs=False, out_dir=out_dir, )
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_timeseries(data, out_dir, settings): plot_settings = { 'agents_key': 'agents', 'title_size': 10, 'tick_label_size': 10, } plot_settings.update(settings) plot_agents_multigen(data, plot_settings, out_dir)
def run_mother_machine(time=10, out_dir='out'): config = get_mother_machine_config() # configure the experiment agent_ids = config.get('agent_ids', ['0']) # get the environment composite environment = Lattice(config.get('environment', {})) composite = environment.generate({}) # add the agents growth_division = GrowDivide(config.get('growth_division', {})) for agent_id in agent_ids: agent = growth_division.generate({'agent_id': agent_id}) composite.merge(composite=agent, path=('agents', agent_id)) experiment = Engine( **{ 'processes': composite['processes'], 'topology': composite['topology'], 'initial_state': config.get('initial_state', {}), 'progress_bar': True, }) # simulate settings = {'total_time': time, 'return_raw_data': True} data = simulate_experiment(experiment, settings) # agents plot plot_settings = {'agents_key': 'agents'} plot_agents_multigen(data, plot_settings, out_dir) # snapshot plot agents, fields = format_snapshot_data(data) bounds = config['environment']['multibody']['bounds'] plot_snapshots(bounds, agents=agents, fields=fields, n_snapshots=4, out_dir=out_dir, filename=f"mother_machine") # make snapshot video make_video( data, bounds, plot_type='fields', step=100, out_dir=out_dir, filename=f"mother_machine", )
def plot_experiment_output( data, plot_settings={}, out_dir='out', ): environment_config = plot_settings['environment_config'] agent_type = plot_settings.get('agent_type', 'agent') plot_types = plot_settings['plot_types'] # extract data multibody_config = environment_config['config']['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()} # pass to plots if 'agents' in plot_types: plot_settings = plot_types['agents'] plot_settings['agents_key'] = 'agents' plot_agents_multigen(data, plot_settings, out_dir, agent_type) if 'snapshots' in plot_types: plot_config = plot_types['snapshots'] field_ids = plot_types['snapshots']['fields'] plot_fields = { time: { field_id: field_instance[field_id] for field_id in field_ids} for time, field_instance in fields.items()} data = { 'agents': agents, 'fields': plot_fields, 'config': multibody_config} plot_config.update({ 'out_dir': out_dir, 'filename': agent_type + '_snapshots', }) plot_snapshots(data, plot_config) if 'tags' in plot_types: plot_config = plot_types['tags'] data = { 'agents': agents, 'config': multibody_config} plot_config.update({ 'out_dir': out_dir, 'filename': agent_type + '_tags', }) plot_tags(data, plot_config)
def plot_multigen(output, variables=None, out_dir=None, filename=None, **kwargs): if filename and not out_dir: out_dir = 'out' plot_settings = { 'include_paths': variables, 'skip_paths': [ ('internal_counts', ), ('cobra_external', ), ], 'remove_zeros': False, 'column_width': 8, 'row_height': 1.5, 'title_on_y_axis': True, 'stack_column': True, 'tick_label_size': 10, 'title_size': 10, **kwargs } fig = plot_agents_multigen(output, plot_settings, out_dir, filename) return fig
def plot_timeseries(t_index): time_indices = np.array(range(0, t_index + 1)) current_data = { time_vec[index]: agent_data[time_vec[index]] for index in time_indices } fig = plot_agents_multigen(current_data, dict(plot_settings, **kwargs)) return fig
def main(): out_dir = os.path.join(COMPOSITE_OUT_DIR, NAME) if not os.path.exists(out_dir): os.makedirs(out_dir) grow_divide = False grow_divide_exchange = True if grow_divide: output = test_grow_divide(2000) plot_settings = {} plot_agents_multigen(output, plot_settings, out_dir, 'grow_divide') if grow_divide_exchange: output = test_grow_divide_exchange(2000) plot_settings = {} plot_agents_multigen(output, plot_settings, out_dir, 'grow_divide_exchange')
def inclusion_plots_suite(data=None, out_dir=EXPERIMENT_OUT_DIR): n_snapshots = 8 tagged_molecules = [ ('inclusion_body', ), ( 'front', 'aggregate', ), ( 'back', 'aggregate', ), ] # multigen plot plot_settings = {} plot_agents_multigen(data, plot_settings, out_dir) # extract data for snapshots multibody_config = lattice_config['multibody'] agents = {time: time_data['agents'] for time, time_data in data.items()} # snapshots plot plot_data = { 'agents': agents, 'config': multibody_config, } plot_config = {'n_snapshots': n_snapshots, 'out_dir': out_dir} plot_snapshots(plot_data, plot_config) # tags plot plot_config = { 'tagged_molecules': tagged_molecules, 'n_snapshots': n_snapshots, 'convert_to_concs': False, 'out_dir': out_dir } plot_tags(plot_data, plot_config)
def plot_multigen_fig(output, agent_colors=None, out_dir='out'): """ plot multi-generational timeseries over the entire simulation """ plot_config = copy.deepcopy(MULTIGEN_PLOT_CONFIG) plot_config['agent_colors'] = agent_colors # plot multigen multigen_fig = plot_agents_multigen(output, plot_config) # add colony mass to multigen_fig colony_mass, time_vec = calculate_colony_mass(output) # convert to hours time_vec = [time / 3600 for time in time_vec] # get mass axis to replace with colony mass allaxes = multigen_fig.get_axes() ax = None for axis in allaxes: if axis.get_title() == 'boundary \nmass': ax = axis # replace with colony mass ax.clear() set_axes(ax, True, sci_notation=MULTIGEN_PLOT_CONFIG['sci_notation']) ax.plot(time_vec, colony_mass, linewidth=MULTIGEN_PLOT_CONFIG['linewidth'], color='darkslategray') ax.set_xlim([time_vec[0], time_vec[-1]]) ax.set_title('total colony mass (fg)', rotation=0, fontsize=MULTIGEN_PLOT_CONFIG['title_size']) ax.set_xlabel('time (hr)') ax.spines['bottom'].set_position(('axes', -0.2)) # save save_fig_to_dir(multigen_fig, 'spatial_multigen.pdf', out_dir)
def run_compartment(out_dir='out'): data = test_inclusion_body(total_time=4000) plot_settings = {} plot_agents_multigen(data, plot_settings, out_dir)
if not os.path.exists(out_dir): os.makedirs(out_dir) agent_id = '0' compartment = GrowthDivision({'agent_id': agent_id}) # settings for simulation and plot settings = { 'environment': { 'volume': 1e-6 * units.L, # L 'ports': { 'fields': ('fields', ), 'external': ( 'boundary', 'external', ), 'global': ('boundary', ), 'dimensions': ('dimensions', ), }, }, 'outer_path': ('agents', agent_id), # TODO -- need to set the agent_id through here? 'return_raw_data': True, 'timestep': 1, 'total_time': 500 } output_data = simulate_compartment_in_experiment(compartment, settings) plot_settings = {} plot_agents_multigen(output_data, plot_settings, out_dir)