Exemplo n.º 1
0
def make_illustration_snapshot():
    fig = plt.figure()
    ax = fig.gca()
    model = vicsek_model_factory(model='angular',
                                 n=200, L=100.0, eta=0.2, v_0=0.5)
    for _ in range(100):
        model.iterate()
    ejm_rcparams.set_pretty_plots(use_latex=True, use_pgf=True)
    ejm_rcparams.prettify_axes(ax)

    ax.set_xlim(-model.L_half, model.L_half)
    ax.set_ylim(-model.L_half, model.L_half)
    ax.set_aspect('equal')

    i_source = np.argmin(np.sum(np.square(model.r), axis=1))
    r_i = model.r[i_source]
    c = plt.Circle(r_i, radius=model.r_v, fill=False, edgecolor='red')
    ax.add_patch(c)
    colors = np.zeros([model.n])
    colors[i_source] = 1.0
    i_neighbs = model._neighbs(i_source)
    for i_neighb in i_neighbs:
        colors[i_neighb] = 0.5

    s = 2.0
    ax.quiver(model.r[:, 0], model.r[:, 1],
              s * model.L * model.u[:, 0], s * model.L * model.u[:, 1],
              colors, pivot='mid', edgecolor='none')
    ax.axis('off')

    plt.savefig('vicsek_snapshot_demo.pdf', bbox_inches='tight',
                transparent=True)
Exemplo n.º 2
0
def plot(dirname_sets_u, dirname_sets_D, cs, labels, ax):
    ejm_rcparams.prettify_axes(ax)

    for dirnames_u, dirnames_D, c, label in zip(dirname_sets_u,
                                                dirname_sets_D, cs, labels):
        pfs, uds, uds_err = utils.pf_uds_x(dirnames_u)
        i_sort = np.argsort(pfs)
        pfs, uds, uds_err = pfs[i_sort], uds[i_sort], uds_err[i_sort]
        pfs, Ds, Ds_err = utils.pf_Ds_scalar(dirnames_D)
        i_sort = np.argsort(pfs)
        pfs, Ds, Ds_err = pfs[i_sort], Ds[i_sort], Ds_err[i_sort]

        uds_norm = uds / u_x_0
        uds_norm_err = uds_err / u_x_0

        Ds_norm = Ds / D_0
        Ds_norm_err = Ds_err / D_0

        ls = Ds_norm / uds_norm
        ls_err = ls * np.sqrt(np.sum(np.square([Ds_norm_err / Ds_norm,
                                                uds_norm_err / uds_norm])))
        ax.errorbar(pfs, ls, yerr=ls_err, label=label, c=c)

    ax.set_xlim(0.0, 1.0)
    ax.set_ylim(0.5, 6.5)
    ax.set_xlabel(r'$\phi$', fontsize=35)
    ax.set_ylabel(r'$l_x$', fontsize=35)
    ax.tick_params(axis='both', labelsize=26, pad=10.0)
Exemplo n.º 3
0
def plot_av_samples(inds, d_avs):
    c = ejm_rcparams.set2(range(len(d_avs)))
    fig = plt.figure()
    for i, d_av in enumerate(d_avs):
        ax = fig.add_subplot(len(d_avs), 1, i + 1)
        ejm_rcparams.prettify_axes(ax)
        ax.plot(d_av, c=c[i])
        if i < len(d_avs) - 1:
            ax.set_xticks([])
        ax.set_yticks([1, 2, 3, 4])
        ax.set_ylim(0.5, 4.5)
    plt.show()
