Esempio n. 1
0
def ce_r_ens_avg(gmt_ens,
                 times,
                 analysis_gmt,
                 analysis_times,
                 trange=(1880, 2000),
                 center_trange=(1900, 2000)):

    start, end = trange
    # Get the global mean for the analysis dataset

    gmt_ens = center_to_time_range(times,
                                   gmt_ens,
                                   time_axis=-1,
                                   trange=center_trange)

    # Get a mask for overlapping times
    analysis_tidx = (analysis_times >= start) & (analysis_times <= end)
    lmr_tidx = (times >= start) & (times <= end)

    ens_ce = \
        np.array([utils2.coefficient_efficiency(analysis_gmt[analysis_tidx],
                                                a_ens_gmt[lmr_tidx])
                  for a_ens_gmt in gmt_ens])
    ens_ce[ens_ce == 1] = np.nan

    ens_r = np.array([
        np.corrcoef(analysis_gmt[analysis_tidx], a_ens_gmt[lmr_tidx])[0, 1]
        for a_ens_gmt in gmt_ens
    ])

    return ens_ce, ens_r
Esempio n. 2
0
def find_ce_corr(VAR,
                 REF,
                 REF_TIME,
                 VAR_TIME,
                 START_TIME,
                 END_TIME,
                 detrend=False):
    """Finds the correlation coefficient and coefficient of efficiency between 
       REF and VAR between START_TIME and END_TIME.
       inputs: 
           VAR = test data (1D in time)
           REF = reference data (1D in time) 
           REF_time = reference data time (1D time)
           VAR_TIME = test data time (1D years)
           START_TIME = comparison start year to be included (float)
           END_TIME = last year included in comparison (float)
       
    """
    yr_range_var = np.where((VAR_TIME >= START_TIME)
                            & (VAR_TIME < END_TIME + 1))
    yr_range_ref = np.where((REF_TIME >= START_TIME)
                            & (REF_TIME < END_TIME + 1))

    if detrend is False:
        ref = REF[yr_range_ref[0]]
        var = VAR[yr_range_var[0]]
    else:
        ref = spy.detrend(REF[yr_range_ref])
        var = spy.detrend(VAR[yr_range_var])

    ce = lmr.coefficient_efficiency(ref, var)
    corr = np.corrcoef(ref, var)[0, 1]
    var_ref = np.var(ref)
    var_var = np.var(var)

    return ce, corr, var_ref, var_var