How to use the pytesmo.metrics.tcol_snr function in pytesmo

To help you get started, we’ve selected a few pytesmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TUW-GEO / pytesmo / tests / tc_metrics.py View on Github external
if realdata:
        df = read_realdata(n=n).dropna()
    else:
        df = create_testdata(n, np.array(list(range(n))))
    snr, err, beta = df_metrics.tcol_snr(df, ref_ind=0)
    print('snr')
    pprint(snr)
    print('err')
    pprint(err)
    print('beta')
    pprint(beta)
    print('------------------')

    if n == 3:
        old_snr, old_err, old_beta = \
            metrics.tcol_snr(df.iloc[:,0].values,
                             df.iloc[:,1].values,
                             df.iloc[:,2].values)
        print('old_snr')
        pprint(old_snr)
        print('old_err')
        pprint(old_err)
        print('old_beta')
        pprint(old_beta)
    print('=================================')
github TUW-GEO / pytesmo / tests / test_metrics.py View on Github external
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)

    beta_pred = 1. / np.array((1, beta_y, beta_z))
    err_pred = np.array((sig_err_x, sig_err_y, sig_err_z))
    snr_pred = np.array(
        ((sig_signal / sig_err_x), (sig_signal / sig_err_y), (sig_signal / sig_err_z)))

    snr, err, beta = met.tcol_snr(x, y, z, ref_ind=0)

    nptest.assert_almost_equal(beta, beta_pred, decimal=2)
    nptest.assert_almost_equal(err, err_pred, decimal=2)
    nptest.assert_almost_equal(np.sqrt(10 ** (snr / 10.)), snr_pred, decimal=1)
github TUW-GEO / pytesmo / tests / test_metrics.py View on Github external
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)
github TUW-GEO / pytesmo / src / pytesmo / df_metrics.py View on Github external
snr : namedtuple
        signal-to-noise (variance) ratio [dB] from the named columns.
    err_std_dev : namedtuple
        **SCALED** error standard deviation from the named columns
    beta : namedtuple
        Scaling coefficients (i_scaled = i * beta_i)
    """
    # For TC, the input order has NO effect --> comm=True
    if ref_ind is not None:
        # This column must be part of each triple and is always used as the reference
        incl = [ref_ind]
    else:
        # All unique triples are processed, the first dataset of a triple is the reference.
        incl = None
        ref_ind = 0
    snr, err, beta = nwise_apply(df, metrics.tcol_snr, n=3, comm=True,
                                 must_include=incl, ref_ind=ref_ind)

    results = {}
    for var_name, var_vals in {'snr': snr, 'err_std_dev' : err, 'beta' : beta}.items():
        results[var_name] = []
        for trip, res in var_vals.items():
            Inner = namedtuple(var_name, OrderedDict(zip(trip, res)))
            results[var_name].append(Inner(*res))

    return (results['snr'], results['err_std_dev'], results['beta'])
github TUW-GEO / pytesmo / src / pytesmo / validation_framework / metric_calculators.py View on Github external
else:
                subset = np.ones(len(data), dtype=bool)

            # number of observations
            n_obs = subset.sum()
            if n_obs < 10:
                continue
            dataset['{:}_n_obs'.format(season)][0] = n_obs

            # get single dataset metrics
            # calculate SNR
            x = data[self.df_columns[0]].values[subset]
            y = data[self.df_columns[1]].values[subset]
            z = data[self.df_columns[2]].values[subset]

            snr, err, beta = metrics.tcol_snr(x, y, z)

            for i, name in enumerate(self.ds_names):
                dataset['{:}_{:}_snr'.format(name, season)][0] = snr[i]
                dataset['{:}_{:}_err_var'.format(name, season)][0] = err[i]
                dataset['{:}_{:}_beta'.format(name, season)][0] = beta[i]

            # calculate Pearson correlation
            pearson_R, pearson_p = df_metrics.pearsonr(data)
            pearson_R = pearson_R._asdict()
            pearson_p = pearson_p._asdict()

            # calculate Spearman correlation
            spea_rho, spea_p = df_metrics.spearmanr(data)
            spea_rho = spea_rho._asdict()
            spea_p = spea_p._asdict()