Exemplo n.º 4
0
def plot():
    red_blue_zero = ejm_rcparams.shifted_cmap(ejm_rcparams.red_blue,
                                              midpoint=0.4)
    fig = plt.figure()
    fig.frameon = False
    ax = fig.gca()
    ejm_rcparams.prettify_axes(ax)
    ax.axis('off')

    inds, d = get_data()
    ax.imshow(d - 2, interpolation='nearest', cmap=red_blue_zero)
    ax.axis('off')
    plt.savefig('original.png', bbox_inches='tight', transparency=True)

    ax.cla()
    d = denoise_data(d)
    ax.imshow(d - 2, interpolation='nearest', cmap=red_blue_zero)
    ax.axis('off')
    plt.savefig('denoise.png', bbox_inches='tight', transparency=True)

    ax.cla()
    inds, d = reduce_data(inds, d)
    d = denoise_data(d)
    inds, d = reduce_data(inds, d)
    ax.imshow(d - 2, interpolation='nearest', cmap=red_blue_zero)
    ax.axis('off')
    plt.savefig('reduced.png', bbox_inches='tight', transparency=True)

    ax.cla()
    fit = fit_data(d, k=5)
    labels = fit.labels_
    d_sort, labels_sort = sort_data_by_label(d, labels)
    ax.imshow(d_sort - 2, interpolation='nearest', cmap=red_blue_zero)
    ax.hlines(np.nonzero(np.diff(labels_sort))[0], 0.0, d_sort.shape[1],
              colors=ejm_rcparams.almost_black)
    ax.axis('off')
    plt.savefig('clustered.png', bbox_inches='tight', transparency=True)

    d_avs = get_average_samples(d, labels)
    fig = plt.figure()
    for i, d_av in enumerate(d_avs):
        ax = fig.add_subplot(len(d_avs), 1, i + 1)
        ejm_rcparams.prettify_axes(ax)
        ax.plot(d_av, c=ejm_rcparams.set2[i])
        ax.set_xticks([])
        ax.set_yticks([1, 2, 3, 4])
        ax.set_ylim(0.5, 4.5)
        ax.tick_params(axis='y', labelsize=20)
        sig = signature_sample(inds, d_av)
        print(sig)
    plt.savefig('signatures.png', bbox_inches='tight')
Exemplo n.º 5
0
def plot(dirname_sets, cs, labels, ax):
    ejm_rcparams.prettify_axes(ax)

    for dirnames, c, label in zip(dirname_sets, cs, labels):
        pfs, Ds, Ds_err = utils.pf_Ds_scalar(dirnames)
        i_sort = np.argsort(pfs)
        pfs, Ds, Ds_err = pfs[i_sort], Ds[i_sort], Ds_err[i_sort]
        ax.errorbar(pfs, Ds / Ds[0], yerr=Ds_err / Ds[0], label=label, c=c)

    ax.set_xlim(0.0, 1.0)
    ax.set_ylim(0.0, 1.0)

    ax.set_xlabel(r'$\phi$', fontsize=35)
    ax.set_ylabel(r'$\mathrm{D} / \mathrm{D}_0$', fontsize=35)
    ax.tick_params(axis='both', labelsize=26, pad=10.0)
def plot(dirname_sets, cs, labels, ax):
    ejm_rcparams.prettify_axes(ax)

    for dirnames, c, label in zip(dirname_sets, cs, labels):
        pfs, uds, uds_err = utils.pf_uds_x(dirnames)
        i_sort = np.argsort(pfs)
        pfs, uds, uds_err = pfs[i_sort], uds[i_sort], uds_err[i_sort]
        ax.errorbar(pfs, uds, yerr=uds_err, label=label, c=c)

    ax.set_xlim(0.0, 1.0)
    ax.set_ylim(0.0, 0.21)

    ax.set_xlabel(r'$\phi$', fontsize=35)
    ax.set_ylabel(r'$u_x$', fontsize=35)
    ax.tick_params(axis='both', labelsize=26, pad=10.0)
Exemplo n.º 7
0
def plot_elbow():
    fig = plt.figure()
    fig.frameon = False
    ax = fig.gca()
    ejm_rcparams.prettify_axes(ax)
    inds, d = get_data()
    d = denoise_data(d)
    inds, d = reduce_data(inds, d)
    d = denoise_data(d)
    inds, d = reduce_data(inds, d)
    ks, ss, vs = get_cluster_number_metrics(d)
    ax.plot(ks[:-1], np.diff(vs))
    ax.set_xlabel('Number of clusters', fontsize=24)
    ax.set_ylabel('Change in average in-cluster variance', fontsize=24)
    ax.tick_params(axis='x', labelsize=24)
    ax.set_yticks([])
    plt.savefig('elbow.png', bbox_inches='tight', transparency=True)
