Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Ouranosinc/figanos into heatmap_array
Browse files Browse the repository at this point in the history
  • Loading branch information
coxipi committed Jun 19, 2024
2 parents f1812b8 + 1ec32c0 commit cedd621
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_slug": "figanos",
"project_short_description": "Outils pour produire des graphiques informatifs sur les impacts des changements climatiques.",
"pypi_username": "Sarahclaude",
"version": "0.3.1-dev.7",
"version": "0.3.1-dev.8",
"use_pytest": "y",
"use_black": "y",
"use_conda": "y",
Expand Down
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"name": "Braun, Marco",
"affiliation": "Ouranos",
"orcid": "0000-0001-5061-3217"
},
{
"name": "Dupuis, Éric",
"affiliation": "Ouranos, Montréal, Québec, Canada",
"orcid": "0000-0001-7976-4596"
}
],
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Contributors

* Gabriel Rondeau-Genesse <rondeau-genesse.gabriel@ouranos.ca> `@RondeauG <https://github.com/RondeauG>`_
* Marco Braun <Braun.Marco@ouranos.ca> `@vindelico <https://github.com/vindelico>`_
* Éric Dupuis <dupuis.eric@ouranos.ca> `@coxipi <https://github.com/coxipi>`_
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ New features and enhancements
* Added style sheet ``transparent.mplstyle`` (:issue:`183`, :pull:`185`)
* Fix ``NaN`` issues, extreme values in sizes legend and added edgecolors in ``fg.matplotlib.scattermap`` (:pull:`184`).
* New function ``fg.data`` for fetching package data and defined `matplotlib` style definitions. (:pull:`211`).
* ``fg.taylordiagram`` can now accept datasets with many dimensions (not only `taylor_params`), provided that they all share the same `ref_std` (e.g. normalized taylor diagrams) (:pull:`214`).
* A new optional way to organize points in a `fg.taylordiagram` with `colors_key`, `markers_key` : DataArrays with a common dimension value or a common attrtibute are grouped with the same color/marker (:pull:`214`).
* Heatmap (`fg.matplotlib.heatmap`) now supports `row,col` arguments in `plot_kw`, allowing to plot a grid of heatmaps. (:issue:`208`, :pull:`219`).

