def run_growth_division(config={}):
    n_agents = 1
    agent_ids = [str(agent_id) for agent_id in range(n_agents)]

    bounds = [20, 20]
    settings = {
        'growth_rate': 0.02,
        'growth_rate_noise': 0.02,
        'division_volume': 2.6,
        'total_time': 140
    }

    gd_config = {
        'agent_shape': config.get('agent_shape', 'segment'),
        'animate': True,
        'jitter_force': 1e-3,
        'bounds': bounds
    }
    body_config = {'bounds': bounds, 'agent_ids': agent_ids}
    gd_config['agents'] = agent_body_config(body_config)
    gd_data = simulate_growth_division(gd_config, settings)

    # snapshots plot
    agents = {
        time: time_data['agents']
        for time, time_data in gd_data.items() if bool(time_data)
    }
    data = {'agents': agents, 'config': gd_config}
    plot_config = {'out_dir': out_dir, 'filename': 'growth_division_snapshots'}
    plot_snapshots(data, plot_config)
Exemple #2
0
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)
Exemple #3
0
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'))
Exemple #4
0
 def plot_snapshots(data, environment_config, out_dir, settings):
     snapshots_data = Analyzer.format_data_for_snapshots(
         data, environment_config)
     plot_config = {
         'out_dir': out_dir,
     }
     plot_config.update(settings)
     plot_snapshots(snapshots_data, plot_config)
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)
Exemple #6
0
def main():
    out_dir = os.path.join(COMPARTMENT_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    bounds = [25, 25]
    config = make_lattice_config(bounds=bounds, )
    data = test_lattice(config=config, n_agents=1, end_time=40)

    # make snapshot plot
    agents = {time: time_data['agents'] for time, time_data in data.items()}
    fields = {time: time_data['fields'] for time, time_data in data.items()}
    plot_data = {
        'agents': agents,
        'fields': fields,
        'config': {
            'bounds': bounds
        }
    }
    plot_config = {'out_dir': out_dir, 'filename': 'snapshots'}
    plot_snapshots(plot_data, plot_config)
Exemple #7
0
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)
Exemple #8
0
def plot_fields(data, config, out_dir='out', filename='fields'):
    fields = {time: time_data['fields'] for time, time_data in data.items()}
    snapshots_data = {'fields': fields, 'config': config}
    plot_config = {'out_dir': out_dir, 'filename': filename}
    plot_snapshots(snapshots_data, plot_config)