def plot(dirname_sets, cs, labels, ax):
    ejm_rcparams.prettify_axes(ax)

    for dirnames, c, label in zip(dirname_sets, cs, labels):
        noise_0_tots, Ds, Ds_err = utils.noise_0_tot_Ds_scalar(dirnames)
        i_sort = np.argsort(noise_0_tots)
        noise_0_tots, Ds, Ds_err = (noise_0_tots[i_sort],
                                    Ds[i_sort], Ds_err[i_sort])
        ax.errorbar(noise_0_tots, Ds, yerr=Ds_err, label=label, c=c)

    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.set_xlim(1e-2, 1e1)
    ax.set_ylim(1.0, 1e5)

    ax.set_xlabel(r'$(\alpha_0, \mathrm{D}_{r,0}) / \si{\per\s}$', fontsize=35)
    ax.set_ylabel(r'$\mathrm{D} / (\si{\um^2\per\s})$', fontsize=35)
    ax.tick_params(axis='both', labelsize=26, pad=10.0)
Exemplo n.º 9
0
def make_disordered_snapshot():
    model = vicsek_model_factory(model='angular',
                                 n=100, L=100.0, eta=0.8, v_0=0.5)
    for _ in range(100):
        model.iterate()

    fig = plt.figure()
    ax = fig.gca()
    ejm_rcparams.set_pretty_plots(use_latex=True, use_pgf=True)
    ejm_rcparams.prettify_axes(ax)
    ax.set_xlim(-model.L_half, model.L_half)
    ax.set_ylim(-model.L_half, model.L_half)
    ax.set_aspect('equal')
    s = 2.0
    ax.quiver(model.r[:, 0], model.r[:, 1],
              s * model.L * model.u[:, 0], s * model.L * model.u[:, 1],
              pivot='mid', edgecolor='none')
    ax.axis('off')

    plt.savefig('vicsek_snapshot_disordered.pdf', bbox_inches='tight',
                transparent=True)
use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_noop = fig.add_subplot(gridspec[0])
ax_op = fig.add_subplot(gridspec[1], sharex=ax_noop, sharey=ax_noop)

ejm_rcparams.prettify_axes(ax_noop, ax_op)


def plot_rdf(ax, dset_path, theta_max):
    dset = dataset.get_dset(dset_path,
                            filter_z_flag=False,
                            theta_max=theta_max)
    vp, vp_err = dset.get_vp()
    R = dset.R
    if use_latex:
        label = (r'$\SI{' + '{:.3g}'.format(R) + r'}{\um}$, ' + r'$\SI{' +
                 '{:.2g}'.format(vp) + r'}{\percent}$')
    else:
        label = (r'$' + '{:.3g}'.format(R) + r'\mu m$, $' +
                 '{:.2g}'.format(vp) + r'\%$')
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_exp = fig.add_subplot(gridspec[0])
ax_sim = fig.add_subplot(gridspec[1], sharex=ax_exp, sharey=ax_exp)

ejm_rcparams.prettify_axes(ax_exp, ax_sim)


def plot_rdf(ax, dset_path):
    dset = dataset.get_dset(dset_path)
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    vp, vp_err = dset.get_vp()
    R = dset.R
    if use_latex:
        label = (r'$\SI{' + '{:.3g}'.format(R) + r'}{\um}$, ' +
                 r'$\SI{' + '{:.2g}'.format(vp) + r'}{\percent}$')
    else:
        label = (r'$' + '{:.3g}'.format(R) + r'\mu m$, $' +
                 '{:.2g}'.format(vp) + r'\%$')
    import numpy as np
    rhos_norm_err[np.isnan(rhos_norm_err)] = 0.0
Exemplo n.º 12
0
use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7
alg = 'mean'

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_exp = fig.add_subplot(gridspec[0])
ax_sim = fig.add_subplot(gridspec[1], sharex=ax_exp, sharey=ax_exp)

ejm_rcparams.prettify_axes(ax_exp, ax_sim)


