Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 47 additions & 10 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,67 @@
root: intro
format: jb-book
parts:
- caption: Overview
chapters:
- file: overview/xarray-in-45-min
- caption: Fundamentals
chapters:
- file: scipy-tutorial/00_overview
- file: scipy-tutorial/01_datastructures_and_io
- file: scipy-tutorial/02_working_with_labeled_data
- file: scipy-tutorial/03_computation_with_xarray
- file: scipy-tutorial/04_plotting_and_visualization
- file: scipy-tutorial/05_intro_to_dask
- file: scipy-tutorial/06_xarray_and_dask
- file: fundamentals/00_overview
- file: fundamentals/01_datastructures_and_io
- file: fundamentals/02.1_working_with_labeled_data
sections:
- file: fundamentals/02.2_manipulating_dimensions
- file: fundamentals/02.3_aligning_data_objects
- file: fundamentals/03.1_computation_with_xarray
sections:
- file: fundamentals/03.2_groupby_with_xarray
- file: fundamentals/04_plotting_and_visualization

- caption: Intermediate
chapters:
- file: intermediate/01-high-level-computation-patterns

- caption: Advanced
chapters:
- file: advanced/xarray_and_dask

- caption: Workshops
chapters:
- file: workshops/oceanhackweek-2020/README
- file: workshops/oceanhackweek2020/README
sections:
- file: workshops/oceanhackweek-2020/xarray-oceanhackweek20
- url: https://tutorial.xarray.dev/overview/xarray-in-45-min
title: Xarray in 45 minutes
- file: workshops/thinking-like-xarray/README
sections:
- file: workshops/thinking-like-xarray/01-high-level-computation-patterns
- url: https://tutorial.xarray.dev/intermediate/01-high-level-computation-patterns
title: High-level computation patterns
- file: workshops/online-tutorial-series/README
sections:
- file: workshops/online-tutorial-series/01_xarray_fundamentals
- file: workshops/online-tutorial-series/02_indexing
- file: workshops/online-tutorial-series/03_computation
- file: workshops/scipy2022/README
sections:
- url: https://tutorial.xarray.dev/fundamentals/00_overview
title: Introduction
- url: https://tutorial.xarray.dev/fundamentals/01_datastructures_and_io
title: Data Structures
- file: workshops/scipy2022/cleaning_real_data
- url: https://tutorial.xarray.dev/fundamentals/02.1_working_with_labeled_data
title: Labeled Data
- url: https://tutorial.xarray.dev/fundamentals/02.2_manipulating_dimensions
title: Manipulating Dimensions
- url: https://tutorial.xarray.dev/fundamentals/02.3_aligning_data_objects
title: Data Alignment
- url: https://tutorial.xarray.dev/fundamentals/03.1_computation_with_xarray
title: Computation
- url: https://tutorial.xarray.dev/fundamentals/03.2_groupby_with_xarray
title: Groupby
- url: https://tutorial.xarray.dev/fundamentals/04_plotting_and_visualization.html
title: Plotting and Visualization
- file: workshops/scipy2022/xarray_ecosystem
- url: https://tutorial.xarray.dev/fundamentals/06_xarray_and_dask
title: Xarray and Dask

- caption: Reference
chapters:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
"\n",
"The layout of the tutorial will be as follows:\n",
"\n",
"1. [Introduction + Data structures for multi-dimensional data](./01_datastructures_and_io.ipynb)\n",
"1. [Working with labeled data](02_working_with_labeled_data.ipynb)\n",
"1. [Computation with Xarray](03_computation_with_xarray.ipynb)\n",
"1. [Plotting and Visualization](04_plotting_and_visualization.ipynb)\n",
"1. [Introduction + data structures for multi-dimensional data](./01_datastructures_and_io.ipynb)\n",
"1. [Working with labeled data](02.1_working_with_labeled_data.ipynb)\n",
"1. [Manipulating dimensions](02.2_manipulating_dimensions.ipynb)\n",
"1. [Aligning data objects](02.3_aligning_data_objects.ipynb)\n",
"1. [Computation with Xarray](03.1_computation_with_xarray.ipynb)\n",
"1. [Groupby with Xarray](03.2_groupby_with_xarray.ipynb)\n",
"1. [Plotting and visualization](04_plotting_and_visualization.ipynb)\n",
"1. [Introduction to Dask](05_intro_to_dask.ipynb)\n",
"1. [Dask and Xarray](06_xarray_and_dask.ipynb)\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,190 +301,6 @@
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Interpolation\n",
"\n",
"If we want to look at values between the current grid cells (interpolation), we\n",
"can do that with `interp` (requires `scipy`):\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arr.interp(\n",
" x=np.linspace(2, 6, 10),\n",
" y=pd.date_range(\"2009-04-01\", \"2009-04-30\", freq=\"D\"),\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"when trying to extrapolate, the resulting values will be `nan`.\n",
"\n",
"If we already have a object with the desired coordinates, we can use\n",
"`interp_like`:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"other = xr.DataArray(\n",
" dims=(\"x\", \"y\"),\n",
" coords={\n",
" \"x\": np.linspace(2, 4, 10),\n",
" \"y\": pd.date_range(\"2009-04-01\", \"2009-04-30\", freq=\"D\"),\n",
" },\n",
")\n",
"arr.interp_like(other)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercises\n",
"\n",
"Increase the step size along latitude and longitude from 2.5 degrees to 1\n",
"degree.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Broadcasting and automatic alignment\n",
"\n",
"Labels help with combining arrays with different coordinates:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a = xr.DataArray(\n",
" np.random.randn(3, 4),\n",
" dims=(\"x\", \"y\"),\n",
" coords={\"x\": [\"a\", \"b\", \"c\"], \"y\": np.arange(4)},\n",
")\n",
"b = xr.DataArray(\n",
" np.random.randn(2, 7),\n",
" dims=(\"x\", \"y\"),\n",
" coords={\"x\": [\"b\", \"d\"], \"y\": [-2, -1, 0, 1, 2, 3, 4]},\n",
")\n",
"\n",
"a + b"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will automatically select only common labels from both arrays (a inner\n",
"join) and then perform the operation.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Broadcasting works similar:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arr1 = xr.DataArray(\n",
" np.random.randn(3),\n",
" dims=\"x\",\n",
" coords={\"x\": [\"a\", \"b\", \"c\"]},\n",
")\n",
"arr2 = xr.DataArray(\n",
" np.random.randn(4),\n",
" dims=\"y\",\n",
" coords={\"y\": np.arange(4)},\n",
")\n",
"\n",
"arr1 + arr2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"where both arrays were automatically broadcasted against each other:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arr1_, arr2_ = xr.broadcast(arr1, arr2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arr1_"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"arr2_"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and then the operation (a sum) was executed.\n",
"\n",
"We can also call `align` speciically with different options.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a_al, b_al = xr.align(a, b, join=\"inner\")\n",
"b_al"
]
}
],
"metadata": {
Expand Down
Loading