Ejemplo n.º 1
0
def do_diffusion_plots_old():
    import utils; utils.DEFAULT_H5_FILE = "data.h5"
    import specs, models, analysis

    for boundary_layer in [3,6,9,12,15]:
        for light in [1,2,4,6,10,16,24,32]:
            query = specs.make_query(boundary_layer='==%s'%boundary_layer,
                                     light_penetration='==%s'%light)

            plt.clf()
            analysis.heights.phase_diagram_2d(
                'diffusion_constant', 'uptake_rate',
                spec_query=query, num_cells=15, statistic='max',
                cmap=plt.get_cmap('hot'), vmin=0, vmax=64)
            save_plot(path='diffusion/heights/max/boundary{0}_light{1}'.format(boundary_layer, light),
                      xlabel='Diffusion Constant',
                      ylabel='Uptake Rate')

            plt.clf()
            analysis.convex_density.phase_diagram_2d(
                'diffusion_constant', 'uptake_rate',
                spec_query=query, num_cells=15, statistic='mean',
                cmap=plt.get_cmap('hot'), vmin=0, vmax=1)
            save_plot(path='diffusion/convex_density/boundary{0}_light{1}'.format(boundary_layer, light),
                      xlabel='Diffusion Constant',
                      ylabel='Uptake Rate')
Ejemplo n.º 2
0
def do_coverage_plots():
    import utils; utils.DEFAULT_H5_FILE = "coverages.h5"
    import specs, models, analysis

    for mass in [500, 1000, 1500, 2000, 2500]:
        for spacing in [1, 2, 4, 6, 8, 10, 16, 24, 32, 64, 128]:
            plt.clf()

            for light in [0, 8, 16]:
                query = specs.make_query(initial_cell_spacing='==%s'%spacing, 
                                         stop_on_mass='==%s'%mass, 
                                         light_penetration='==%s'%light)
                analysis.coverages.average_curve_plot(spec_query=query, lw=3, 
                        label='Light Penetration Depth = %s'%light)
            plt.legend()
            save_plot(path='coverages/mass%s_spacing%s'%(mass, spacing), 
                      xlabel='Depth', ylabel='Coverage')
Ejemplo n.º 3
0
def do_diffusion_plots():
    import utils; utils.DEFAULT_H5_FILE = "diffusion.h5"
    import specs, models, analysis

    for light in [0, 8]:
        query = specs.make_query(light_penetration='==%s'%light)

        plt.clf()
        analysis.heights.phase_diagram_2d(
            'diffusion_constant', 'uptake_rate',
            spec_query=query, num_cells=40, statistic='max',
            cmap=plt.get_cmap('hot'), vmin=5, vmax=35)
        save_plot(path='diffusion/heights/max/light{0}'.format(light),
                  xlabel='Diffusion Constant',
                  ylabel='Uptake Rate')

        plt.clf()
        analysis.heights.phase_diagram_2d(
            'diffusion_constant', 'uptake_rate',
            spec_query=query, num_cells=40, statistic='mean',
            cmap=plt.get_cmap('hot'), vmin=5, vmax=18)
        save_plot(path='diffusion/heights/mean/light{0}'.format(light),
                  xlabel='Diffusion Constant',
                  ylabel='Uptake Rate')

        plt.clf()
        #levels = [0.6, 0.7, 0.8, 0.9, 1.0]
        #analysis.convex_density.contour_plot(
        #    'diffusion_constant', 'uptake_rate', levels=levels,
        #    spec_query=query, num_cells=100, statistic='mean',
        #    smoothing=0.5, cmap=plt.get_cmap('hot'), vmin=0.0, vmax=1.0)
        analysis.convex_density.phase_diagram_2d(
            'diffusion_constant', 'uptake_rate', 
            spec_query=query, num_cells=40, statistic='mean',
            cmap=plt.get_cmap('hot'), vmin=0.6, vmax=1.0)
        save_plot(path='diffusion/convex_density/light{0}'.format(light),
                  xlabel='Diffusion Constant',
                  ylabel='Uptake Rate')
