Beispiel #1
0
def proj_aerosols(AA, piControl, H85, start=None, stop=None):

    if start is None:
        start = cdtime.comptime(1945, 1, 1)
    if stop is None:
        stop = cdtime.comptime(1984, 12, 31)
    data = [H85.reshaped["west"], H85.reshaped["east"]]
    nmod, nyears, nmonths = H85.reshaped["west"].shape
    P = MV.zeros((nmod, nyears))
    msolver = AA.solvers["multi"]
    fac = da.get_orientation(msolver)

    for i in range(nmod):
        to_proj = [H85.reshaped["west"][i], H85.reshaped["east"][i]]
        P[i] = msolver.projectField(to_proj)[:, 0] * fac
    P.setAxis(0, H85.reshaped["west"].getAxis(0))
    timeax = H85.reshaped["west"].getAxis(1)
    timeax.id = "time"
    P.setAxis(1, timeax)

    piCdata = [piControl.reshaped["west"], piControl.reshaped["east"]]
    pc = msolver.projectField(piCdata)[:, 0]
    Pt = P(time=(start, stop))
    nt = len(Pt.getTime())
    hslopes = cmip5.get_linear_trends(Pt)
    pslopes = da.get_slopes(pc, nt)
Beispiel #2
0
    def DA_histogram(self,
                     experiment,
                     direction,
                     start=None,
                     stop=None,
                     datasets=None):
        fingerprint = getattr(self, experiment)

        if start is None:
            start = cmip5.start_time(self.gpcp.reshaped["east"])
            start = cdtime.comptime(start.year, start.month, 1)
        if stop is None:
            stop = cmip5.stop_time(self.gpcp.reshaped["east"])
            stop = cdtime.comptime(stop.year, stop.month, 30)

        #get the h85 projections over the same time period
        H85m = self.model_projections(experiment,
                                      direction)(time=(start, stop))
        H85 = cmip5.cdms_clone(np.ma.mask_rows(H85m), H85m)
        H85_trends = cmip5.get_linear_trends(H85)
        #get the piControl projection time series
        noise = self.noise_projections(experiment, direction)
        L = stop.year - start.year + 1
        noise_trends = da.get_slopes(noise, L)

        #plot
        plt.hist(H85_trends.compressed(),
                 25,
                 color=da_colors("h85"),
                 alpha=.5,
                 normed=True)
        plt.hist(noise_trends,
                 25,
                 color=da_colors("piC"),
                 alpha=.5,
                 normed=True)
        da.fit_normals_to_data(H85_trends,
                               color=da_colors("h85"),
                               lw=3,
                               label="H85")
        da.fit_normals_to_data(noise_trends,
                               color=da_colors("piC"),
                               lw=3,
                               label="piControl")
        # plt.axvline(obs_trend,label=obs.dataset,color=da_colors(obs.dataset))

        #Project the observations
        if datasets is None:
            datasets = ["gpcp", "cmap", "precl"]
        if type(datasets) != type([]):
            datasets = [datasets]
        for dataset in datasets:

            obs_proj = self.obs_projections(experiment, dataset,
                                            direction)(time=(start, stop))
            obs_trend = cmip5.get_linear_trends(obs_proj)
            plt.axvline(obs_trend, label=dataset, color=da_colors(dataset))
            print dataset + "S/N is: " + str(obs_trend / np.std(noise_trends))
Beispiel #3
0
 def sn_at_time(self,start_time,L,overlapping=True):
     if not hasattr(self,"P"):
         self.model_projections()
     stop_time=start_time.add(L,cdtime.Years)
     modslopes = cmip5.get_linear_trends(self.P(time=(start_time,stop_time)))
     if overlapping:
         noiseterm = bootstrap_slopes(self.noise,L)
     else:
         noiseterm = da.get_slopes(self.noise,L)/365.
     return modslopes,noiseterm
