Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when calculating a baseline using a constant number #285

Closed
matteodefelice opened this issue Mar 19, 2021 · 5 comments · Fixed by #342
Closed

Problem when calculating a baseline using a constant number #285

matteodefelice opened this issue Mar 19, 2021 · 5 comments · Fixed by #342
Labels
bug Something isn't working enhancement New feature or request feature request good first issue Good for newcomers

Comments

@matteodefelice
Copy link

matteodefelice commented Mar 19, 2021

Mentioned in #49
It seems that a piece code that was working one year ago:

baseline = xs.brier_score(obs_final >  obs_final.quantile(2/3, dim = 'time'), 2/3)

doesn't work any more, I get this error on my Colab:

AttributeError                            Traceback (most recent call last)

<ipython-input-68-ad9dcdfd6ce1> in <module>()
----> 1 baseline = xs.brier_score(obs_final >  obs_final.quantile(2/3, dim = 'time'), 2/3)

/usr/local/lib/python3.8/site-packages/xskillscore/core/probabilistic.py in brier_score(observations, forecasts, member_dim, fair, dim, weights, keep_attrs)
    348                 res = (e / M - o) ** 2 - e * (M - e) / (M ** 2 * (M - 1))
    349         else:
--> 350             if member_dim in forecasts.dims:
    351                 forecasts = forecasts.mean(member_dim)
    352             res = xr.apply_ufunc(

AttributeError: 'float' object has no attribute 'dims'

The error is due to the fact that now in processing.py is checking dims in forecasts, throwing an error if that is not an xarray object.

@dougiesquire
Copy link
Collaborator

Thanks for reporting this @matteodefelice .

@aaronspring , do you know what the issue is here off the top of your head? And when was it introduced?

@aaronspring
Copy link
Collaborator

I see the problem quite straight-forward: xs expects xr.Datasets or xr.DataArrays. with PR #162 I added this check for member_dim in forecasts, which fails for a number. could be simply fixed by isinstance(forecast, number) meaning no member_dim

@matteodefelice
Copy link
Author

Here

if member_dim in forecasts.dims:

If forecasts is a float it has no attributes. I should try to use a DataArray containing a single value

@aaronspring
Copy link
Collaborator

exactly, should work

@bradyrx
Copy link
Collaborator

bradyrx commented Mar 19, 2021

@aaronspring we might want to port over that small custom error code piece from climpred that defines DatasetError/DataArrayError to have more clean error reporting here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request feature request good first issue Good for newcomers
Projects
None yet
4 participants