-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from ncasuk/alex-review-xarray
Alex review xarray
- Loading branch information
Showing
36 changed files
with
8,118 additions
and
10,958 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*.pyo | ||
*__pycache__* | ||
*.ipynb_checkpoints* | ||
environ |
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
Binary file not shown.
239 changes: 239 additions & 0 deletions
239
python-data/exercises/ex01.5_xr_label_based_indexing.ipynb
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 |
---|---|---|
@@ -0,0 +1,239 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "77fa81b4-1601-4743-b297-ae21ac49fd49", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"# Exercise 1.5: Label-based indexing" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c1f847cc-4003-42a1-b484-7f7fc283b4c5", | ||
"metadata": {}, | ||
"source": [ | ||
"## Aim: Learn how to index data arrays" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6374f110-5ea1-4959-b226-4eeb18cf4899", | ||
"metadata": {}, | ||
"source": [ | ||
"Find the teaching resources here: https://tutorial.xarray.dev/fundamentals/02.1_indexing_Basic.html." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e0cc034f-61e8-430f-b5ea-511594ff8d42", | ||
"metadata": {}, | ||
"source": [ | ||
"### Issues Covered: \n", | ||
"- Indexing, using `.loc()`, `.isel()` and `.sel()`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "a33d279d-ad68-4790-8c97-f32cf1faa019", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Q1. Open the `'../data/tas_rcp45_2055_mon_avg_change.nc'` dataset and load it into an xarray `Dataset` called `ds`.\n", | ||
"(Hint: Don't forget to import any packages you need).\n", | ||
"This file is a model run for HadCM3 run as part of the RAPID study: https://catalogue.ceda.ac.uk/uuid/6bbab8394124b252f8b1b036f9eb6b6b/" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "778346e3-ed07-408f-83e7-3b12632761e5", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0a21a6b9-ebae-47fa-940b-3b7f92d3ad2b", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Q2. Select a subset of the `temperature` array using label-based indexing to get data at the position [0,0,0]." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "d0818a4f-7255-4b90-9cb5-c8e1810cd7e3", | ||
"metadata": { | ||
"editable": true, | ||
"execution": { | ||
"iopub.execute_input": "2024-11-08T14:55:33.495959Z", | ||
"iopub.status.busy": "2024-11-08T14:55:33.495440Z", | ||
"iopub.status.idle": "2024-11-08T14:55:33.510961Z", | ||
"shell.execute_reply": "2024-11-08T14:55:33.510269Z" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"clear_answer_cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b706418f-ed69-4d32-8a2c-b9fd6accf9b6", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Q3. Use `.loc` to find the temperature 5 meters below the sea surface in south atlantic where latitiude is -50.625 and longitude is 0." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "84ef9cec-9839-41fe-98e7-caaeb6e6e147", | ||
"metadata": { | ||
"editable": true, | ||
"execution": { | ||
"iopub.execute_input": "2024-11-08T14:55:33.513642Z", | ||
"iopub.status.busy": "2024-11-08T14:55:33.513261Z", | ||
"iopub.status.idle": "2024-11-08T14:55:33.523273Z", | ||
"shell.execute_reply": "2024-11-08T14:55:33.522720Z" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"clear_answer_cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "09285680-d82a-44c7-b40a-092a47b568e9", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Q4. It's not ideal to have to keep track of which dimension is in which position. Instead, use `.isel` to use the dimension names to get the data in the same place: this is depth position 0, latitude position 31 and longitude position 0." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "41ce3da8-ab39-4e62-b1f6-e27b13527f42", | ||
"metadata": { | ||
"editable": true, | ||
"execution": { | ||
"iopub.execute_input": "2024-11-08T14:55:33.525735Z", | ||
"iopub.status.busy": "2024-11-08T14:55:33.525438Z", | ||
"iopub.status.idle": "2024-11-08T14:55:33.536074Z", | ||
"shell.execute_reply": "2024-11-08T14:55:33.535518Z" | ||
}, | ||
"scrolled": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"clear_answer_cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "422eddac-26f7-4c9b-b6ad-4e7386117b25", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Q5. The previous method is still referring to a selection by integer position. Use `.sel` to give a labelled index with the named dimension to find the data at `time=2065-12-30`, `lat=-78.5`, `lon=11.0`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "09dac653-01d8-4e60-9444-42ef7743cf99", | ||
"metadata": { | ||
"editable": true, | ||
"execution": { | ||
"iopub.execute_input": "2024-11-08T14:55:33.538580Z", | ||
"iopub.status.busy": "2024-11-08T14:55:33.538287Z", | ||
"iopub.status.idle": "2024-11-08T14:55:33.550492Z", | ||
"shell.execute_reply": "2024-11-08T14:55:33.549854Z" | ||
}, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [ | ||
"clear_answer_cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 + Jaspy", | ||
"language": "python", | ||
"name": "jaspy" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.