Beispiel #4
0
def DA_histogram(fingerprint,
                 obslist,
                 h85,
                 piC,
                 direction,
                 start=None,
                 stop=None):
    if type(obslist) == type([]):
        obs = obslist[0]
    else:
        obs = obslist
    if start is None:
        start = cmip5.start_time(obs.reshaped["east"])
        start = cdtime.comptime(start.year, start.month, 1)
    if stop is None:
        stop = cmip5.stop_time(obs.reshaped["east"])
        stop = cdtime.comptime(stop.year, stop.month, 30)
    #project the observations onto the fingerprint
    obs_proj = obs_projections(fingerprint, obs, direction)(time=(start, stop))
    obs_trend = cmip5.get_linear_trends(obs_proj)
    #get the h85 projections over the same time period
    H85m = model_projections(fingerprint, h85, direction)(time=(start, stop))
    H85 = cmip5.cdms_clone(np.ma.mask_rows(H85m), H85m)
    H85_trends = cmip5.get_linear_trends(H85)
    #get the piControl projection time series
    noise = noise_projections(fingerprint, piC, direction)
    L = len(obs_proj)
    noise_trends = da.get_slopes(noise, L)

    #plot
    plt.hist(H85_trends.compressed(),
             25,
             color=da_colors("h85"),
             alpha=.5,
             normed=True)
    plt.hist(noise_trends, 25, color=da_colors("piC"), alpha=.5, normed=True)
    da.fit_normals_to_data(H85_trends,
                           color=da_colors("h85"),
                           lw=3,
                           label="H85")
    da.fit_normals_to_data(noise_trends,
                           color=da_colors("piC"),
                           lw=3,
                           label="piControl")
    plt.axvline(obs_trend, label=obs.dataset, color=da_colors(obs.dataset))
    if type(obslist) == type([]):
        for obs in obslist[1:]:

            obs_proj = obs_projections(fingerprint, obs,
                                       direction)(time=(start, stop))
            obs_trend = cmip5.get_linear_trends(obs_proj)
            plt.axvline(obs_trend,
                        label=obs.dataset,
                        color=da_colors(obs.dataset))
    return H85, noise, obs_proj
Beispiel #5
0
    def sn_at_time(self, start_time, L, depth, overlapping=True):
        self.project_piControl_on_solver(depth)

        self.model_projections(depth)
        stop_time = start_time.add(L, cdtime.Years)
        modslopes = cmip5.get_linear_trends(self.P[depth](time=(start_time,
                                                                stop_time)))
        if overlapping:
            noiseterm = b.bootstrap_slopes(self.noise[depth], L)
        else:
            noiseterm = da.get_slopes(self.noise[depth], L) / 365.
        return modslopes, noiseterm
Beispiel #6
0
def signal_to_noise_map(drought_atlas,start_year=1100,modern_start=1979):

    preindustrial = drought_atlas[start_year:1850]
    modern = drought_atlas[modern_start:]
    modern_times = modern.shape[0]
    nt,nlat,nlon=drought_atlas.shape
    SN = MV.zeros(drought_atlas.shape[1:])+1.e20
    signals = cmip5.get_linear_trends(modern)
    for i in range(nlat):
        for j in range(nlon):
            if not drought_atlas.mask[-1,i,j]:
                noise = da.get_slopes(preindustrial[:,i,j],modern_times)/365. #get_slopes assumes time units are days; these are years
                width=np.ma.std(noise)
                signal = signals[i,j]
                SN[i,j]=signal/width
    return SN
Beispiel #7
0
    def sn_at_time(self,
                   start_time,
                   L,
                   overlapping=True,
                   noisestart=None,
                   solver=None):
        if noisestart is None:
            noisestart = cmip5.start_time(self.obs)
        noisestop = cmip5.stop_time(self.get_noise(solver=solver))

        stop_time = start_time.add(L, cdtime.Years)
        modslopes = cmip5.get_linear_trends(
            self.get_forced(solver=solver)(time=(start_time, stop_time)))
        if overlapping:
            noiseterm = bootstrap_slopes(
                self.get_noise(solver=solver)(time=(noisestart, noisestop)), L)
        else:
            noiseterm = da.get_slopes(
                self.get_noise(solver=solver)(time=(noisestart, noisestop)),
                L) / 365.
        return modslopes, noiseterm
