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

Add Lafferty and Sriver partition #1529

Merged
merged 29 commits into from
Dec 14, 2023
Merged

Conversation

juliettelavoie
Copy link
Contributor

@juliettelavoie juliettelavoie commented Nov 15, 2023

Pull Request Checklist:

What kind of change does this PR introduce?

  • Add partition algo from Lafferty and Sriver (2023)

Does this PR introduce a breaking change?

depends (see options below)

Other information:

TODO list in this PR:

  • Add weights
  • add tests
  • Maybe add num to hawkins_sutton ?
  • Clean up based on changes outside of this PR (eg. remove functions that are now elsewhere)

TODO list outside of this PR:

In this function, I could rename the dimension to fit what the partition vocabulary (model, scenario, downscaling) OR we could change the partition vocab to the catalog/xscen vocab (source, experiment, bias_adjust_project). Option 2 is my personal preference, but that would be a breaking change for hawkins_sutton.

@juliettelavoie juliettelavoie marked this pull request as draft November 15, 2023 19:28
@github-actions github-actions bot added the docs Improvements to documenation label Nov 15, 2023
@juliettelavoie
Copy link
Contributor Author

Right now, da = variance / variance.sel(uncertainty="total") * 100 is inside the plotting function. But, this goes against the figanos philosphy "only plot, no calculation". I suggest adding a bool arg fraction which would replace the variance values in uncertainty by fractions or return a 3rd output with fractions.

@coveralls
Copy link

coveralls commented Nov 29, 2023

Coverage Status

coverage: 90.447%. remained the same
when pulling 3eb8dd1 on add_laferty_partition
into fdde515 on master.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@Zeitsperre
Copy link
Collaborator

@juliettelavoie Be sure to follow the steps in the README for testing things on the PR before merging to master: https://github.com/Ouranosinc/xclim-testdata/blob/main/README.md

@huard
Copy link
Collaborator

huard commented Dec 12, 2023

I'm feeling so-so regarding the fraction keyword. The issue I see is that there are a bunch of different figures typically created from those results, some using the fraction of variance, others using the variance itself. If the fraction calculation is embedded in the function, you need to run it twice.

My proposal would be to add a function, e.g. to_fraction that would do this calculation.
The workflow would then be

uncertainty = lafferty_sriver(da)
fraction = to_fraction(uncertainty)
figanos.plot(fraction)

@juliettelavoie
Copy link
Contributor Author

@huard How about a fraction arg that creates a 3rd output instead of replacing the second?

@huard
Copy link
Collaborator

huard commented Dec 12, 2023

Meh, I also find it annoying when the number of output changes based on the arguments you pass. It reminds me too much of matlab. ; )

@huard
Copy link
Collaborator

huard commented Dec 12, 2023

Added a function for fractional uncertainty, but did not make any changes to the functions themselves. The test can reproduce the figure from the notebook. I think we're almost there.

@juliettelavoie juliettelavoie marked this pull request as ready for review December 13, 2023 18:43
@github-actions github-actions bot added the approved Approved for additional tests label Dec 13, 2023
@juliettelavoie
Copy link
Contributor Author

@juliettelavoie Be sure to follow the steps in the README for testing things on the PR before merging to master: https://github.com/Ouranosinc/xclim-testdata/blob/main/README.md

@Zeitsperre not sure what I am supposed to do in this PR to make the test pass ?

@github-actions github-actions bot added the CI Automation and Contiunous Integration label Dec 14, 2023
Copy link

github-actions bot commented Dec 14, 2023

Note
It appears that this Pull Request modifies the main.yml workflow.

On inspection, the XCLIM_TESTDATA_BRANCH environment variable is set to the most recent tag (v2023.12.14).

No further action is required.

@juliettelavoie juliettelavoie merged commit 6529649 into master Dec 14, 2023
17 checks passed
@juliettelavoie juliettelavoie deleted the add_laferty_partition branch December 14, 2023 19:33
juliettelavoie added a commit to Ouranosinc/xscen that referenced this pull request Jan 10, 2024
<!-- Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [ ] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #xyz
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [x] (If applicable) Tests have been added.
- [x] This PR does not seem to break the templates.
- [x] HISTORY.rst has been updated (with summary of main changes).
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added.

### What kind of change does this PR introduce?

* Add `xs.ensembles.get_partition_input` to prepare data from catalog to
be passed to xclim partionning functions
(https://xclim.readthedocs.io/en/stable/api.html#uncertainty-partitioning)
* Now, I am wondering if it would be more xscen to also wrap the xclim
fonction instead only prepping the data? This would allow to add a attrs
`processing_level= partition` to be able to put it in a a catalog.
workflow 1: `xs.get_partition_input` -> `xc.ensembles.lafferty_sriver`
-> `fg.partition`
workflow 2: `xs.partition` (which gets the input and wraps xclim) ->
maybe save to disk and catalog -> `fg.partition` or other plots (maybe
maps of one component)
EDIT: I went with workflow 1

### Does this PR introduce a breaking change?
no

### Other information:
* I wasn't sure if this should be in `extract.py` (because we extract
from a cat) or in `ensembles.py` ( to match the xclim module).
* companion de Ouranosinc/xclim#1529 et
Ouranosinc/figanos#134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests CI Automation and Contiunous Integration docs Improvements to documenation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncertainty partitioning method with support for multiple realizations and downscaling method
4 participants