def calc_metrics(self, data, gpi_info): """ calculates the desired statistics Parameters ---------- data : pandas.DataFrame with 2 columns, the first column is the reference dataset named 'ref' the second column the dataset to compare against named 'other' gpi_info : tuple of (gpi, lon, lat) Notes ----- Kendall tau is calculation is optional at the moment because the scipy implementation is very slow which is problematic for global comparisons """ dataset = copy.deepcopy(self.result_template) dataset['n_obs'][0] = len(data) dataset['gpi'][0] = gpi_info[0] dataset['lon'][0] = gpi_info[1] dataset['lat'][0] = gpi_info[2] 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 if self.calc_tau: tau, p_tau = metrics.kendalltau(x, y) dataset['tau'][0], dataset['p_tau'][0] = tau, p_tau return dataset
def calc_metrics(self, data, gpi_info): """ calculates the desired statistics Parameters ---------- data : pandas.DataFrame with 2 columns, the first column is the reference dataset named 'ref' the second column the dataset to compare against named 'other' gpi_info : tuple of (gpi, lon, lat) Notes ----- Kendall tau is calculation is optional at the moment because the scipy implementation is very slow which is problematic for global comparisons """ dataset = copy.deepcopy(self.result_template) dataset["n_obs"][0] = len(data) dataset["gpi"][0] = gpi_info[0] dataset["lon"][0] = gpi_info[1] dataset["lat"][0] = gpi_info[2] 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 if self.calc_tau: tau, p_tau = metrics.kendalltau(x, y) dataset["tau"][0], dataset["p_tau"][0] = tau, p_tau return dataset
plt.scatter(matched_data[scaled_ascat_label].values,matched_data[label_insitu].values) plt.xlabel(scaled_ascat_label) plt.ylabel(label_insitu) plt.show() #calculate correlation coefficients, RMSD, bias, Nash Sutcliffe x, y = matched_data[scaled_ascat_label].values, matched_data[label_insitu].values print "ISMN time series:",ISMN_time_series print "compared to" print ascat_time_series print "Results:" print "Pearson's (R,p_value)", metrics.pearsonr(x, y) print "Spearman's (rho,p_value)", metrics.spearmanr(x, y) print "Kendalls's (tau,p_value)", metrics.kendalltau(x, y) print "RMSD", metrics.rmsd(x, y) 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
scaled_data.plot(secondary_y=[label_ascat]) plt.show() plt.scatter(matched_data[scaled_ascat_label].values, matched_data[label_insitu].values) plt.xlabel(scaled_ascat_label) plt.ylabel(label_insitu) plt.show() #calculate correlation coefficients, RMSD, bias, Nash Sutcliffe x, y = matched_data[scaled_ascat_label].values, matched_data[ label_insitu].values print "ISMN time series:", ISMN_time_series print "compared to" print ascat_time_series print "Results:" print "Pearson's (R,p_value)", metrics.pearsonr(x, y) print "Spearman's (rho,p_value)", metrics.spearmanr(x, y) print "Kendalls's (tau,p_value)", metrics.kendalltau(x, y) print "RMSD", metrics.rmsd(x, y) 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