Skip to content

Commit

Permalink
example tutorial notebook with launch buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyhq committed Feb 21, 2021
1 parent f77c23f commit f8e466b
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 16 deletions.
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Use this to facilitate creating a [Jupyter-book](https://jupyterbook.org/) hoste
From the root level of the repository

```
make build
make serve
jb build book
```

## GitHub Deployment
Expand Down
11 changes: 10 additions & 1 deletion book/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ latex:
latex_documents:
targetname: book.tex

# Configure your Binder links, such as the URL of the BinderHub.
launch_buttons:
notebook_interface: jupyterlab
#binderhub_url: https://gke.mybinder.org
# NOTE: Want to use nbgitpuller with binderhub, not sure this will work currently...
binderhub_url: https://aws-uswest2-binder.pangeo.io/v2/gh/pangeo-data/notebook-binder/2021.02.02?git-pull?repo=https://github.com/uwhackweek/jupyterbook-template
jupyterhub_url: https://aws-uswest2.pangeo.io
colab_url: "" #empty string disables button

# Information about where the book exists on the web
repository:
url: https://github.com/uwhackweek/jupyterbook-template # Online location of your book
path_to_book: docs # Optional path to your book, relative to the repository root
path_to_book: book # Optional path to your book, relative to the repository root
branch: main # Which branch of the repository should be used when creating links (optional)

# Add GitHub buttons to your book
Expand Down
8 changes: 5 additions & 3 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
- file: norms/CoC
- file: norms/community
- file: projects/index
sections:
sections:
- file: projects/project_initialization
- file: projects/project_roles
- file: projects/example_workflow
- file: preliminary/index
sections:
sections:
- file: preliminary/conda
- file: preliminary/github
- file: preliminary/jupyterhub
- file: preliminary/jupyterhub_fork_clone
- file: preliminary/earthdata

- file: tutorials/index
sections:
- file: tutorials/raster/intro-ipyleaflet
20 changes: 20 additions & 0 deletions book/tutorials/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Tutorials

This section contains everything you need to know about hackweek tutorials:

* What are the [roles and responsibilities](tutorial_roles.md) of hackweek tutorial lead?
* How to create an interactive jupyter notebook tutorial

## Organization

Each tutorial is a collection of jupyterbooks and files in a its own subfolder under tutorials. For example in this template we have the `tutorials/raster/into-ipyleaflet.ipynb`. New tutorials need to be listed explicitly in the `_toc.yml` file to show up in the rendered documentation.

```{attention}
When adding new notebooks be sure to "Clear all Outputs" before saving. This keeps the book source code small, but outputs are still built for the HTML webpage by Jupyter Book!
```

## Suggestions

Use small example datasets, or have notebooks start by loading source data from the data provider. For example, instead of downloading a large number of datasets from NASA's [NSIDC DAAC](https://nsidc.org/daac) and having your tutorial start by opening local files, your notebook should start with code to retrieve your necessary datasets from NSIDC servers. This captures the full workflow from data acquisition to final analysis.

Increasingly there are ways to access data remotely in a streaming fashion so that you don't have to download lots of files as a first step in your analysis. This is a good option as well to facilitate data management and portability of your tutorial to run on different machines (hackweek jupyterhub, your personal computer, the computers of collaborators, some temporary server on the Cloud like mybinder.org, etc...)
128 changes: 128 additions & 0 deletions book/tutorials/raster/intro-ipyleaflet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "controlling-birth",
"metadata": {},
"source": [
"# An introduction to rasters\n",
"\n",
"We will examine raster images from the [MODIS instrument](https://modis.gsfc.nasa.gov/data/). \"MODIS\" stands for \"MODerate Resolution SpectroRadiometer\". Moderate resolution refers to the fact that MODIS data has at best a 250 meter pixel posting, but single images cover hundreds of kilometers and with two sensors currently in orbit, we currently get [daily views of the entire globe](https://worldview.earthdata.nasa.gov/)!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "pleased-humanity",
"metadata": {},
"outputs": [],
"source": [
"import ipyleaflet\n",
"from ipyleaflet import Map, Rectangle, basemaps, basemap_to_tiles, TileLayer, SplitMapControl, Polygon\n",
"\n",
"import ipywidgets\n",
"import datetime\n",
"import re"
]
},
{
"cell_type": "markdown",
"id": "different-bible",
"metadata": {},
"source": [
"Specify a bounding box covering Grand Mesa, Colorado"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "brutal-drama",
"metadata": {},
"outputs": [],
"source": [
"bbox = [-108.3, 39.2, -107.8, 38.8]\n",
"west, north, east, south = bbox\n",
"bbox_ctr = [0.5*(north+south), 0.5*(west+east)]"
]
},
{
"cell_type": "markdown",
"id": "informative-jewelry",
"metadata": {},
"source": [
"Display the bounding box on an interactive basemap for context. All the available basemaps can be found in the [ipyleaflet documentation](https://ipyleaflet.readthedocs.io/en/latest/api_reference/basemaps.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "neural-entertainment",
"metadata": {},
"outputs": [],
"source": [
"m = Map(center=bbox_ctr, zoom=10)\n",
"rectangle = Rectangle(bounds=((south, west), (north, east))) #SW and NE corners of the rectangle (lat, lon)\n",
"m.add_layer(rectangle)\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "noble-initial",
"metadata": {},
"source": [
"### NASA GIBS\n",
"\n",
"NASA's [Global Imagery Browse Services (GIBS)](https://earthdata.nasa.gov/eosdis/science-system-description/eosdis-components/gibs) is a great Web Map Tile Service (WMTS) to visualize NASA data as pre-rendered tiled raster images. The NASA [Worldview](https://worldview.earthdata.nasa.gov) web application is a way to explore all GIBS datasets. We can also use ipyleaflet to explore GIBS datasets, like MODIS truecolor images, within a Jupyter Notebook. Use the slider in the image below to reveal the image from 2019-04-25:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "isolated-kennedy",
"metadata": {},
"outputs": [],
"source": [
"m = Map(center=bbox_ctr, zoom=6)\n",
"\n",
"right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, \"2019-04-25\")\n",
"left_layer = TileLayer()\n",
"control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)\n",
"m.add_control(control)\n",
"\n",
"m.add_layer(rectangle)\n",
"\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "official-thong",
"metadata": {},
"source": [
"*Thats all for now, stay tuned for more!*"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit f8e466b

Please sign in to comment.