Beispiel #8
0
def TOE(OnePct, piControl, H85, start=None):
    #Calculate the time of emergence:
    data = [H85.reshaped["west"], H85.reshaped["east"]]
    nmod, nyears, nmonths = H85.reshaped["west"].shape
    P = MV.zeros((nmod, nyears))
    msolver = OnePct.solvers["multi"]
    fac = da.get_orientation(msolver)

    for i in range(nmod):
        to_proj = [H85.reshaped["west"][i], H85.reshaped["east"][i]]
        P[i] = msolver.projectField(to_proj)[:, 0] * fac
    P.setAxis(0, H85.reshaped["west"].getAxis(0))
    timeax = H85.reshaped["west"].getAxis(1)
    timeax.id = "time"
    P.setAxis(1, timeax)

    piCdata = [piControl.reshaped["west"], piControl.reshaped["east"]]
    pc = msolver.projectField(piCdata)[:, 0]
    if start is None:
        start = cdtime.comptime(2000, 1, 1)
    stop = start.add(1, cdtime.Years)
    final_year = cdtime.comptime(2099, 12, 31)
    tl = final_year.year - start.year + 1

    NOISE = MV.zeros(tl)
    SIGNAL = MV.zeros((nmod, tl))
    i = 0
    while stop.cmp(final_year) < 0:
        modelproj = P(time=(start, stop))
        L = modelproj.shape[1]
        slopes = da.get_slopes(pc, L)
        SIGNAL[:, i] = cmip5.get_linear_trends(modelproj)
        NOISE[i] = np.ma.std(slopes)
        stop = stop.add(1, cdtime.Years)
        i += 1
    return SIGNAL, NOISE
Beispiel #9
0
def average_histogram(obslist,
                      h85,
                      piC,
                      direction,
                      start=None,
                      stop=None,
                      months="JJ"):
    if months is "JJ":
        mmean = lambda x: MV.average(x[:, 5:7], axis=1)
        bigmmean = lambda X: MV.average(X[:, :, 5:7], axis=2)
    elif months is "SO":
        mmean = lambda x: MV.average(x[:, 8:10], axis=1)
        bigmmean = lambda X: MV.average(X[:, :, 8:10], axis=2)
    elif months is "JJA":
        mmean = lambda x: MV.average(x[:, 5:8], axis=1)
        bigmmean = lambda X: MV.average(X[:, :, 5:8], axis=2)
    elif months is "Jun":
        mmean = lambda x: x[:, 5]
        bigmmean = lambda X: MV.average(X[:, :, 5])
    if type(obslist) == type([]):
        obs = obslist[0]
    else:
        obs = obslist
    if start is None:
        start = cmip5.start_time(obs.reshaped["east"])
        start = cdtime.comptime(start.year, start.month, 1)
    if stop is None:
        stop = cmip5.stop_time(obs.reshaped["west"])
        stop = cdtime.comptime(stop.year, stop.month, 30)
    #calculate the trend in the observations

    obs_avg = mmean(obs.reshaped[direction](time=(start, stop)))

    obs_trend = cmip5.get_linear_trends(obs_avg)
    #get the h85 trends over the same time period
    H85m = bigmmean(h85.reshaped[direction])(time=(start, stop))
    H85 = cmip5.cdms_clone(np.ma.mask_rows(H85m), H85m)
    H85_trends = cmip5.get_linear_trends(H85)
    #get the piControl projection time series
    noise = mmean(piC.reshaped[direction])
    L = len(obs_avg)
    noise_trends = da.get_slopes(noise, L)

    #plot
    plt.hist(H85_trends.compressed(),
             25,
             color=da_colors("h85"),
             alpha=.5,
             normed=True)
    plt.hist(noise_trends, 25, color=da_colors("piC"), alpha=.5, normed=True)
    da.fit_normals_to_data(H85_trends,
                           color=da_colors("h85"),
                           lw=3,
                           label="H85")
    da.fit_normals_to_data(noise_trends,
                           color=da_colors("piC"),
                           lw=3,
                           label="piControl")
    plt.axvline(obs_trend, label=obs.dataset, color=da_colors(obs.dataset))
    if type(obslist) == type([]):
        for obs in obslist[1:]:
            obs_avg = mmean(obs.reshaped[direction](time=(start, stop)))

            obs_trend = cmip5.get_linear_trends(obs_avg)

            plt.axvline(obs_trend,
                        label=obs.dataset,
                        color=da_colors(obs.dataset))
    plt.xlabel("S/N")
    plt.ylabel("Frequency")
    plt.legend(loc=0)
