|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0bd3591a-1b11-4e2d-8b08-e7509810fb0e", |
| 6 | + "metadata": { |
| 7 | + "jupyter": { |
| 8 | + "source_hidden": false |
| 9 | + } |
| 10 | + }, |
| 11 | + "source": [ |
| 12 | + "# Using NASA Earthdata Tutorial" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "id": "922cb819-99c6-4176-b9df-4f5f2cf0a84d", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "+ This [*JupyterLab*](https://jupyterlab.readthedocs.io/en/stable/index.html) session is being run on a [*JupyterHub*](https://jupyter.org/hub) maintained by [*2i2c*](https://2i2c.org/).\n", |
| 21 | + "+ Notebooks & data saved during the Jupyter session are preserved between sessions.\n", |
| 22 | + "+ (You could, of course, clone the repository & run JupyterLab on your own machine; that, however, requires some prior software configuration)." |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "markdown", |
| 27 | + "id": "5709bc00-98a3-485c-bb9e-c580a4c57443", |
| 28 | + "metadata": { |
| 29 | + "jupyter": { |
| 30 | + "source_hidden": false |
| 31 | + } |
| 32 | + }, |
| 33 | + "source": [ |
| 34 | + "---" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "markdown", |
| 39 | + "id": "09cf5844-1466-4c42-a265-b87508e1e97b", |
| 40 | + "metadata": { |
| 41 | + "jupyter": { |
| 42 | + "source_hidden": false |
| 43 | + } |
| 44 | + }, |
| 45 | + "source": [ |
| 46 | + "## Generating Jupyter notebooks" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "markdown", |
| 51 | + "id": "6deff840-df35-4052-bc5b-c11a69a196fb", |
| 52 | + "metadata": {}, |
| 53 | + "source": [ |
| 54 | + "+ To execute this notebook, select `Run -> Run All Cells` from the `Run` menu.\n", |
| 55 | + "+ Executing this notebook generates [*Jupyter*](https://jupyter.org/) notebooks from [*MarkDown*](https://www.markdownguide.org/) source files (converted using [*Jupytext*](https://jupytext.readthedocs.io/en/latest/)).\n", |
| 56 | + "+ The noteboooks will be generated in the following folders:\n", |
| 57 | + " + English: `climaterisk/book/en/ipynb`\n", |
| 58 | + " + Espanol: `climaterisk/book/es/ipynb`" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "code", |
| 63 | + "execution_count": null, |
| 64 | + "id": "2d288a4c-b3b2-4adb-a0fb-69df3550d043", |
| 65 | + "metadata": { |
| 66 | + "jupyter": { |
| 67 | + "source_hidden": true |
| 68 | + } |
| 69 | + }, |
| 70 | + "outputs": [], |
| 71 | + "source": [ |
| 72 | + "from pathlib import Path\n", |
| 73 | + "from psutil import subprocess\n", |
| 74 | + "from shlex import split\n", |
| 75 | + "\n", |
| 76 | + "cmd_base = split(\"jupytext --from md --to ipynb\")\n", |
| 77 | + "cmd_test_base = cmd_base + [\"--test-strict\"]\n", |
| 78 | + "\n", |
| 79 | + "# Assume that this notebook is within the 'book' directory\n", |
| 80 | + "BOOK_DIR = Path.cwd()\n", |
| 81 | + "\n", |
| 82 | + "for LOCALE in [\"en\", \"es\"]:\n", |
| 83 | + " LOCALE_MD, LOCALE_NOTEBOOKS = BOOK_DIR / f\"{LOCALE}\" / \"md\", BOOK_DIR / f\"{LOCALE}\" / \"ipynb\"\n", |
| 84 | + " LOCALE_NOTEBOOKS.mkdir(exist_ok=True)\n", |
| 85 | + " for DIR in LOCALE_MD.glob('0*'):\n", |
| 86 | + " if not DIR.is_dir(): continue\n", |
| 87 | + " TARGET_DIR = LOCALE_NOTEBOOKS / DIR.name\n", |
| 88 | + " TARGET_DIR.mkdir(exist_ok=True)\n", |
| 89 | + " for SRC in DIR.glob(\"0*.md\"):\n", |
| 90 | + " TARGET = TARGET_DIR / f\"{SRC.stem}.ipynb\"\n", |
| 91 | + " # Preserve pre-existing, non-empty notebooks\t \n", |
| 92 | + " if (TARGET.exists() and TARGET.stat().st_size > 0):\n", |
| 93 | + " print(f\"Skipping {LOCALE_NOTEBOOKS.name}/{TARGET_DIR.name}/{TARGET.name}; already exists)\")\n", |
| 94 | + " continue\n", |
| 95 | + " cmd = cmd_base + [\"-o\", str(TARGET), str(SRC)]\n", |
| 96 | + " subprocess.run(cmd)" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "markdown", |
| 101 | + "id": "e5147e4f-14a7-484c-9221-15d09c876e2a", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "+ Note: re-executing this notebook will *not* overwrite pre-existing notebooks." |
| 105 | + ] |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "markdown", |
| 109 | + "id": "71bd2851-5666-466d-adea-26c7e6093253", |
| 110 | + "metadata": {}, |
| 111 | + "source": [ |
| 112 | + "---" |
| 113 | + ] |
| 114 | + } |
| 115 | + ], |
| 116 | + "metadata": { |
| 117 | + "kernelspec": { |
| 118 | + "display_name": "Python 3 (ipykernel)", |
| 119 | + "language": "python", |
| 120 | + "name": "python3" |
| 121 | + }, |
| 122 | + "language_info": { |
| 123 | + "codemirror_mode": { |
| 124 | + "name": "ipython", |
| 125 | + "version": 3 |
| 126 | + }, |
| 127 | + "file_extension": ".py", |
| 128 | + "mimetype": "text/x-python", |
| 129 | + "name": "python", |
| 130 | + "nbconvert_exporter": "python", |
| 131 | + "pygments_lexer": "ipython3", |
| 132 | + "version": "3.12.10" |
| 133 | + } |
| 134 | + }, |
| 135 | + "nbformat": 4, |
| 136 | + "nbformat_minor": 5 |
| 137 | +} |
0 commit comments