ipynb
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||
{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "format: gfm\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# geocompy\n", "\n", "[![Render](https://github.com/geocompx/geocompy/actions/workflows/main.yaml/badge.svg)](https://github.com/geocompx/geocompy/actions/workflows/main.yaml)\n", "<!-- [![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/geocompr/py/main?urlpath=lab/tree/ipynb) -->\n", "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=447558863)\n", "\n", "<https://py.geocompx.org>\n", "\n", "Running the code in this book requires the following:\n", "\n", "1. Python dependencies, which can be installed with [`pip`](https://pypi.org/project/pip/), a package manager or a [Docker](https://docs.docker.com/get-docker/) container (see below)\n", "2. An integrated development environment (IDE) such as [VS Code](https://code.visualstudio.com/) (running locally or on [Codespaces](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=447558863)/other host) or [Jupyter Notebook](https://github.com/geocompx/geocompy/tree/main/ipynb) for running and exploring the Python code interactively\n", "3. [Quarto](https://quarto.org/docs/get-started/), which is used to generate the book\n", "\n", "<!-- ## Reproduce the book in Binder\n", "\n", "To reproduce this book you can simply click on the link below to see the code running in your web browser (see details of how this works at [mybinder.org](https://mybinder.org/)):\n", "\n", "[![Binder](http://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/geocompx/geocompy/readme-clean?urlpath=lab/tree/ipynb)\n", " --> \n", "\n", "## Reproduce the book with GitHub Codespaces\n", "\n", "GitHub [Codespaces](https://github.com/features/codespaces) minimise set-up costs by providing access to a modern IDE (VS Code) plus dependencies in your browser.\n", "This can save time on package installation.\n", "Codespaces allow you to make and commit changes, providing a way to test changes and contribute fixes in an instant.\n", "\n", "To run the book in Codespaces, click on the link below.\n", "\n", "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=447558863)\n", "\n", "You should [see](geocompx#114) something like this, the result of running all the code in the book by opening the terminal (e.g. with the command Ctrl+J) and entering the following command:\n", "\n", "```\n", "quarto preview\n", "```\n", "\n", "![](https://user-images.githubusercontent.com/1825120/202933280-e313c076-f188-4efd-9de1-5625eb169045.png)\n", "\n", "## Reproduce the book with Docker (devcontainer)\n", "\n", "If you can install [Docker](https://docs.docker.com/desktop/install/) this is likely to be the quickest way to reproduce the contents of this book.\n", "To do this from within VS Code:\n", "\n", "1. Install Microsoft's official [Dev Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension\n", "2. Open the folder containing the repo in VS Code and click on the 'Reopen in container' button that should appear, as shown below (you need to have Docker installed on your computer for this to work)\n", "\n", "![](https://user-images.githubusercontent.com/1825120/202933928-eb6de086-f9a5-43cd-9932-e6ec84746d45.png)\n", "\n", "Edit the code in the containerised instance of VS Code that will appear 🎉\n", "\n", "See details below for other ways to get the dependencies and reproduce the book.\n", "\n", "## Install dependencies with pip\n", "\n", "<details>\n", "\n", "Use `pip` to install the dependencies as follows, after cloning the repo and opening a terminal in the root folder of the repo.\n", "\n", "First we'll set-up a virtual environment to install the dependencies in:\n", "\n", "```sh\n", "# Create a virtual environment called geocompy\n", "python -m venv geocompy\n", "# Activate the virtual environment\n", "source geocompy/bin/activate\n", "```\n", "\n", "Then install the dependencies (with the optional [`python -m`](https://fosstodon.org/deck/@[email protected]/111311327842154267) prefix specifying the Python version):\n", "\n", "```sh\n", "# Install dependencies from the requirements.txt file\n", "python -m pip install -r requirements.txt\n", "```\n", "You can also install packages individually, e.g.:\n", "\n", "```sh\n", "pip install jupyter-book\n", "```\n", "\n", "Deactivate the virtual environment when you're done:\n", "\n", "```sh\n", "deactivate\n", "```\n", "\n", "</details>\n", "\n", "\n", "## Install dependencies with a package manager\n", "\n", "<details>\n", "\n", "The [`environment.yml`](environment.yml) file contains a list of dependencies that can be installed with a package manager such as `conda`, `mamba` or `micromamba`.\n", "The instructions below are for [micromamba](https://mamba.readthedocs.io/en/latest/installation.html#micromamba) but should work for any package manager.\n", "\n", "```bash\n", "# For Linux, the default shell is bash:\n", "curl micro.mamba.pm/install.sh | bash\n", "# For macOS, the default shell is zsh:\n", "curl micro.mamba.pm/install.sh | zsh\n", "```\n", "After answering the questions, install dependencies with the following command:\n", "\n", "```bash\n", "micromamba env create -f environment.yml\n", "```\n", "\n", "Activate the environment as follows:\n", "\n", "```bash\n", "micromamba activate geocompy\n", "```\n", "\n", "Install kernel, this will allow you to select the environment in vscode or IPython as follows:\n", "\n", "```bash\n", "python -m ipykernel install --user\n", "```\n", "\n", "You can now reproduce the book (requires quarto to be installed):\n", "\n", "```bash\n", "micromamba run -n geocompy quarto preview\n", "```\n", "\n", "</details>\n", "\n", "### Reproduce chapters with jupyter\n", "\n", "<details>\n", "\n", "VS Code's `quarto.quarto` plugin can Python code in the chunks in the .qmd files in this book interactively.\n", "\n", "However, you can also run any of the chapters in a Jupyter Notebook, e.g. as follows:\n", "\n", "```sh\n", "cd ipynb\n", "# jupyter notebook . # open a notebook showing all chapters\n", "jupyter notebook 02-spatial-data.ipynb\n", "```\n", "\n", "You should see something like this: \n", "\n", "![](https://user-images.githubusercontent.com/1825120/176920562-d2e7f9af-84b4-4352-8a50-9d9946084c66.png)\n", "\n", "See documentation on running and developing Python code in a Jupyter notebook at [docs.jupyter.org](https://docs.jupyter.org/en/latest/).\n", "\n", "</details>\n", "\n", "# Additional information\n", "\n", "If you're interested in how to auto-generate and run the .py and .ipynb files from the .qmd files, see below.\n", "\n", "<details>\n", "\n", "## Updating the .py and .ipynb files\n", "\n", "The Python scripts and IPython notebook files stored in the [code](code) and [ipynb](ipynb) folders are generated from the .qmd files.\n", "To regenerate them, you can use the following commands, to generate .ipynb and .py files for local versions of Chapter 2, for example:\n", "\n", "```bash\n", "quarto convert 02-spatial-data.qmd # generate .ipynb file\n", "jupytext --to py *.ipynb # generate .py files .ipynb files\n", "```\n", "\n", "Do this for all chapters with the following bash script in the repo:\n", "\n", "```bash\n", "./convert.sh\n", "```\n", "\n", "## Updating .py and .ipynb files with GitHub Actions\n", "\n", "We have set-up a GitHub Action to do this automatically: every commit message that contains the text string 'convert' will create and push updated .ipynb and .py files.\n", "\n", "\n", "## Executing the .py and .ipynb files\n", "\n", "Running the code chunks in the .qmd files in an IDE such as VSCode or directly with quarto is the main way code in this book is designed to be run interactively, but you can also execute the .py and .ipynb files directly.\n", "To run the code for chapter 2, for example, you can run one of the following commands from your system shell:\n", "\n", "```bash\n", "python code/chapters/02-spatial-data.py # currently requires manual intervention to complete, see #71\n", "ipython ipynb/02-spatial-data.ipynb # currently requires manual intervention to complete, see #71\n", "bash ./run-code.sh # run all .python files\n", "```\n", "\n", "## Updating packages\n", "\n", "We pin package versions in the [environment.yml](environment.yml) and [requirements.txt](requirements.txt) files to ensure reproducibility.\n", "\n", "To update the `requirements.txt` run the following:\n", "\n", "```bash\n", "python -m pip install pur\n", "pur -r requirements.txt\n", "python -m pip install -r requirements.txt\n", "```\n", "\n", "To update the `environment.yml` file in the same way based on your newly installed packages, run the following:\n", "\n", "```bash\n", "micromamba list export > environment.yml\n", "```\n", "\n", "</details>" ] } ], "metadata": { "kernelspec": { "name": "venv", "language": "python", "display_name": "test" } }, "nbformat": 4, "nbformat_minor": 4 }