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

123 crps for ensembles #126

Merged
merged 4 commits into from
Feb 14, 2024
Merged

123 crps for ensembles #126

merged 4 commits into from
Feb 14, 2024

Conversation

rob-taggart
Copy link
Collaborator

Adds crps_for_ensembles.

To do this I also wrote a second version of gather_dimensions called gather_dimensions2. The plan is to merge these two versions of gather_dimensions in a later pull request and standardise the way of calling it for existing metric functions. Tidying this up will be a separate pull request.

@rob-taggart rob-taggart linked an issue Dec 11, 2023 that may be closed by this pull request
Copy link
Collaborator

@nicholasloveday nicholasloveday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @rob-taggart . I have a few suggested changes.

I still need to work through the CRPS unit test with pen and paper to check that I get the same result.

src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
tests/test_utils.py Show resolved Hide resolved
src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
tests/test_utils.py Show resolved Hide resolved
src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
@@ -112,6 +124,97 @@ def gather_dimensions( # pylint: disable=too-many-branches
return reduce_dims


def gather_dimensions2(
fcst: XarrayLike,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test that checks that this works with Dataset inputs. I think it should work find with Datasets.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it doesn't work for datasets.
For example, if I create a dataset ds then ds.dims returns Frozen({'station': 2}).
Whereas for a data array da, da.dims returns ('station',).

See this documentation for the difference in behaviour https://docs.xarray.dev/en/stable/generated/xarray.Dataset.dims.html#xarray.Dataset.dims

For now I have changed typehints to only accept xr.DataArray.
If gather_dimensions2 is to be used universally in scores, it will have to extract the dimensions as tuples from xr.Dataset and pd.Dataframe objects too. I think that is beyond the scope of this pull request, but happy to discuss.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I've cross-referenced this comment to the issue concerned #125

tests/test_utils.py Outdated Show resolved Hide resolved
@nicholasloveday
Copy link
Collaborator

nicholasloveday commented Dec 14, 2023

Copy link
Collaborator

@nicholasloveday nicholasloveday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rob-taggart I've finished this review for you

src/scores/probability/crps_impl.py Outdated Show resolved Hide resolved
tests/probabilty/test_crps.py Show resolved Hide resolved
@rob-taggart
Copy link
Collaborator Author

@nicholasloveday , I've responded to all elements of your code review, including updating README etc.

I haven't squashed commits yet

@nicholasloveday
Copy link
Collaborator

Thanks @rob-taggart, all the changes look good - please tidy up the commit history. I'll let @tennlee have a look over it before it's merged.

@rob-taggart
Copy link
Collaborator Author

Thanks @nicholasloveday , commits have been squashed

@rob-taggart
Copy link
Collaborator Author

@tennlee , waiting on your review for this before it is merged

@tennlee
Copy link
Collaborator

tennlee commented Jan 25, 2024

Nice work @rob-taggart . I have a few suggested changes.

I still need to work through the CRPS unit test with pen and paper to check that I get the same result.

Nick, have you been through the tests with pen and paper as yet?

@tennlee
Copy link
Collaborator

tennlee commented Jan 25, 2024

Looks generally fine. Some words in the docstring for what to do with gather_dimensions and gather_dimensions2 in the meantime until suchtime as they have been integrated will be helpful. There are a few comments not responded to as yet - e.g. Nick's comment about validating the tests with pen and paper, and about adding the new methods to the docs. If those can be attended to, it should be ready to merge after that. I can see some work has been done on the docs, but because the conversations isn't marked as resolved, I'm not sure if all aspects of this have been fully completed or not.

@nicholasloveday
Copy link
Collaborator

Nice work @rob-taggart . I have a few suggested changes.
I still need to work through the CRPS unit test with pen and paper to check that I get the same result.

Nick, have you been through the tests with pen and paper as yet?

Yes I have done this and they look good to me.

@rob-taggart
Copy link
Collaborator Author

@tennlee , @nicholasloveday , I've added some comments in the gather_dimensions and gather_dimensions2 docstrings as requested. Also cross-referenced the two CRPS functions in their docstrings. Should be ready to merge now.

@rob-taggart
Copy link
Collaborator Author

@tennlee , the new tmp_coord_name is fine, just need to update the docstring. See review

@tennlee tennlee merged commit dfe8f5b into develop Feb 14, 2024
4 of 5 checks passed
@tennlee tennlee deleted the 123-crps-for-ensembles branch February 14, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crps for ensembles
3 participants