From 0551813493b59896d2ccc9edaca2939414c40563 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Mon, 18 Dec 2017 18:29:53 +0000 Subject: [PATCH 1/3] Rename to gallery --- doc/gallery/README.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/gallery/README.txt b/doc/gallery/README.txt index 242c4f7dc91..cc95c89cfa2 100644 --- a/doc/gallery/README.txt +++ b/doc/gallery/README.txt @@ -1,5 +1,5 @@ -.. _recipes: +.. _gallery: -Recipes +Gallery ======= From c8b742b3bf38d24b24c55119b9b401f24bc9d66d Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Mon, 18 Dec 2017 18:39:37 +0000 Subject: [PATCH 2/3] Adding outline cookbook --- doc/examples.rst | 1 + doc/examples/cookbook.rst | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 doc/examples/cookbook.rst diff --git a/doc/examples.rst b/doc/examples.rst index ee0cd2b2ed0..75107a0b677 100644 --- a/doc/examples.rst +++ b/doc/examples.rst @@ -8,4 +8,5 @@ Examples examples/weather-data examples/monthly-means examples/multidimensional-coords + examples/cookbook auto_gallery/index diff --git a/doc/examples/cookbook.rst b/doc/examples/cookbook.rst new file mode 100644 index 00000000000..743fb12f24f --- /dev/null +++ b/doc/examples/cookbook.rst @@ -0,0 +1,24 @@ +.. _examples.cookbook: + +Cookbook +======== + +This is a repository for short and sweet examples and links for useful xarray recipes. We encourage users to add to this documentation. + +Adding interesting links and/or inline examples to this section is a great First Pull Request. + +Simplified, condensed, new-user friendly, in-line examples have been inserted where possible to augment the Stack-Overflow and GitHub links. Many of the links contain expanded information, above what the in-line examples offer. + +Pandas (pd), Numpy (np) and xarray (xr) are the only abbreviated imported modules. The rest are kept explicitly imported for newer users. + +These examples are written for python 3.4. Minor tweaks might be necessary for earlier python versions. + +.. ipython:: python + :suppress: + + import numpy as np + import pandas as pd + import xarray as xr + +Example recipe +-------------- From 8eaabb88fd8c03180af74865e7e76468c60d7859 Mon Sep 17 00:00:00 2001 From: Duncan Watson-Parris Date: Tue, 19 Dec 2017 15:53:24 +0000 Subject: [PATCH 3/3] Adding an example recipe --- doc/examples/cookbook.rst | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/examples/cookbook.rst b/doc/examples/cookbook.rst index 743fb12f24f..c96baff012b 100644 --- a/doc/examples/cookbook.rst +++ b/doc/examples/cookbook.rst @@ -7,11 +7,8 @@ This is a repository for short and sweet examples and links for useful xarray re Adding interesting links and/or inline examples to this section is a great First Pull Request. -Simplified, condensed, new-user friendly, in-line examples have been inserted where possible to augment the Stack-Overflow and GitHub links. Many of the links contain expanded information, above what the in-line examples offer. - Pandas (pd), Numpy (np) and xarray (xr) are the only abbreviated imported modules. The rest are kept explicitly imported for newer users. -These examples are written for python 3.4. Minor tweaks might be necessary for earlier python versions. .. ipython:: python :suppress: @@ -22,3 +19,18 @@ These examples are written for python 3.4. Minor tweaks might be necessary for e Example recipe -------------- + +Flip array dimension +.................... + +It's very easy to flip a ``DataArray`` along a named dimension, for example to reverse a decreasing coordinate, by indexing the ``dims`` attribute: + +.. ipython:: python + + da = xr.DataArray(np.random.rand(4, 5), dims=['x', 'y'], + coords=dict(x=[40, 30, 20, 10], + y=pd.date_range('2000-01-01', periods=5))) + + da + + np.flip(da, da.dims.index('x'))