def tcol_error(df): """Triple collocation error estimate In this case df has to have exactly 3 columns, since triple wise application of a function is not yet implemented and would probably return a complicated structure Returns ------- result : namedtuple with column names of df See Also -------- pytesmo.metrics.tcol_error """ if len(df.columns) != 3: raise DataFrameDimensionError("DataFrame has to have 3 columns") tcol_result = namedtuple('triple_collocation_error',df.columns) return tcol_result._make(metrics.tcol_error(df.ix[:,0].values, df.ix[:,1].values, df.ix[:,2].values))
def test_tcol_error(): """ Test the triple collocation error estimation based on a random signal and error. Also compare the results to the other method """ n = 1000000 signal = np.sin(np.linspace(0, 2 * np.pi, n)) sig_err_x = 0.02 sig_err_y = 0.07 sig_err_z = 0.04 err_pred = np.array((sig_err_x, sig_err_y, sig_err_z)) err_x = np.random.normal(0, sig_err_x, n) err_y = np.random.normal(0, sig_err_y, n) err_z = np.random.normal(0, sig_err_z, n) alpha_y = 0.2 alpha_z = 0.5 beta_y = 0.9 beta_z = 1.6 x = signal + err_x y = alpha_y + beta_y * (signal + err_y) z = alpha_z + beta_z * (signal + err_z) snr, err, beta = met.tcol_snr(x, y, z, ref_ind=0) # classical triple collocation errors use scaled (removed alpha and beta) # input arrays ex, ey, ez = met.tcol_error(signal + err_x, signal + err_y, signal + err_z) nptest.assert_almost_equal(err, np.array([ex, ey, ez]), decimal=2) nptest.assert_almost_equal(err_pred, np.array([ex, ey, ez]), decimal=2)
def tcol_error(df): """Triple collocation error estimate In this case df has to have exactly 3 columns, since triple wise application of a function is not yet implemented and would probably return a complicated structure Returns ------- result : namedtuple with column names of df See Also -------- pytesmo.metrics.tcol_error """ if len(df.columns) != 3: raise DataFrameDimensionError("DataFrame has to have 3 columns") tcol_result = namedtuple('triple_collocation_error', df.columns) return tcol_result._make(metrics.tcol_error(df.ix[:, 0].values, df.ix[:, 1].values, df.ix[:, 2].values))