Exemple #1
0
    def project_east_west(self, dataset, experiment, best_fit=True):
        X = self.OBS[string.upper(dataset)]
        fingerprint = getattr(self, experiment)
        westsolver = fingerprint.solvers["west"]
        westfac = da.get_orientation(westsolver)
        time_plot(westfac * westsolver.projectField(X.reshaped["west"])[:, 0],
                  label="WEST",
                  color=get_colors("west"))

        eastsolver = fingerprint.solvers["east"]
        eastfac = da.get_orientation(eastsolver)
        time_plot(eastfac * eastsolver.projectField(X.reshaped["east"])[:, 0],
                  label="EAST",
                  color=get_colors("east"))

        plt.legend()
        plt.ylabel("Projection onto " + fingerprint.experiment +
                   " fingerprint")
        if best_fit:
            y = westfac * westsolver.projectField(X.reshaped["west"])[:, 0]
            t = cmip5.get_plottable_time(y)
            p = np.polyfit(t, y.asma(), 1)
            plt.plot(t, np.polyval(p, t), "--", color=get_colors("west"))

            y = eastfac * eastsolver.projectField(X.reshaped["east"])[:, 0]
            t = cmip5.get_plottable_time(y)
            p = np.polyfit(t, y.asma(), 1)
            plt.plot(t, np.polyval(p, t), "--", color=get_colors("east"))
def get_crossing_time(region, variable, scenario, month):
    vcert = stats.norm.interval(.99)[1]
    mfile = get_file(region, variable, scenario, month)
    if mfile is None:
        crossing_time = None

    else:
        f = cdms.open(mfile)
        data = f(variable + "_SN")
        avg = MV.average(data, axis=0)
        threshexceed = np.where(np.abs(avg) > vcert)[0]
        #If it never exceeds the threshold, return None
        if len(threshexceed) == 0:
            return (None)
        #If it hasn't exceeded the threshold by the last time step, return None
        if len(avg) - 1 not in threshexceed:
            return (None)
        if len(np.where(np.diff(threshexceed) > 1)[0]) > 0:
            isnot1 = np.max(np.where(np.diff(threshexceed) > 1)[0]) + 1
        else:
            isnot1 = 0
        staysabove = int(threshexceed[isnot1])
        crossing_time = int(cmip5.get_plottable_time(data)[staysabove])
        f.close()
    return (crossing_time)
Exemple #3
0
def get_slopes(c,yrs,plot = False):
    """
    get non-overlapping trends in concatenated control run
    """
    trends = np.ma.array([])
    start = 0
    end = yrs
    if plot:
        
        Ntot = float(len(c)/yrs)
    while end < len(c):
        ctrunc = c[start:end]
        #if len(ctrunc.compressed()) == len(ctrunc):
        if True:
        # Express in "per decade" units.  All control runs are in days.
            slope0,intercept0 = genutil.statistics.linearregression(ctrunc)
            slope = slope0*3650.
            if plot:
                xax = cmip5.get_plottable_time(ctrunc)
                plt.plot(xax,ctrunc.asma(),color = cm.RdYlBu(float(start/yrs)/Ntot))
                plt.plot(xax,float(slope0)*ctrunc.getTime()[:]+float(intercept0),color ="k",linewidth = 3)
            trends = np.append(trends,slope)
        start = end
        end += yrs
       
    trends = MV.masked_where(np.isnan(trends),trends)
    trends = trends.compressed()
    return trends
Exemple #4
0
def time_plot(x,ax=None,**kwargs):
    """ plot a cdms time series """
    t = cmip5.get_plottable_time(x)
    if ax is None:
        ax=plt.gca()
    
    ax.plot(t,x.asma(),**kwargs)
Exemple #5
0
def plot_h85_trends(H85):
    x = cmip5.get_plottable_time(H85)
    nmod = H85.shape[0]
    cmap = cm.magma
    for i in range(nmod):
        if not H85[i].mask[0]:
            time_plot(H85[i],
                      lw=.5,
                      alpha=.5,
                      color=cm.magma(float(i) / float(nmod)))
            p = np.ma.polyfit(x, H85[i], 1)
            plt.plot(x,
                     np.polyval(p, x),
                     color=cm.magma(float(i) / float(nmod)))
Exemple #6
0
def project_multi(X, fingerprint, best_fit=True):
    multisolver = fingerprint.solvers["multi"]
    multifac = da.get_orientation(multisolver)
    time_plot(multifac * multisolver.projectField(X)[:, 0],
              label="MULTI",
              color=get_colors("multi"))

    plt.legend()
    plt.ylabel("Projection onto " + fingerprint.experiment + " fingerprint")
    if best_fit:
        y = multifac * multisolver.projectField(X)[:, 0]
        t = cmip5.get_plottable_time(y)
        p = np.polyfit(t, y.asma(), 1)
        plt.plot(t, np.polyval(p, t), "--", color=get_colors("multi"))