def plot_rdf(ax, dset_path, i):
    dset = dataset.get_dset(dset_path)
    vp, vp_err = dset.get_vp()
    R = dset.R
    R_peak, R_peak_err = dset.get_R_peak(dr=dr, alg=alg)
    if use_latex:
        label = (r'$\SI{' + '{:.3g}'.format(R) + r'}{\um}$, ' + r'$\SI{' +
                 '{:.2g}'.format(vp) + r'}{\percent}$')
    else:
        label = (r'$' + '{:.3g}'.format(R) + r'\mu m$, $' +
                 '{:.2g}'.format(vp) + r'\%$')
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    rhos_norm_err[np.isnan(rhos_norm_err)] = 0.0
Exemplo n.º 13
0
from ciabatta import ejm_rcparams
from colors import *
from dataset import pickle_load
import numpy as np
import paths

save_flag = True

use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

fig = plt.figure(figsize=(12, 12 * ejm_rcparams.golden_ratio))
ax = fig.add_subplot(111)
ejm_rcparams.prettify_axes(ax)

dr = 0.7


def get_stat(pickle_path, alg):
    superset = pickle_load(pickle_path)
    eta_0, eta_0_err = superset.get_eta_0()
    f_peak, f_peak_err = superset.get_f_peak(alg, dr)
    return eta_0, eta_0_err, f_peak, f_peak_err

eta_0, eta_0_err, f_peak, f_peak_err = get_stat(paths.exp_pickle_path, 'mean')
ax.errorbar(eta_0, f_peak, xerr=eta_0_err, yerr=f_peak_err, ls='none', label=r'Method A', c=color_exp)

eta_0, eta_0_err, f_peak, f_peak_err = get_stat(paths.exp_pickle_path, 'median')
ax.errorbar(eta_0, f_peak, xerr=eta_0_err, yerr=f_peak_err, ls='none', label=r'Method B', c=color_median)
use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_Drc_zero = fig.add_subplot(gridspec[0])
ax_Drc_inf = fig.add_subplot(gridspec[1], sharex=ax_Drc_zero,
                             sharey=ax_Drc_zero)

ejm_rcparams.prettify_axes(ax_Drc_zero, ax_Drc_inf)


def plot_rdf(ax, dset_path):
    dset = dataset.get_dset(dset_path)
    vp, vp_err = dset.get_vp()
    if use_latex:
        label = r'$\phi = \SI{%.2g}{\percent}$' % vp
    else:
        label = r'$\phi = %.2g \%$' % vp
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    rhos_norm_err[np.isnan(rhos_norm_err)] = 0.0
    ax.errorbar(R_edges_norm[:-1], rhos_norm, yerr=rhos_norm_err, label=label)

for dset_path in paths.constant_R_Drc_0_dset_paths:
    plot_rdf(ax_Drc_zero, dset_path)
Exemplo n.º 15
0

for exp in [True, False]:

    if exp:
        fname = 'grid_exp'
        color = color_exp
        dset_paths = paths.grid_exp_dset_paths
    else:
        fname = 'grid_sim'
        color = color_opt
        dset_paths = paths.grid_sim_dset_paths

    fig, axs = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(16, 12))
    axs = axs.flatten()
    ejm_rcparams.prettify_axes(*axs)

    for i, ax in enumerate(axs):
        for dset_path in dset_paths:
            dset = dataset.get_dset(dset_path)
            rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
            vp, vp_err = dset.get_vp()
            R = dset.R
            if use_latex:
                label = (r'$\SI{' + '{:.3g}'.format(R) + r'}{\um}$, ' +
                         r'$\SI{' + '{:.2g}'.format(vp) + r'}{\percent}$')
            else:
                label = (r'$' + '{:.3g}'.format(R) + r'\mu m$, $' +
                         '{:.2g}'.format(vp) + r'\%$')
            ax.errorbar(R_edges_norm[:-1], rhos_norm, yerr=rhos_norm_err,
                        label=label, color=color)
Exemplo n.º 16
0
dr = 0.7

