Example #1
0
def nmmehist():
    from nmme import gen_ensembles
    df = gen_ensembles()
    prcp = get_lcrb_prcp()
    fig, (ax1, ax2) = plt.subplots(1,2, figsize = (12,4))
    ax1.hist(df[1998], label = 'NMME Ensembles', color = 'gray')
    ax1.vlines(prcp['1998'], 0, 17, label = 'Observed', linewidth = 4)
    ax1.set_title('1998')
    ax1.set_xlabel('Prcp')

    ax2.hist(df[2004], label = 'NMME Ensembles', color = 'gray')
    ax2.vlines(prcp['2004'], 0, 12, label = 'Observed', linewidth = 4)
    ax2.set_title('2004')
    ax2.set_xlabel('Prcp')
    plt.legend()
    fig.suptitle('NMME Ensemble Histograms', fontsize = 18, fontweight = 'bold')
    fig.savefig(EV['HOME'] + '/Desktop/CodePresentation/images/nmmehist')
    return
Example #2
0
def nmmecompare():
    from nmme import gen_ensembles
    from data_load import gen_models, combine_models, RPSS, HSS
    from scipy.stats import gaussian_kde as gk
    models = gen_models(cc = 0.95, quick = True)
    clim_data, hindcast, ensemble = combine_models(models)
    df = gen_ensembles()

    cmap = mpl.cm.get_cmap('viridis')
    rgba = [cmap(0.25), cmap(0.7)]
    idx = np.arange(1921,2011)>=1982
    x = 16
    dNIPA = gk(ensemble[:,idx][x], bw_method = 0.5)
    dNMME = gk(df.values[x], bw_method = 0.5)
    p_x = np.linspace(0, 600, 1000)
    fig, (ax1, ax2) = plt.subplots(1,2,sharey = True, figsize = (14,10))
    ax1.plot(p_x, dNMME.pdf(p_x)*1000, color = rgba[0], label = 'NMME', linewidth = 2)
    ax1.plot(p_x, dNIPA.pdf(p_x)*1000, color = rgba[1], label = 'NIPA', linewidth = 2)
    ax1.fill_between(p_x, 0, dNIPA.pdf(p_x)*1000, color = rgba[1], alpha = 0.5)
    ax1.fill_between(p_x, 0, dNMME.pdf(p_x)*1000, color = rgba[0],alpha = 0.5)
    ax1.vlines(clim_data[idx][x], 0, 6, linewidth = 4, color = 'k')
    ax1.set_title(str(clim_data.index.year[idx][x]),fontsize = 18, fontweight='bold')
    ax1.set_ylabel('Probability Density, $10^{-3}$', fontweight = 'bold')
    h, l = ax1.get_legend_handles_labels()
    ax1.legend(h, l)

    x = 25
    dNIPA = gk(ensemble[:,idx][x], bw_method = 0.5)
    dNMME = gk(df.values[x], bw_method = 0.5)
    p_x = np.linspace(0, 600, 1000)
    ax2.plot(p_x, dNMME.pdf(p_x)*1000, color = rgba[0], label = 'NMME', linewidth = 2)
    ax2.plot(p_x, dNIPA.pdf(p_x)*1000, color = rgba[1], label = 'NIPA', linewidth = 2)
    ax2.fill_between(p_x, 0, dNIPA.pdf(p_x)*1000, color = rgba[1], alpha = 0.5)
    ax2.fill_between(p_x, 0, dNMME.pdf(p_x)*1000, color = rgba[0],alpha = 0.5)
    ax2.vlines(clim_data[idx][x], 0, 6, linewidth = 4, color = 'k')
    ax2.set_title(str(clim_data.index.year[idx][x]), fontsize = 18, fontweight='bold')
    fig.text(0.33, 0.015, 'Total MAMJ Precipitation, mm')
    fig.savefig(EV['HOME'] + '/Desktop/Feb20Response/images/nmmecompare')
    plt.close(fig)
    return