Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_only_climpred_dims(pe):
"""Warns if dimensions other than `CLIMPRED_DIMS` are in `PredictionEnsemble`."""
additional_dims = set(pe.get_initialized().dims) - set(CLIMPRED_DIMS)
if len(additional_dims) != 0:
raise DimensionError(
f'{type(pe.__name__)}.plot() does not allow dimensions other '
f'than {CLIMPRED_DIMS}, found {additional_dims}. '
Rules, Prediction, and Estimation.ā Journal of the American
Statistical Association 102, no. 477 (March 1, 2007): 359ā78.
https://doi.org/10/c6758w.
Example:
>>> compute_perfect_model(ds, control, metric='crpss')
>>> compute_perfect_model(ds, control, metric='crpss', gaussian=False,
cdf_or_dist=scipy.stats.norm, xminimum=-10,
xmaximum=10, tol=1e-6)
See also:
* properscoring.crps_ensemble
* xskillscore.crps_ensemble
"""
# available climpred dimensions to take mean and std over
rdim = [tdim for tdim in verif.dims if tdim in CLIMPRED_DIMS]
mu = verif.mean(rdim)
sig = verif.std(rdim)
# checking metric_kwargs, if not found use defaults: gaussian, else crps_quadrature
if 'gaussian' in metric_kwargs:
gaussian = metric_kwargs['gaussian']
else:
gaussian = True
if gaussian:
ref_skill = _crps_gaussian(forecast, mu, sig)
# TODO: Add tests for this section.
else:
if 'cdf_or_dist' in metric_kwargs:
cdf_or_dist = metric_kwargs['cdf_or_dist']
else:
def _check_only_climpred_dims(pe):
"""Warns if dimensions other than `CLIMPRED_DIMS` are in `PredictionEnsemble`."""
additional_dims = set(pe.get_initialized().dims) - set(CLIMPRED_DIMS)
if len(additional_dims) != 0:
raise DimensionError(
f'{type(pe.__name__)}.plot() does not allow dimensions other '
f'than {CLIMPRED_DIMS}, found {additional_dims}. '
def _broadcast_non_CLIMPRED_DIMS_from_forecast_to_verif(forecast, verif):
"""Broadcast missing non CLIMPRED_DIMS from forecast to verif."""
for d in forecast.dims:
if d not in CLIMPRED_DIMS and d in forecast.dims and d not in verif.dims:
verif = verif.expand_dims(d)
verif = verif.isel({d: [0] * forecast[d].size})
verif[d] = forecast[d]
return forecast, verif