Ejemplo n.º 1
0
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')
Ejemplo n.º 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)
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'))
Ejemplo n.º 4
0
def run_lattice_experiment(agent_config=get_gd_minimal_config,
                           filename='agents'):
    n_agents = 1

    experiment_config = get_lattice_config()
    experiment_config['n_agents'] = n_agents
    experiment_config['agent'] = agent_config()
    experiment = lattice_experiment(experiment_config)

    # simulate
    settings = {'timestep': 1, 'total_time': 200, 'return_raw_data': True}
    data = simulate_experiment(experiment, settings)

    # 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
    plot_settings = {'agents_key': 'agents'}
    plot_agents_multigen(data, plot_settings, out_dir, filename)

    # snapshot plot
    data = {'agents': agents, 'fields': fields, 'config': multibody_config}
    plot_config = {'out_dir': out_dir, 'filename': filename + '_snapshots'}
    plot_snapshots(data, plot_config)
Ejemplo n.º 5
0
 def plot_timeseries(self, data, out_dir):
     plot_settings = {
         'agents_key': 'agents',
         'title_size': 10,
         'tick_label_size': 10,
     }
     plot_settings.update(self.timeseries_config)
     plot_agents_multigen(data, plot_settings, out_dir)
Ejemplo n.º 6
0
def plot(args):
    if args.atlas:
        client = get_atlas_client(SECRETS_PATH)
    else:
        client = get_local_client(args.port, args.database_name)
    data, environment_config = data_from_database(args.experiment_id, client)
    del data[0]

    out_dir = os.path.join(OUT_DIR, args.experiment_id)
    if os.path.exists(out_dir):
        if not args.force:
            raise IOError('Directory {} already exists'.format(out_dir))
    else:
        os.makedirs(out_dir)

    if args.snapshots or args.tags:
        agents = {
            time: timepoint['agents']
            for time, timepoint in data.items()
        }
        fields = {
            time: timepoint['fields']
            for time, timepoint in data.items()
        }
        if args.snapshots:
            snapshots_data = {
                'agents': agents,
                'fields': fields,
                'config': environment_config,
            }
            plot_config = {
                'out_dir': out_dir,
            }
            plot_snapshots(snapshots_data, plot_config)
        if args.tags is not None:
            with open(args.tags, 'r') as f:
                reader = csv.reader(f)
                molecules = [(store, molecule) for store, molecule in reader]
            tags_data = {
                'agents': agents,
                'config': environment_config,
            }
            plot_config = {
                'out_dir': out_dir,
                'tagged_molecules': molecules,
            }
            plot_tags(tags_data, plot_config)

    if args.timeseries:
        plot_settings = {
            'agents_key': 'agents',
            'title_size': 10,
            'tick_label_size': 10,
        }
        plot_agents_multigen(data, plot_settings, out_dir)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
    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)