Exemplo n.º 1
0
def obsprd_plot(plots, flavour):

    pops = {
        'obs': { 'sw': [], 'aw': [] },
        'prd': { 'sw': [], 'aw': [] },
    }

    for plotname in plots:

        if plotname in ignore:
            continue

        plot = plots[plotname]

        L, U, N, T, x, plotfile = plot['attrs']
        nsw, naw = plot['nsw'], plot['naw']

        sw, aw = abb_init_kernels(L, U, N, flavour, plotname)

        for obs_year in sw.years[1:]:
            pops['obs']['sw'].append(len(sw.meas['SW'][obs_year]) / sw.plot_size * 1e4)
            pops['obs']['aw'].append(len(aw.meas['AW'][obs_year]) / sw.plot_size * 1e4)

            j = T.index(obs_year)
            pops['prd']['sw'].append(sw.population(nsw[j]))
            pops['prd']['aw'].append(aw.population(naw[j]))

        tmp = np.asarray(pops['obs']['sw'])
        if any(tmp > 15000):
            print plotname


    stats = { 'sw': {}, 'aw': {} }

    for species in [ 'sw', 'aw' ]:

        from utils.stats import dent_blackie, theil, MSEP
        from scipy.stats import ttest_ind, mannwhitneyu, pearsonr

        obs = pops['obs'][species]
        prd = pops['prd'][species]

        F, pval, (a, b) = dent_blackie(obs, prd)
        stats[species]['F'] = (F, pval)

        stats[species]['theil'] = theil(obs, prd)
        stats[species]['t'] = ttest_ind(prd, obs)
        stats[species]['mannwhitneyu'] = mannwhitneyu(prd, obs)
        stats[species]['pearsonr'] = pearsonr(prd, obs)

        mc, sc, rc, msep = MSEP(obs, prd)
        stats[species]['msep'] = msep
        stats[species]['mc']   = mc
        stats[species]['sc']   = sc
        stats[species]['rc']   = rc

        x    = np.asarray(sorted(prd))
        yhat = a + b*x
        yex  = x

        plt.figure()
        plt.plot(prd, obs, 'ok', label='data', alpha=0.5)
        plt.plot(x,   yex, '-r', label='y=x')
        plt.plot(x,   yhat, '-b', label='best fit')
        plt.ylabel('observed')
        plt.xlabel('predicted')
        plt.legend(loc='best')
        plt.savefig('plots/obsprd_%s_%s.png' % (flavour, species))
        plt.close()
        # plt.title({'sw': 'Spruce', 'aw': 'Aspen'}[species])

    return stats
Exemplo n.º 2
0
        # XXX: should really remove these plots
        if p1 > p0:
            print "NEW TREES:", plotname, obs_year
            continue

        j = T.index(obs_year)
        n1 = sw.population(nsw1[j])
        n2 = sw.population(nsw2[j])

        obs.append(p1 / p0)
        prd["const"].append(n1 / p0)
        prd["model"].append(n2 / p0)


for flavour in prd:
    F, pval, (a, b) = dent_blackie(obs, prd[flavour])
    mrstats[flavour]["F"] = (F, pval)

    x = np.asarray(sorted(prd[flavour]))
    yhat = a + b * x
    yex = x

    plt.figure()
    plt.plot(prd[flavour], obs, "ok", label="data", alpha=0.5)
    plt.plot(x, yex, "-r", label="exact")
    plt.plot(x, yhat, "-b", label="fit")
    plt.ylabel("observed")
    plt.xlabel("predicted")
    plt.legend(loc="best")
    plt.savefig("plots/mortobsprd_sw_mort_%s.pdf" % flavour)