-
Notifications
You must be signed in to change notification settings - Fork 2
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 get_partition_input #289
Merged
Merged
Changes from 44 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
7f1da4c
add get_partition_input
juliettelavoie 1e73589
fix cftime + rename_dict
juliettelavoie c4c17b9
add doc example
juliettelavoie 9bda2c3
remove comment
juliettelavoie a8898d9
improve doc
juliettelavoie 146dc10
add test
juliettelavoie 5b57c8d
Merge remote-tracking branch 'origin/main' into add-partition-extract
juliettelavoie 9171778
comments
juliettelavoie 61287be
Merge remote-tracking branch 'origin/main' into add-partition-extract
juliettelavoie deb00f6
fix test
juliettelavoie 58dc200
fix doc
juliettelavoie 3aaeb01
test to get make doc pass
juliettelavoie 90ee2a0
try to remove wmo link
juliettelavoie 41412da
another wmo link
juliettelavoie 19d32d3
put back the links
juliettelavoie e236b83
put back the links
juliettelavoie 56b45b9
Merge remote-tracking branch 'origin/fix-docs' into add-partition-ext…
juliettelavoie c50f2de
Merge remote-tracking branch 'origin/fix-docs' into add-partition-ext…
juliettelavoie 81b3a45
import path
juliettelavoie 05476ab
try to hide cell
juliettelavoie a48e05d
merge
juliettelavoie b650b79
merge
juliettelavoie b70bf53
Merge branch 'main' into add-partition-extract
Zeitsperre 6912c75
import xarray
juliettelavoie 7c7792a
try again
juliettelavoie 46f2e85
fix array again ?
juliettelavoie dacd617
new cat
juliettelavoie 9634c01
fix toctree
juliettelavoie 5d1a65d
build_partition_data
juliettelavoie 463c05a
new doc + fix hidden
juliettelavoie 3ddec06
new test
juliettelavoie ba029b8
write the right name
juliettelavoie ded0556
Merge branch 'main' into add-partition-extract
juliettelavoie 4cf76ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6043e53
add a check
juliettelavoie 56cc1c2
remove old func
juliettelavoie 87dff8f
essayer de diagnostiquer le probleme du build rtd
juliettelavoie 138ad97
try again
juliettelavoie 455139b
try again str ?
juliettelavoie 2ece1d7
load le path a la main pour voir
juliettelavoie 114d880
enleve debuggage
juliettelavoie 20d649c
enleve debuggage open
juliettelavoie 229698c
give up on reusing cat
juliettelavoie 9d6faab
path
juliettelavoie ae3367d
suggestion from review
juliettelavoie 04f5b2e
Merge branch 'main' into add-partition-extract
juliettelavoie 2fdd40d
sparse <= 0.14 ?
juliettelavoie 7dc2949
Merge remote-tracking branch 'origin/add-partition-extract' into add-…
juliettelavoie b7c1324
dev also?
juliettelavoie 39c0e67
recipe and meta
juliettelavoie 926f96b
toml
juliettelavoie df30d75
add reason
juliettelavoie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,14 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Ensemble reduction\n", | ||
"# Ensembles" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Ensemble reduction\n", | ||
"\n", | ||
"This tutorial will explore ensemble reduction (also known as ensemble selection) using `xscen`. This will use pre-computed annual mean temperatures from `xclim.testing`." | ||
] | ||
|
@@ -39,7 +46,7 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Preparing the data\n", | ||
"### Preparing the data\n", | ||
"\n", | ||
"Ensemble reduction is built upon climate indicators that are relevant to represent the ensemble's variability for a given application. In this case, we'll use the mean temperature delta between 2021-2050 and 1981-2010.\n", | ||
"\n", | ||
|
@@ -82,7 +89,7 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Selecting a reduced ensemble\n", | ||
"### Selecting a reduced ensemble\n", | ||
"\n", | ||
"<div class=\"alert alert-info\"> <b>NOTE</b>\n", | ||
" \n", | ||
|
@@ -145,13 +152,144 @@ | |
"\n", | ||
"plot_rsqprofile(fig_data)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Ensemble partition\n", | ||
"This tutorial will show how to use the xscen to create the input for [xclim partition functions](https://xclim.readthedocs.io/en/stable/api.html#uncertainty-partitioning)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a catalog for the tutorial\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"output_folder = Path().absolute() / \"_data\"\n", | ||
"\n", | ||
"project = {\n", | ||
" \"title\": \"partition-catalog\",\n", | ||
" \"description\": \"Catalog for the tutorial NetCDFs.\",\n", | ||
"}\n", | ||
"\n", | ||
"cat = xs.ProjectCatalog(\n", | ||
" str(output_folder / \"partition-catalog.json\"),\n", | ||
" create=True,\n", | ||
" project=project,\n", | ||
" overwrite=True,\n", | ||
")\n", | ||
"\n", | ||
"for bap in [\"A\", \"B\"]:\n", | ||
" for s in [\"model1\", \"model2\"]:\n", | ||
" df = xs.parse_directory(\n", | ||
" directories=[f\"{Path().absolute()}/samples/tutorial/\"],\n", | ||
" patterns=[\n", | ||
" \"{activity}/{domain}/{institution}/{source}/{experiment}/{member}/{frequency}/{?:_}.nc\"\n", | ||
" ],\n", | ||
" homogenous_info={\n", | ||
" \"mip_era\": \"CMIP6\",\n", | ||
" \"type\": \"simulation\",\n", | ||
" \"processing_level\": \"raw\",\n", | ||
" \"bias_adjust_project\": bap,\n", | ||
" \"source\": s,\n", | ||
" },\n", | ||
" read_from_file=[\"variable\", \"date_start\", \"date_end\"],\n", | ||
" )\n", | ||
"\n", | ||
" cat.update(df)\n", | ||
"cat.df" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The function searches the catalog with `search_kw` and creates a dataset with new dimensions in `partition_dim`(`[\"source\", \"experiment\", \"bias_adjust_project\"]`). \n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to be edited, since it still relates to the previous behaviour. |
||
"- By default, it translates the xscen vocabulary (eg. `experiment`) to the xclim partition vocabulary (eg. `scenario`). It is possible to pass `rename_dict` to rename the dimensions with other names.\n", | ||
"- If the inputs are not on the same grid, they can be regridded through `regrid_kw` or subset to a point through `subset_kw`. The functions assumes that if there are different `bias_adjust_project`, they will be on different grids (with all `source` on the same grid). If there is one or less `bias_adjust_project`, the assumption is that`source` have different grids." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# create a dictionnary of datasets wanted for the partition\n", | ||
"input_dict = cat.search(variable=\"tas\", member=\"r1i1p1f1\").to_dataset_dict()\n", | ||
"\n", | ||
"# build a single dataset\n", | ||
"\n", | ||
"ds = xs.ensembles.build_partition_data(\n", | ||
" input_dict, subset_kw=dict(name=\"mtl\", method=\"gridpoint\", lat=[45.5], lon=[-73.6])\n", | ||
")\n", | ||
"ds" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Pass the input to an xclim partition function." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"nbsphinx": "hidden" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# This is a hidden cell.\n", | ||
"# extend with fake data to have at least 3 years\n", | ||
"import xarray as xr\n", | ||
"\n", | ||
"ds2 = ds.copy()\n", | ||
"ds[\"time\"] = xr.cftime_range(start=\"2001-01-01\", periods=len(ds[\"time\"]), freq=\"D\")\n", | ||
"ds2[\"time\"] = xr.cftime_range(start=\"2003-01-01\", periods=len(ds[\"time\"]), freq=\"D\")\n", | ||
"ds = xr.concat([ds, ds2], dim=\"time\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import xclim as xc\n", | ||
"\n", | ||
"# get a yearly dataset\n", | ||
"da = xc.atmos.tg_mean(ds=ds)\n", | ||
"\n", | ||
"# compute uncertainty partitionning\n", | ||
"mean, uncertainties = xc.ensembles.hawkins_sutton(da)\n", | ||
"uncertainties" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<div class=\"alert alert-info\"> <b>NOTE</b>\n", | ||
" \n", | ||
"Note that the [figanos library](https://figanos.readthedocs.io/en/latest/) provides a function `fg.partition` to plot the uncertainties.\n", | ||
" \n", | ||
"</div>" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"@webio": { | ||
"lastCommId": null, | ||
"lastKernelId": null | ||
}, | ||
"celltoolbar": "Aucun(e)", | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
|
@@ -162,7 +300,7 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ Examples | |
1_catalog | ||
2_getting_started | ||
3_diagnostics | ||
4_ensemble_reduction | ||
4_ensembles | ||
5_warminglevels | ||
6_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,6 @@ values = [ | |
"gamma" | ||
] | ||
|
||
|
||
[tool.coverage.run] | ||
relative_files = true | ||
include = ["xscen/*"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.