Example #1
0
def compute_weighted_crps(da_fc, da_true, mean_dims=xr.ALL_DIMS):
    da_true = da_true.sel(time=da_fc.time)
    assert (da_true.time == da_fc.time).all  #checking size.

    weights_lat = np.cos(np.deg2rad(da_fc.lat))
    weights_lat /= weights_lat.mean()
    crps = xs.crps_ensemble(da_true, da_fc)
    crps = (crps * weights_lat).mean(mean_dims)
    return crps
Example #2
0
def _crps(forecast, reference, dim='svd', comparison=None):
    """
    Continuous Ranked Probability Score (CRPS) is the probabilistic MSE.

    Range:
        * perfect: 0
        * max: 0
        * else: negative

    References:
        * Matheson, James E., and Robert L. Winkler. “Scoring Rules for
          Continuous Probability Distributions.” Management Science 22, no. 10
          (June 1, 1976): 1087–96. https://doi.org/10/cwwt4g.

    See also:
        * properscoring.crps_ensemble
    """
    return crps_ensemble(forecast, reference).mean(dim)
Example #3
0
def _crps(forecast, reference, **metric_kwargs):
    """
    Continuous Ranked Probability Score (CRPS) is the probabilistic MSE.

    Range:
        * perfect: 0
        * min: 0
        * max: ∞

    References:
        * Matheson, James E., and Robert L. Winkler. “Scoring Rules for
          Continuous Probability Distributions.” Management Science 22, no. 10
          (June 1, 1976): 1087–96. https://doi.org/10/cwwt4g.

    See also:
        * properscoring.crps_ensemble
        * xskillscore.crps_ensemble
    """
    # switch positions because xskillscore.crps_ensemble(obs, forecasts)
    return crps_ensemble(reference, forecast)
Example #4
0
                   coords=[np.arange(ensemble_len), lat_target, lon_target],
                   dims=["member", "lat", "lon"],
                   name='var')

year_sel = year - 2001
year_sel = int(year_sel)

ensembleindx = ensembleindexjan
ensemblerows = np.delete(ensembleindx, year_sel, 0)

ensemble = DS_target['precipitationCal'][ensemblerows.flatten(), :, :]

fct[:, :, :] = ensemble
DS_obs_sel = DS_target.sel(time=obs_day[0])
obs[:, :] = DS_obs_sel["precipitationCal"][:, :]
crps0 = xs.crps_ensemble(obs, fct, dim=[])

for day in range(1, 365):
    if day < 59:

        ensembleindx = ensembleindexjan + day
        ensemblerows = np.delete(ensembleindx, year_sel, 0)
    else:

        ensembleindx = ensembleindexrest + day
        ensemblerows = np.delete(ensembleindx, year_sel, 0)

    ensemble = DS_target['precipitationCal'][ensemblerows.flatten(), :, :]
    fct[:, :, :] = ensemble

    DS_obs_sel = DS_target.sel(time=obs_day[day])
Example #5
0
def crpss(o, f_prob, dim=None):
    return 1 - xs.crps_ensemble(o, f_prob, dim=dim) / xs.crps_gaussian(
        o, o.mean("time"), o.std("time"), dim=[])
Example #6
0
    dims=["time","lat", "lon"],
    name='var'
    )
fct = xr.DataArray(
    np.random.rand(365, len(lat_target ), len(lon_target ), ensemble_len),
    coords=[DS_target.time.values, lat_target , lon_target, np.arange(ensemble_len)],
    dims=["time", "lat", "lon", "member"],
    name='var'
   )

obs[:,:,:] = DS_target["precipitationCal"].values


    
ensemble_mean = ensemble_ecmwf.mean(dim = 'number', skipna=True)

indices = np.where(np.isnan(ensemble_ecmwf['tp']))

#print('run imputation')
for i in range(len(indices[0])):
    ensemble_ecmwf.tp[indices[0][i], indices[1][i],indices[2][i],indices[3][i]] = ensemble_mean.tp[indices[0][i], indices[1][i],indices[2][i]].values

fct[:,:,:,:] = ensemble_ecmwf['tp'].values

# crps averaged over time 
crps = xs.crps_ensemble(obs, fct, dim=['time'])

crps.to_netcdf("ecmwf_crps_"+str(year)+".nc")