Ejemplo n.º 4
0
def find_diffusion_line():
    import utils; utils.DEFAULT_H5_FILE = "diffusion3.h5"
    import specs, models, analysis
    import random

    # boundary = 5
    # slope = 4.40
    # query = '(boundary_layer=={0})&(uptake_rate >= {1}*diffusion_constant)'\
    #         .format(boundary, slope)

    # high_growth = [models.Result.where('spec_uuid=="%s"'%spec.uuid)
    #                for spec in specs.Spec.where(query)
    #                if analysis.convex_density.get_by_spec(spec)['mean'] < 0.9]
    # print len(high_growth)

    # for result_set in high_growth:
    #     result = random.choice(list(result_set))
    #     spec = result.spec
    #     path = "fig/images/weird/b{0}_ur{1}_d{2}.png"\
    #            .format(boundary, spec.uptake_rate, spec.diffusion_constant)
    #     cv2.imwrite(path, result.int_image*255)

    boundary = 5
    query = specs.make_query(boundary_layer='==%s'%boundary,
                             uptake_rate=('>0.49', '<0.52'),
                             diffusion_constant='<0.25')
    line = [models.Result.where('spec_uuid=="%s"'%spec.uuid)
            for spec in sorted(specs.Spec.where(query), 
                               key=lambda s:s.diffusion_constant)]

    for i, result_set in enumerate(line):
        result = random.choice(list(result_set))
        spec = result.spec
        path = "fig/images/weird/{0}_b{1}_ur{2}_d{3}.png"\
               .format(i, boundary, spec.uptake_rate, spec.diffusion_constant)
        cv2.imwrite(path, result.int_image*255)
Ejemplo n.º 5
0
def do_biomass_vs_light_plots_spaced():
    import utils; utils.DEFAULT_H5_FILE = "biomass.h5"
    import specs, models, analysis
    from numpy.random import randint

    plt.clf()

    query = specs.make_query(light_penetration='==8', stop_on_mass='<4000')
    x8, y8 = analysis.mass.scatter_plot(analysis.light_exposure, spec_query=query, 
                                        marker='o', mfc='none', ms=8,
                                        label='Light Dependent (Penetration Depth = 8)')

    query = specs.make_query(light_penetration='==0', stop_on_mass='<4000')
    x0, y0 = analysis.mass.scatter_plot(analysis.light_exposure, spec_query=query, 
                                        mec='r', mfc='r', ms=4,
                                        label='Light Independent', marker='.')

    plt.semilogx()
    plt.xlim([400, 2400])
    powers = [2.6, 2.8, 3.0, 3.2, 3.4]
    plt.xticks([10**x for x in powers], ['$10^{%s}$'%x for x in powers])
    plt.legend(loc='lower right')
    save_plot(path='new_spaced_biomass_vs_light_exposure_all', 
              xlabel='Biomass', ylabel='Light Exposure')

    def dump_to_file(path, xs, ys):
        with open(path, "w") as f:
            f.write("biomass,light_exposure\n")
            for x, y in zip(xs, ys):
                f.write("%s,%s\n"%(x, y))
    dump_to_file("fig/new_spaced_light_indep_data.txt", x0, y0)
    dump_to_file("fig/new_spaced_light_dep_dep8_data.txt", x8, y8)

    x_range = [400, 2400]
    points = np.linspace(*x_range)
    log_points = np.log10(points)
    plt.xlim(x_range)
    plt.ylim([220, 670])

    def do_fit(x, y, label, **plot_args):
        in_range = (x >= x_range[0])*(x <= x_range[1])
        log_x = np.log10(x[in_range])
        y = y[in_range]

        fit = np.polyfit(log_x, y, 1, full=True)
        p = np.poly1d(fit[0])
        r2 = 1 - fit[1]/(y.size*y.var())
        print label, p, r2
        plt.plot(points, p(log_points), label=label, **plot_args)
        return p

    p0 = do_fit(x0, y0, 'Light Independent', c='r', lw=3)
    p8 = do_fit(x8, y8, 'Light Dependent (Penetration Depth = 8)', ls='--', lw=3, c='k')
    
    save_plot(path='new_spaced_biomass_vs_light_exposure_upper', 
              xlabel='Biomass', ylabel='Light Exposure')

    def get_percent_diff(p1, p2):
        return np.abs((p1(log_points)-p2(log_points))/p1(log_points)).mean()
    real_diff = get_percent_diff(p0, p8)
    print "Real diff", real_diff

    pool = np.array(zip(x0, y0) + zip(x8, y8))
    def sample_percent_diff():
        def sample(size): return pool[randint(pool.shape[0], size=size), :]
        subpool0, subpool8 = sample(x0.size), sample(x8.size)
        def fit(subpool): return np.poly1d(np.polyfit(np.log10(subpool[:, 0]), subpool[:, 1], 1))
        p0, p8 = fit(subpool0), fit(subpool8)
        return get_percent_diff(p0, p8)