Beispiel #10
0
    def average_histogram(self,
                          direction,
                          start=None,
                          stop=None,
                          months="JJ",
                          datasets=None):
        if months is "JJ":
            mmean = lambda x: MV.average(x[:, 5:7], axis=1)
            bigmmean = lambda X: MV.average(X[:, :, 5:7], axis=2)

        elif months is "SO":
            mmean = lambda x: MV.average(x[:, 8:10], axis=1)
            bigmmean = lambda X: MV.average(X[:, :, 8:10], axis=2)
        elif months is "JJA":
            mmean = lambda x: MV.average(x[:, 5:8], axis=1)
            bigmmean = lambda X: MV.average(X[:, :, 5:8], axis=2)
        elif months is "JAS":
            mmean = lambda x: MV.average(x[:, 6:9], axis=1)
            bigmmean = lambda X: MV.average(X[:, :, 6:9], axis=2)
        elif months is "Jun":
            mmean = lambda x: x[:, 5]
            bigmmean = lambda X: MV.average(X[:, :, 5])
        elif months is "YEAR":
            mmean = lambda x: MV.average(x, axis=1)
            bigmmean = lambda X: MV.average(X, axis=2)
        if start is None:
            start = cmip5.start_time(self.gpcp.reshaped["east"])
            start = cdtime.comptime(start.year, start.month, 1)
        if stop is None:
            stop = cmip5.stop_time(self.gpcp.reshaped["east"])
            stop = cdtime.comptime(stop.year, stop.month, 30)

        #get the h85 trends over the same time period
        H85m = bigmmean(self.h85.reshaped[direction])(time=(start, stop))
        H85 = cmip5.cdms_clone(np.ma.mask_rows(H85m), H85m)
        H85_trends = cmip5.get_linear_trends(H85)
        #get the piControl projection time series
        noise = mmean(self.piC.reshaped[direction])
        L = stop.year - start.year + 1
        noise_trends = da.get_slopes(noise, L)

        #plot
        plt.hist(H85_trends.compressed(),
                 25,
                 color=da_colors("h85"),
                 alpha=.5,
                 normed=True)
        plt.hist(noise_trends,
                 25,
                 color=da_colors("piC"),
                 alpha=.5,
                 normed=True)
        da.fit_normals_to_data(H85_trends,
                               color=da_colors("h85"),
                               lw=3,
                               label="H85")
        da.fit_normals_to_data(noise_trends,
                               color=da_colors("piC"),
                               lw=3,
                               label="piControl")

        #calculate the trend in the observations
        if datasets is None:
            datasets = ["gpcp", "cmap", "precl"]
        if type(datasets) != type([]):
            datasets = [datasets]
        for dataset in datasets:
            X = self.OBS[string.upper(dataset)]
            obs_avg = mmean(X.reshaped[direction](time=(start, stop)))

            obs_trend = cmip5.get_linear_trends(obs_avg)

            plt.axvline(obs_trend, label=dataset, color=da_colors(dataset))
        plt.xlabel("S/N")
        plt.ylabel("Frequency")
        plt.legend(loc=0)