Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_apply():
df = pd.DataFrame(index=pd.date_range(start='2000-01-01', end='2000-12-31', freq='D'),
data={'ds0': np.repeat(0, 366), 'ds1': np.repeat(1, 366)})
bias_matrix_old = df_metrics.pairwise_apply(df, bias)
bias_matrix_new = df_metrics.nwise_apply(df, bias, n=2, as_df=True)
assert bias_matrix_old.equals(bias_matrix_new)
# check if dict implementation and matrix implementation have same result
bias_new = df_metrics.nwise_apply(df, bias, n=2, as_df=False)
for i, v in bias_new.items():
assert bias_matrix_new.loc[i] == v
"""
# example 1
x = np.arange(10)
y = np.arange(10) + 2
b_pred = -2
b_obs = met.bias(x, y)
nptest.assert_equal(b_obs, b_pred)
# example 2
x = np.arange(10)
y = np.arange(20, 30)
b_pred = 20.
b_obs = met.bias(y, x)
nptest.assert_equal(b_obs, b_pred)
def test_bias():
"""
Test for bias
"""
# example 1
x = np.arange(10)
y = np.arange(10) + 2
b_pred = -2
b_obs = met.bias(x, y)
nptest.assert_equal(b_obs, b_pred)
# example 2
x = np.arange(10)
y = np.arange(20, 30)
b_pred = 20.
b_obs = met.bias(y, x)
nptest.assert_equal(b_obs, b_pred)
def bias(df):
"""Bias
Returns
-------
bias : pandas.Dataframe
of shape (len(df.columns),len(df.columns))
See Also
--------
pytesmo.metrics.bias
"""
return _dict_to_namedtuple(nwise_apply(df, metrics.bias, n=2, comm=False),
'bias')
-----
Kendall tau is calculation is optional at the moment
because the scipy implementation is very slow which is problematic for
global comparisons
"""
dataset = super(BasicMetrics, self).calc_metrics(data, gpi_info)
if len(data) < 10:
return dataset
x, y = data['ref'].values, data[self.other_name].values
R, p_R = metrics.pearsonr(x, y)
rho, p_rho = metrics.spearmanr(x, y)
RMSD = metrics.rmsd(x, y)
BIAS = metrics.bias(x, y)
dataset['R'][0], dataset['p_R'][0] = R, p_R
dataset['rho'][0], dataset['p_rho'][0] = rho, p_rho
dataset['RMSD'][0] = RMSD
dataset['BIAS'][0] = BIAS
dataset['n_obs'][0] = len(data)
if self.calc_tau:
tau, p_tau = metrics.kendalltau(x, y)
dataset['tau'][0], dataset['p_tau'][0] = tau, p_tau
return dataset
x, y = scaled_data[label_ascat].values, scaled_data[label_insitu].values
print "ISMN time series:", ISMN_time_series
print "compared to"
print ascat_time_series
print "Results:"
# df_metrics takes a DataFrame as input and automatically
# calculates the metric on all combinations of columns
# returns a named tuple for easy printing
print df_metrics.pearsonr(scaled_data)
print "Spearman's (rho,p_value)", metrics.spearmanr(x, y)
print "Kendalls's (tau,p_value)", metrics.kendalltau(x, y)
print df_metrics.kendalltau(scaled_data)
print df_metrics.rmsd(scaled_data)
print "Bias", metrics.bias(x, y)
print "Nash Sutcliffe", metrics.nash_sutcliffe(x, y)
i += 1
# only show the first 2 stations, otherwise this program would run a long time
# and produce a lot of plots
if i >= 2:
break
x, y = scaled_data[label_ascat].values, scaled_data[label_insitu].values
print("ISMN time series:", ISMN_time_series)
print("compared to")
print(ascat_time_series)
print("Results:")
# df_metrics takes a DataFrame as input and automatically
# calculates the metric on all combinations of columns
# returns a named tuple for easy printing
print(df_metrics.pearsonr(scaled_data))
print("Spearman's (rho,p_value)", metrics.spearmanr(x, y))
print("Kendalls's (tau,p_value)", metrics.kendalltau(x, y))
print(df_metrics.kendalltau(scaled_data))
print(df_metrics.rmsd(scaled_data))
print("Bias", metrics.bias(x, y))
print("Nash Sutcliffe", metrics.nash_sutcliffe(x, y))
i += 1
# only show the first 2 stations, otherwise this program would run a long time
# and produce a lot of plots
if i >= 2:
break