for exp in [True, False]:

    if exp:
        fname = 'grid_exp'
        color = color_exp
        dset_paths = paths.grid_exp_dset_paths
    else:
        fname = 'grid_sim'
        color = color_opt
        dset_paths = paths.grid_sim_dset_paths

    fig, axs = plt.subplots(3, 3, sharex=True, sharey=True, figsize=(16, 12))
    axs = axs.flatten()
    ejm_rcparams.prettify_axes(*axs)

    for i, ax in enumerate(axs):
        for dset_path in dset_paths:
            dset = dataset.get_dset(dset_path)
            rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
            vp, vp_err = dset.get_vp()
            R = dset.R
            if use_latex:
                label = (r'$\SI{' + '{:.3g}'.format(R) + r'}{\um}$, ' +
                         r'$\SI{' + '{:.2g}'.format(vp) + r'}{\percent}$')
            else:
                label = (r'$' + '{:.3g}'.format(R) + r'\mu m$, $' +
                         '{:.2g}'.format(vp) + r'\%$')
            ax.errorbar(R_edges_norm[:-1],
                        rhos_norm,
Exemplo n.º 17
0
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_Drc_zero = fig.add_subplot(gridspec[0])
ax_Drc_inf = fig.add_subplot(gridspec[1],
                             sharex=ax_Drc_zero,
                             sharey=ax_Drc_zero)

ejm_rcparams.prettify_axes(ax_Drc_zero, ax_Drc_inf)


def plot_rdf(ax, dset_path):
    dset = dataset.get_dset(dset_path)
    vp, vp_err = dset.get_vp()
    if use_latex:
        label = r'$\phi = \SI{%.2g}{\percent}$' % vp
    else:
        label = r'$\phi = %.2g \%$' % vp
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    rhos_norm_err[np.isnan(rhos_norm_err)] = 0.0
    ax.errorbar(R_edges_norm[:-1], rhos_norm, yerr=rhos_norm_err, label=label)


for dset_path in paths.constant_R_Drc_0_dset_paths:
Exemplo n.º 18
0
import paths
from ciabatta import ejm_rcparams

save_flag = True

use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(12, 12 * ejm_rcparams.golden_ratio))
ax = fig.add_subplot(111)

ejm_rcparams.prettify_axes(ax)


def plot_rdf(ax, dset_path, smooth):
    dset = dataset.get_dset(dset_path)
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    vp, vp_err = dset.get_vp()
    R = dset.R
    if use_latex:
        label = r"$\SI{" + "{:.3g}".format(R) + r"}{\um}$, " + r"$\SI{" + "{:.2g}".format(vp) + r"}{\percent}$"
    else:
        label = r"$" + "{:.3g}".format(R) + r"\mu m$, $" + "{:.2g}".format(vp) + r"\%$"
    if smooth:
        label += r", Smooth swimming"
    else:
        label += r", Wild type"
use_latex = save_flag
use_pgf = True

ejm_rcparams.set_pretty_plots(use_latex, use_pgf)

dr = 0.7

fig = plt.figure(figsize=(14, 6))

gridspec = GridSpec(1, 2)

ax_noop = fig.add_subplot(gridspec[0])
ax_op = fig.add_subplot(gridspec[1], sharex=ax_noop, sharey=ax_noop)

ejm_rcparams.prettify_axes(ax_noop, ax_op)


def plot_rdf(ax, dset_path, theta_max):
    dset = dataset.get_dset(dset_path, filter_z_flag=False, theta_max=theta_max)
    vp, vp_err = dset.get_vp()
    R = dset.R
    if use_latex:
        label = r"$\SI{" + "{:.3g}".format(R) + r"}{\um}$, " + r"$\SI{" + "{:.2g}".format(vp) + r"}{\percent}$"
    else:
        label = r"$" + "{:.3g}".format(R) + r"\mu m$, $" + "{:.2g}".format(vp) + r"\%$"
    rhos_norm, rhos_norm_err, R_edges_norm = dset.get_rhos_norm(dr)
    rhos_norm_err[np.isnan(rhos_norm_err)] = 0.0
    ax.errorbar(R_edges_norm[:-1], rhos_norm, yerr=rhos_norm_err, label=label)