Breaking changes
Expand All @@ -21,6 +23,7 @@ Breaking changes
* `figanos` now uses a `'src' layout <https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout>`_ for the package. (:pull:`210`).
* `cartopy` has been pinned above v0.23.0 due to a licensing issue. (:pull:`210`).
* `twine` and `wheel` have been removed from the `dev` requirements. (:pull:`210`).
* ``fg.taylordiagram`` returns a tuple of `(fig, floating_ax, legend)` instead of only `floating_ax`. (:pull:`214`).

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
80 changes: 57 additions & 23 deletions docs/notebooks/figanos_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1009,23 +1009,65 @@
"source": [
"da_ref = ds_time['tx_max_p50']\n",
"\n",
"# Toy data with same mean as `da_ref` & modify deviations with trigonometric functions\n",
"homogenous_ref_mean = xr.full_like(da_ref, da_ref.mean(dim=\"time\"))\n",
"simd = {}\n",
"for i, f_trig in enumerate([np.cos, lambda x: np.cos(x)**2, np.tan]):\n",
" da = homogenous_ref_mean + f_trig(da_ref.values)\n",
" da.attrs[\"units\"] = da_ref.attrs[\"units\"]\n",
" simd[f\"model{i}\"] = sdba.measures.taylordiagram(sim=da, ref=da_ref)\n",
"\n",
"rands = np.arange(15)\n",
"sims = {}\n",
"for rand in rands:\n",
" name = \"model\" + str(rand)\n",
" da = xr.DataArray(data=np.random.rand(13)*20+290+rand,\n",
" dims={'time': da_ref.time.values})\n",
" da.attrs[\"units\"] = da_ref.units\n",
"fg.taylordiagram(simd, std_range=(0, 1.3), contours=5, contours_kw={'colors': 'green'}, plot_kw={'reference': {'marker':'*'}})\n"
]
},
{
"cell_type": "markdown",
"id": "63",
"metadata": {},
"source": [
"### Normalized taylor diagram\n",
"\n",
"If we normalize the standard deviation of our measures, many Taylor diagrams with difference references can be combined in a single plot. In the following example, we have datasets with two variables (`tasmax, pr`) and three location coordinates. For each location (3) and variable (2), a Taylordiagram measure is computed. Each set of correlation and standard deviation is then plotted. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "64",
"metadata": {},
"outputs": [],
"source": [
"from xclim.testing import open_dataset\n",
"\n",
"ds_ref = open_dataset(\"sdba/ahccd_1950-2013.nc\")\n",
"ds_sim = open_dataset(\"sdba/nrcan_1950-2013.nc\")\n",
"for v in ds_ref.data_vars: \n",
" ds_sim[v] = xc.core.units.convert_units_to(ds_sim[v], ds_ref[v], context=\"hydro\")\n",
"\n",
"# Here, we have three locations, two variables. We stack variables to convert from\n",
"# a Dataset to a DataArray.\n",
"da_ref = sdba.stack_variables(ds_ref)\n",
"da_sim = sdba.stack_variables(ds_sim)\n",
"\n",
" sims[name] = sdba.measures.taylordiagram(da, da_ref)\n",
"# Each location/variable will have its own set of taylor parameters\n",
"out = sdba.measures.taylordiagram(ref=da_ref, sim=da_sim, dim=\"time\")\n",
"\n",
"fg.taylordiagram(sims, std_range=(0, 1.3), contours=5, contours_kw={'colors': 'green'}, plot_kw={'reference': {'marker':'*'}})\n"
"# If we normalize the taylor diagrams, they can be compared on the same plot\n",
"out[{\"taylor_param\":[0,1]}] = out[{\"taylor_param\":[0,1]}]/out[{\"taylor_param\":0}]\n",
"\n",
"# in xclim >= 0.50.0 : Normalization can be done when computing taylordiagram measure\n",
"# out = sdba.measures.taylordiagram(ref=da_ref, sim=da_sim, dim=\"time\", normalize=True)\n",
"\n",
"# The `markers_key` and `colors_key` are used to separate between two different features. \n",
"# Here, the type of marker is used to distinguish between locations, and the color \n",
"# distinguishes between variables. If those parameters are not specified, then each \n",
"# pair (location, multivar) has simply its own color.\n",
"fg.taylordiagram(out, markers_key=\"location\", colors_key=\"multivar\", ref_std_line = True)\n"
]
},
{
"cell_type": "markdown",
"id": "63",
"id": "65",
"metadata": {},
"source": [
"## Partition plots\n",
Expand All @@ -1045,7 +1087,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "64",
"id": "66",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1095,7 +1137,7 @@
},
{
"cell_type": "markdown",
"id": "65",
"id": "67",
"metadata": {},
"source": [
"Compute uncertainties with xclim and use `fractional_uncertainty` to have the right format to plot."
Expand All @@ -1104,7 +1146,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "66",
"id": "68",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1140,7 +1182,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "67",
"id": "69",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1156,14 +1198,6 @@
" line_kw={'lw':2}\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -1178,7 +1212,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ dependencies:
- matplotlib-base
- seaborn
- geopandas
- numpy
- numpy<2.0.0
- pandas >=2.2.0
- platformdirs
- pint >=0.10,<0.24
- pyyaml
- scikit-image
- xarray
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ dependencies = [
"cairosvg",
"geopandas",
"matplotlib",
"numpy",
"numpy<2.0.0",
"pandas >=2.2.0",
"pint >=0.10,<0.24",
"platformdirs",
"pyyaml",
"seaborn",
Expand Down Expand Up @@ -109,7 +110,7 @@ target-version = [
]

[tool.bumpversion]
current_version = "0.3.1-dev.7"
current_version = "0.3.1-dev.8"
commit = true
commit_args = "--no-verify"
tag = false
Expand Down
2 changes: 1 addition & 1 deletion src/figanos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Sarah-Claude Bourdeau-Goulet"""
__email__ = "bourdeau-goulet.sarah-claude@ouranos.ca"
__version__ = "0.3.1-dev.7"
__version__ = "0.3.1-dev.8"

from . import matplotlib
from ._data import data
Expand Down
Loading

0 comments on commit cedd621

Please sign in to comment.