예제 #1
0
파일: utils.py 프로젝트: bgzimmerman/nipa
def categorize(data, ncat = 3, hindcast = False):
    from pandas import Series
    from numpy import sort
    from data_load import get_lcrb_prcp
    prcp = get_lcrb_prcp()
    index = prcp.index

    x = sort(data)
    n = len(x)
    upper = x[((2 * n) / ncat) - 1]
    lower = x[(n / ncat) - 1]


    cat_dat = Series(index = index)


    for year in prcp.index.year:
        if data[year] <= lower:
            cat_dat[year] = 'B'
        elif data[year] > upper:
            cat_dat[year] = 'A'
        else:
            cat_dat[year] = 'N'

    return cat_dat
예제 #2
0
def gen_model(phase = 'lanina', cc = 0.95, bc = 0.80, quick = True):
    from simpleNIPA import NIPAphase
    from numpy import ravel
    from smapFuncts import sstMap


    lcrb_prcp = get_lcrb_prcp()
    sst, slp, mei, phaseind = get_climate_data()

    model = NIPAphase(lcrb_prcp, sst, mei, phaseind[phase])
    model.bootcorr(corrconf = cc, bootconf = bc, quick = quick)
    model.gridCheck(lim = 5, ntim = 3, debug = True)
    model.crossvalpcr()
    return model
예제 #3
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
예제 #4
0
def violin():
    from data_load import get_lcrb_prcp, get_climate_data
    prcp = get_lcrb_prcp()
    _,_,_, phaseind = get_climate_data()
    cmap = mpl.cm.get_cmap('viridis')
    rgba = [cmap(0.25), cmap(0.7)]

    data = [prcp[phaseind['lanina']], prcp, prcp[phaseind['elnino']]]
    violin_parts = plt.violinplot(data, showmeans = True)
    plt.ylim(0,650)
    plt.xticks(range(1,4),['La Nina', 'All Years', 'El Nino'], fontsize = 18)
    plt.title('MAMJ Precipitation in LCRB by Phase', fontsize = 22,
                fontweight = 'bold')

    for feature in ['cbars', 'cmins', 'cmeans', 'cmaxes']:
        violin_parts[feature].set_color('black')
    for pc, color in zip(violin_parts['bodies'], [cmap(0), cmap(0.75), cmap(0.4)]):
        pc.set_facecolor(color)
    plt.ylabel('Precipitation, mm', fontweight='bold')
    plt.savefig(EV['HOME'] + '/Desktop/Feb20Response/images/violin')
    return
예제 #5
0
def timeseries():
    ###Make figure showing which years fall where
    prcp = get_lcrb_prcp()
    sst, slp, mei, phaseind = get_climate_data()
    cmap = mpl.cm.get_cmap('seismic')
    fig, ax = plt.subplots(1, figsize = (12,6))
    ax.plot(prcp, color = 'k', linewidth = 2)
    colors = [cmap(0.2), cmap(0.4), cmap(0.6), cmap(0.8)]
    phases = ['lanina', 'neutneg', 'neutpos', 'elnino']

    for phase, color in zip(phases, colors):
        if phase == 'lanina': title = 'La Nina'
        if phase == 'elnino': title = 'El Nino'
        if phase == 'neutpos': title = 'Neutral-Positive'
        if phase == 'neutneg': title = 'Neutral-Negative'
        ax.plot(prcp[phaseind[phase]], marker = 'o',
                markersize = 10, color = color, linewidth = 0, label = title)
    plt.legend(loc = 'best')
    ax.set_ylim(0, 650)
    ax.set_xlabel('Years', fontsize = 16, fontweight = 'bold')
    ax.set_ylabel('Total MAMJ Precipitaton, mm', fontsize = 16, fontweight = 'bold')
    fig.savefig(EV['HOME'] + '/Desktop/Feb20Response/images/timeseries')
    return
예제 #6
0
파일: utils.py 프로젝트: bgzimmerman/nipa
        elif data[year] > upper:
            cat_dat[year] = 'A'
        else:
            cat_dat[year] = 'N'

    return cat_dat

if __name__ == '__main__':

    ### I think to do PCA on all and then split just requires
    ### Using the None phase and then phasind.
    from simpleNIPApca import *
    from numpy import concatenate, corrcoef, array
    phase = None
    patterns, lats, lons, lams, pcs = combine_regions(phase)
    prcp = get_lcrb_prcp()
    sst, slp, mei, phaseind = get_climate_data()
    pcs = concatenate((pcs['Indian'], pcs['Atlantic'], pcs['Pacific']))
    # lams = concatenate((lams['Indian'], lams['Atlantic'], lams['Pacific']))
    #
    #
    # phase = 'elnino'
    #
    # from numpy.random import randint
    # idx = randint(0,89,90)
    # for phase in phaseind:
    #     model = NIPAphase(prcp[idx], pcs[:,phaseind[phase]], mei, phaseind[phase])
    #     model.crossvalpcr()
    #     print '%s: %.2f' % (phase, model.correlation)
    #     print model.overall_index
    #     print lams[model.overall_index]