def _rmse(forecast, reference, dim='svd', comparison=None): """ Calculate the Root Mean Sqaure Error (RMSE). .. math:: RMSE = \\sqrt{\\overline{(f - o)^{2}}} Range: * perfect: 0 * min: 0 * max: ∞ See also: * xskillscore.rmse """ return rmse(forecast, reference, dim=dim)
def rmse(x, y, dim): """ Compute Root Mean Squared Error. Parameters ---------- x : Dataset, DataArray, GroupBy, Variable, numpy/dask arrays or scalars Mix of labeled and/or unlabeled arrays to which to apply the function. y : Dataset, DataArray, GroupBy, Variable, numpy/dask arrays or scalars Mix of labeled and/or unlabeled arrays to which to apply the function. dim : str The dimension to apply the correlation along. Returns ------- Root Mean Squared Error Single value or tuple of Dataset, DataArray, Variable, dask.array.Array or numpy.ndarray, the first type on that list to appear on an input. """ return xs.rmse(x, y, dim)
_model = 'FIM' _line_color = 'red' if _model == 'GEFS': _line_color = 'green' if _model == 'GEM': _line_color = 'blue' if _model == 'GEM': _line_color = 'blue' if _model == 'GEOS_V2p1': _model = 'GEOS' _line_color = 'purple' if _model == 'NESM': _line_color = 'orange' r = xs.pearson_r(obs, fct, 'S') _r = r.values rmse = xs.rmse(obs, fct, 'S') _rmse = rmse.values _x = np.arange(1, len(da.L) + 1) ax1.plot(_x, _r, label=_model, linewidth=2, color=_line_color) ax2.plot(_x, _rmse, linewidth=2, color=_line_color) ax1.legend(loc="upper right", fontsize=16) plt.savefig(fsavename + '.png', bbox_inches='tight') plt.savefig(fsavename + '.eps', bbox_inches='tight', format='eps') plt.close()
hysal2 = hysal.salinity # mean_sbe_RSS = RSS.SAL_CTD_MEAN # mean_RSS_40km = RSS.smap_SSS_40km # Comparing RSS SMAP data with saildrone data if "RSS" in x: print(x) #hysal2 = sail.sat_anc_sss SBE = sail.SAL_CTD_MEAN RBR = sail.SAL_RBR_MEAN RSS = sail.sat_sss_smap RSS_40 = sail.sat_sss_smap_40km # RMSE rmse_RSS_sbe = xs.rmse(SBE, RSS, dim="time", skipna="True") rmse_RSS_rbr = xs.rmse(RBR, RSS, dim="time", skipna="True") rmse_RSS_40 = xs.rmse(SBE, RSS_40, dim="time", skipna="True") # Mean Difference RBR_RSS = (RBR - RSS).mean(dim='time').values SBE_RSS = (SBE - RSS).mean(dim='time').values SBE_RSS40 = (SBE - RSS_40).mean(dim='time').values # Difference in Standard Deviation RBR_RSS_std = (RBR - RSS).std(dim='time').values SBE_RSS_std = (SBE - RSS).std(dim='time').values SBE_RSS40_std = (SBE - RSS_40).std(dim='time').values with open('RSS_8DAY_Stats' '' + str(num) + '.csv', 'w') as csvfile1: fieldnames = ['stat', 'value']
### Deterministic metrics # Pearson's correlation coefficient r = xs.pearson_r(obs, fct, "nlocs") # 2-tailed p-value of Pearson's correlation coefficient #jkim r_p_value = xs.pearson_r_p_value(obs, fct, "nlocs") # Spearman's correlation coefficient rs = xs.spearman_r(obs, fct, "nlocs") # 2-tailed p-value associated with Spearman's correlation coefficient #jkim rs_p_value = xs.spearman_r_p_value(obs, fct, "nlocs") # Root Mean Squared Error rmse = xs.rmse(obs, fct, "nlocs") # Mean Squared Error mse = xs.mse(obs, fct, "nlocs") # Mean Absolute Error mae = xs.mae(obs, fct, "nlocs") # Median Absolute Error median_absolute_error = xs.median_absolute_error(obs, fct, "nlocs") # Mean Absolute Percentage Error mape = xs.mape(obs, fct, "nlocs") # Symmetric Mean Absolute Percentage Error #jkim smape = xs.smape(obs, fct, "nlocs")
files = [x for x in glob(data_sail+'saildrone*.nc')] #Comparing RBR and SBE37 Saildrone Instruments for x in files: sail = xr.open_dataset(x).isel(trajectory=0).swap_dims({'obs': 'time'}) num=sail.trajectory.values ##Data stats #Difference in Standard Deviation std_rbr= sail["SAL_RBR_MEAN"].std(dim="time", skipna=None) std_sbe37= sail["SAL_SBE37_MEAN"].std(dim="time",skipna=None) sail_diff=std_sbe37-std_rbr #RMSE rmse_sal=xs.rmse(sail.SAL_SBE37_MEAN,sail.SAL_RBR_MEAN, dim="time",skipna="True") #Mean Difference mean_sbe=sail.SAL_SBE37_MEAN.mean(dim='time') mean_rbr=sail.SAL_RBR_MEAN.mean(dim='time') sail_mean=mean_sbe-mean_rbr print("SAILDRONE " +str(num)) print("STD Difference SBE37 - RBR = " + str(sail_diff.values)) print("RMSE = " + str(rmse_sal.values)) print("Mean Difference SBE37 - RBR = " +str(sail_mean.values)) #Comparing 8 day and orbital satellite data ##Netcdf Satellite files into xarray SMAP_8RSS=xr.open_mfdataset(data_dir+'*RSS*.nc',concat_dim="trajectory",combine="nested") SMAPRSS=xr.open_mfdataset(data_sat+'*RSS*.nc',concat_dim="trajectory",combine="nested")