fut_olr, time, lat, lon, fut_dtime = ncout
                elif ndim == 6:
                    fut_olr, time, lat, lon, lev, fut_dtime = ncout
                    fut_olr = np.squeeze(fut_olr)
                else:
                    print 'Check number of levels in ncfile'

                # Select years
                inds = np.where((fut_dtime[:, 0] >= 2065)
                                & (fut_dtime[:, 0] <= 2099))[0]
                fut_dtime = fut_dtime[inds]
                fut_olr = fut_olr[inds, :, :]

                if plotthresh:

                    fut_thresh=fs.find_saddle(fut_olr,method='fmin',addtests=threshtest,\
                                      showplot=False)

            else:

                print futfile + 'does not exist'
                fut_thresh = ''

        ### Plot histogram with the thresh
        ax = plt.subplot(yplots, xplots, cnt)

        # plot historical hist
        olr_flat = np.nan_to_num(olr.ravel())
        y, binEdges = np.histogram(olr_flat, bins=50, density=True)
        bincentres = 0.5 * (binEdges[1:] + binEdges[:-1])
        plt.plot(bincentres, y, linestyle='solid', linewidth=2, color='k')
        if plotthresh:
    else:
        startd = date(ystart, mstart, dstart)
        begind = date(int(beginatyr), 01, 01)
        daysgap = (begind - startd).days
    olr = olr[daysgap:, :, :]
    time = time[daysgap:]
    dtime = dtime[daysgap:]
if testyear:
    if cal == "360_day":
        olr, dtime, time = olr[:360, :, :], dtime[:360], time[:360]
    else:
        olr, dtime, time = olr[:365, :, :], dtime[:365], time[:365]

### Get saddle of ref olr
refolrvals = olr
refolrthresh=fs.find_saddle(refolrvals,method='fmin',showplot=False)

### Count total number of models - (assumes using "all" models)
nm_dset=np.zeros(ndset)
for d in range(ndset):
    dset = dsetnames[d]
    nmod = len(dsetdict.dset_deets[dset])
    nm_dset[d]=nmod
nallmod=np.sum(nm_dset)
nallmod=int(nallmod)
print 'Total number of models = '+str(nallmod)

### Open array for names for cbar
modnm=["" for x in range(nallmod)] # creates a list of strings for modnames

### Display options for plot
Exemplo n.º 3
0
            if testyear:
                if cal == "360_day":
                    olr, dtime, time = olr[:360, :, :], dtime[:360], time[:360]
                else:
                    olr, dtime, time = olr[:365, :, :], dtime[:365], time[:365]
            if future:
                print 'Selecting years ' + fyear1 + ' to ' + fyear2
                inds = np.where((dtime[:, 0] >= int(fyear1))
                                & (dtime[:, 0] <= int(fyear2)))[0]
                dtime = dtime[inds]
                time = time[inds]
                olr = olr[inds, :, :]

            ### Get OLR threshold - and plot if showdistr
            if calcthresh:
                thresh=fs.find_saddle(olr,method='fmin',addtests=threshtest,\
                                  showplot=showdistr,figd=outsuf)
            else:
                if future:
                    threshtxt = txtdir + 'thresholds.fmin.fut_rcp85.cmip5.txt'
                else:
                    threshtxt = txtdir + 'thresholds.fmin.noaa_cmip5.txt'
                print threshtxt
                thcnt = 0
                print 'getting threshold....'
                with open(threshtxt) as f:
                    for line in f:
                        if dset + '\t' + name in line:
                            thresh = line.split()[2]
                            print 'thresh=' + str(thresh)
                            thcnt += 1
                        # Once you have the threshold stop looping
        if res == 'native':
            lat2 = lat
            lon2 = lon
        elif res == 'noaa':
            if testfile:
                yr_noaa = "1979_1979"
            else:
                yr_noaa = "1974_2013"
            f_noaa=cwd+"/../../../CTdata/metbot_multi_dset/"\
                "noaa/noaa.olr.day.mean."+yr_noaa+".nc"
            olrdump, timedump, lat2, lon2, dtimedump = mync.openolr(f_noaa,
                                                                    'olr',
                                                                    subs=sub)

        ### Get thresholds and loop
        thresh = fs.find_saddle(olr, method='fmin')
        if threshtest:
            lowert = thresh - 5
            uppert = thresh + 5
            threshs = [lowert, thresh, uppert]
        else:
            threshs = [thresh]

        ### Loop threshes
        nthresh = len(threshs)
        for t in range(nthresh):
            thisthresh = threshs[t]
            print thisthresh
            thre_str = str(int(thisthresh))
            print thre_str