Ejemplo n.º 1
0
def gen_sst_maps(base_fp = EV['HOME'] + '/Desktop/lcrb_sst/'):
    from simpleNIPA import NIPAphase
    from numpy import ravel
    from smapFuncts import sstMap

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

    models = {}

    for bootconf in [1.0]:
        for corrconf in [.99]:
            fig, axes = plt.subplots(nrows = 3, ncols = 2, figsize = (12, 12))
            for phase, ax in zip(phaseind, ravel(axes)):
                print 'Starting %s, %.2f, %.2f' % (phase, corrconf, bootconf)
                model = NIPAphase(lcrb_prcp, sst, mei, phaseind[phase])
                model.bootcorr(corrconf = corrconf, bootconf = bootconf, quick = True)
                model.gridCheck(lim = 6)
                model.crossvalpcr()
                if not model.flags['noSST']:
                    fig, ax, m = sstMap(model, fig = fig, ax = ax)
                    ax.set_title('%s, %.2f, %i' % (phase, model.correlation, model.n_post_grid))
                else:
                    print '%s has no significant SST'
                models[phase] = model
                fp = base_fp + '%i_%i_shift' % (int(corrconf * 100), int(bootconf*100))
            fig.savefig(fp); plt.close(fig)
    return models
Ejemplo n.º 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
Ejemplo n.º 3
0
def gen_models(quick = False):
    from simpleNIPA import NIPAphase
    from numpy import ravel
    from smapFuncts import sstMap

    models = {}

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

    for phase in phaseind:
        model = NIPAphase(lcrb_prcp, sst, mei, phaseind[phase])
        model.bootcorr(ntim = 100, corrconf = 0.99, bootconf = 0.80, quick = quick)
        model.gridCheck()
        model.crossvalpcr()
        if not model.flags['noSST']: model.genEnsemble()
        models[phase] = model
    return models
Ejemplo n.º 4
0
def gen_models(n = 100, cc = 0.90, bc = 0.80, quick = False):
    from simpleNIPA import NIPAphase
    from numpy import ravel
    from smapFuncts import sstMap

    models = {}

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

    for phase in ['lanina', 'neutneg', 'neutpos', 'elnino', 'allyears']:
        model = NIPAphase(lcrb_prcp, sst, mei, phaseind[phase])
        model.bootcorr(ntim = n, corrconf = cc, bootconf = bc, quick = quick)
        model.gridCheck(lim = 5, ntim = 3)
        model.crossvalpcr()
        if not model.flags['noSST']: model.genEnsemble()
        models[phase] = model
    return models
Ejemplo n.º 5
0
def make_monte_file(n = 10000, lcrb = False, corrconf = 0.90, bootconf = 0.80, quick = False):
    from simpleNIPA import NIPAphase
    from numpy import ravel, isnan, arange, nan
    from random import sample
    from smapFuncts import sstMap
    from matplotlib import pyplot as plt

    if quick:
        filename = '%ixx' % (int(corrconf*100))
    else:
        filename = '%i%i' % (int(corrconf*100), int(bootconf*100))

    if lcrb:
        filename = filename + '_lcrb.csv'
        n = 1000
    else:
        filename = filename + '_%i.csv' % (n)

    #_Initialize dictionary to hold NIPA models for different phases
    models = {}

    #_Initialize files with input filename
    all_file, sig_file = init_monte_files(filename)

    #_Get the clim_data
    clim_data = get_lcrb_prcp()

    #_Get atmospheric data
    sst, slp, mei, phaseind = get_climate_data()

    #_Only want to analyze the four phases. Can do All years separately.
    phases = ['lanina', 'neutneg', 'neutpos', 'elnino']

    #_Begin monte carlo for n rounds.
    for mc in range(1, n + 1):
        print 'Starting round %i' % mc
        #_Create random index
        idx = arange(90)
        if not lcrb:
            idx = sample(xrange(90),90)

        #_Initialize array for testing if all phases are significant
        sig = []

        #_Loop through phases and generate models
        for phase in phases:
            model = NIPAphase(clim_data[idx], sst, mei, phaseind[phase])
            model.bootcorr(ntim = 100, corrconf = corrconf, bootconf = bootconf, quick = quick)
            model.gridCheck(debug = True)
            if not model.flags['noSST']:
                model.crossvalpcr()
            else:
                model.correlation = nan
            #_Store model
            models[phase] = model

            #_Write line
            line = '%i,%s,%.2f,%i\n' % (mc, phase, model.correlation,model.n_post_grid)
            all_file.write(line)

            #_If the model correlation is not nan, append True to sig
            if model.flags['noSST']:
                sig.append(False)
            else:
                sig.append(True)


        if all(sig):
            print 'All significant, combining models'
            sig_file.write('%i\n' % mc)

    #_Close files
    all_file.close; sig_file.close()

    return
Ejemplo n.º 6
0
def make_monte_file(n = 10000, filename = '9980.csv', lcrb = False,
                    corrconf = 0.90, bootconf = 0.8, quick = True):
    from simpleNIPA import NIPAphase
    from numpy import ravel, isnan
    from random import sample
    from smapFuncts import sstMap
    from matplotlib import pyplot as plt

    if lcrb:
        filename = filename[:4] + '_lcrb.csv'
        n = 1
    #_Initialize dictionary to hold NIPA models for different phases
    models = {}

    #_Initialize files with input filename
    all_file, sig_file = init_monte_files(filename)

    #_Get the clim_data
    clim_data = get_lcrb_prcp()

    #_Get atmospheric data
    sst, slp, mei, phaseind = get_climate_data()

    #_Only want to analyze the four phases. Can do All years separately.
    phases = ['lanina', 'neutneg', 'neutpos', 'elnino']

    #_Begin monte carlo for n rounds.
    for mc in range(1, n + 1):
        print 'Starting round %i' % mc
        #_Create random index
        idx = xrange(90)
        if not lcrb:
            idx = sample(xrange(90),90)

        #_Initialize array for testing if all phases are significant
        sig = []

        #_Loop through phases and generate models
        for phase in phases:

            model = NIPAphase(clim_data[idx], sst, mei, phaseind[phase])
            model.bootcorr(ntim = 100, corrconf = corrconf, bootconf = bootconf, quick = quick)
            model.gridCheck(); model.crossvalpcr()

            #_Store model
            models[phase] = model

            #_Write line
            line = '%i,%s,%.2f,%i\n' % (mc, phase, model.correlation,model.n_post_grid)
            all_file.write(line)

            #_If the model correlation is not nan, append True to sig
            sig.append(~isnan(model.correlation))


        # if all(sig):
        #     print 'All significant, combining models'
        #     [models[phase].genEnsemble() for phase in phases]
        #     clim_data, hindcast, ensemble = combine_models(models)
        #
        #     #_Create and write the long line for the significant data
        #     line = write_sig_data(mc, clim_data, hindcast, ensemble)
        #     sig_file.write(line)

    #_Close files
    all_file.close; sig_file.close()

    return