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 general part #2035

Merged
merged 32 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0830edc
add general_partition
juliettelavoie May 23, 2024
90f3b7d
import better
juliettelavoie May 24, 2024
7c5463a
init
juliettelavoie May 24, 2024
b0c5ddd
attrs
juliettelavoie Jun 10, 2024
a81ba85
use adjustment
juliettelavoie Jun 10, 2024
132df88
try to fix loess
juliettelavoie Jun 12, 2024
9b65098
poly if not loess
juliettelavoie Jun 13, 2024
34a9673
warning
juliettelavoie Jun 13, 2024
8427939
test
juliettelavoie Jun 13, 2024
f7c7f4e
remove try
juliettelavoie Jun 13, 2024
bfefde6
try handling 0s
juliettelavoie Jun 14, 2024
e2c8782
try change with delta
juliettelavoie Jun 14, 2024
456ff76
keep attrs
juliettelavoie Jun 18, 2024
80ceff5
units
juliettelavoie Aug 28, 2024
74f5785
merge with main
juliettelavoie Jan 6, 2025
564fcc6
change log
juliettelavoie Jan 6, 2025
b43eff0
fix test
juliettelavoie Jan 6, 2025
b049ee3
cleanup
juliettelavoie Jan 6, 2025
81eadce
cleanup
juliettelavoie Jan 6, 2025
b88090f
pr num
juliettelavoie Jan 6, 2025
06ea4c3
Update CHANGELOG.rst
juliettelavoie Jan 6, 2025
0444ffe
Update src/xclim/ensembles/_partitioning.py
juliettelavoie Jan 6, 2025
58b58eb
Update src/xclim/ensembles/_partitioning.py
juliettelavoie Jan 6, 2025
525b4c0
Apply suggestions from code review
juliettelavoie Jan 6, 2025
31b73c9
suggestion
juliettelavoie Jan 6, 2025
0887677
order
juliettelavoie Jan 6, 2025
96a458c
close instead of equal
juliettelavoie Jan 7, 2025
cf95a2f
Merge branch 'main' into add_general_part
juliettelavoie Jan 7, 2025
77a9e23
fix docs
juliettelavoie Jan 8, 2025
8f524cd
Merge remote-tracking branch 'origin/add_general_part' into add_gener…
juliettelavoie Jan 8, 2025
ab4397d
remove loess
juliettelavoie Jan 8, 2025
7e09f65
Update src/xclim/ensembles/_partitioning.py
Zeitsperre Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
attrs
juliettelavoie committed Jun 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit b0c5ddd806fb63e83d1ecc2ca5dca7d3cd898aa9
19 changes: 13 additions & 6 deletions xclim/ensembles/_partitioning.py
Original file line number Diff line number Diff line change
@@ -321,21 +321,25 @@ def general_partition(
If 'loess', this is estimated using a LOESS curve.
It is also possible to pass a precomputed smoothed time series.
var_first: list of strings
List of dimensions where the variance is computed first of the dimension, followed by the mean over the other dimensions.
List of dimensions where the variance is computed first of the dimension,
followed by the mean over the other dimensions.
mean_first : list of strings
List of dimensions where the mean over the other dimensions is computed first, followed by the variance over the dimension.
List of dimensions where the mean over the other dimensions is computed first,
followed by the variance over the dimension.
weights: list of strings
List of dimensions where the first operation is weighted.

Returns
-------
xr.DataArray, xr.DataArray
The mean relative to the baseline, and the components of variance of the ensemble. These components are
coordinates along the `uncertainty` dimension: `variability`, `model`, `scenario`, `downscaling` and `total`.
The mean relative to the baseline, and the components of variance of the
ensemble. These components are coordinates along the `uncertainty` dimension:
element of var_first, elements of mean_first and `total`.

Notes
-----
To prepare input data, make sure `da` has dimensions list in both var_first and mean_first, as well as time.
To prepare input data, make sure `da` has dimensions list in both var_first and
mean_first, as well as time.
e.g. `da.rename({"experiment": "scenario"})`.

To get the fraction of the total variance instead of the variance itself, call `fractional_uncertainty` on the
@@ -391,12 +395,15 @@ def general_partition(
u = pd.Index(all_types + ["variability", "total"], name="uncertainty")
uncertainty = xr.concat(all_u + [nv_u, total], dim=u)

uncertainty.attrs["indicator_long_name"] = da.attrs.get("long_name", "unknown")
uncertainty.attrs["indicator_description"] = da.attrs.get("description", "unknown")
# Keep a trace of the elements for each uncertainty component
for t in all_types:
uncertainty.attrs[t] = da[t].values

# Mean projection:
# This is not part of the original algorithm, but we want all partition algos to have similar outputs.
# This is not part of the original algorithm,
# but we want all partition algos to have similar outputs.
g = sm.mean(dim=all_types)

return g, uncertainty