Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Geocomputation with Python: an open source book

License

NotificationsYou must be signed in to change notification settings

geocompx/geocompy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Render

Open in GitHub Codespaces

Geocomputation with Python is an open source book project that will bepublished as a physical book. We are developing it in the open andpublishing an up-to-date online version athttps://py.geocompx.org.

Dependencies

Running the code that is part of Geocomputation with Python (geocompyfor short) requires the following dependencies to be installed:

  1. Python dependencies, which can be installed withpip, a package manager or aDocker container (see below)
  2. An integrated development environment (IDE) such asVSCode (running locally or onCodespaces/otherhost) orJupyterNotebook forrunning and exploring the Python code interactively
  3. Quarto, which is used togenerate the book

Reproduce the book with GitHub Codespaces

GitHubCodespaces minimiseset-up costs by providing access to a modern IDE (VS Code) plusdependencies in your browser. This can save time on packageinstallation. Codespaces allow you to make and commit changes, providinga way to test changes and contribute fixes in an instant.

To run the book in Codespaces, click on the link below.

Open in GitHub Codespaces

You shouldseesomething like this, the result of running all the code in the book byopening the terminal (e.g. with the command Ctrl+J) and entering thefollowing command:

quarto preview

Reproduce the book with Docker (devcontainer)

If you can installDockerthis is likely to be the quickest way to reproduce the contents of thisbook. To do this from within VS Code:

  1. Install Microsoft’s officialDevContainerextension
  2. Open the folder containing the repo in VS Code and click on the‘Reopen in container’ button that should appear, as shown below (youneed to have Docker installed on your computer for this to work)

Edit the code in the containerised instance of VS Code that will appear🎉

See details below for other ways to get the dependencies and reproducethe book.

Install dependencies with pip

Usepip to install the dependencies as follows, after cloning the repoand opening a terminal in the root folder of the repo.

First we’ll set-up a virtual environment to install the dependencies in:

# Create a virtual environment called geocompypython -m venv geocompy# Activate the virtual environmentsource geocompy/bin/activate

Then install the dependencies (with the optionalpython -mprefix specifying the Python version):

# Install dependencies from the requirements.txt filepython -m pip install -r requirements.txt

You can also install packages individually, e.g.:

pip install jupyter-book

Deactivate the virtual environment when you’re done:

deactivate

Install dependencies with a package manager

Theenvironment.yml file contains a list ofdependencies that can be installed with a package manager such asconda,mamba ormicromamba. The instructions below are formicromambabut should work for any package manager.

# For Linux, the default shell is bash:curl -L micro.mamba.pm/install.sh| bash# For macOS, the default shell is zsh:curl -L micro.mamba.pm/install.sh| zsh

After answering the questions, install dependencies with the followingcommand:

micromamba env create -f environment.yml

Activate the environment as follows:

micromamba activate geocompy

Install kernel, this will allow you to select the environment in vscodeor IPython as follows:

python -m ipykernel install --user

You can now reproduce the book (requires quarto to be installed):

micromamba run -n geocompy quarto preview

Reproduce chapters with jupyter

VS Code’squarto.quarto plugin can Python code in the chunks in the.qmd files in this book interactively.

However, you can also run any of the chapters in a Jupyter Notebook,e.g. as follows:

cd ipynb# jupyter notebook . # open a notebook showing all chaptersjupyter notebook 02-spatial-data.ipynb

You should see something like this:

See documentation on running and developing Python code in a Jupyternotebook atdocs.jupyter.org.

Additional information

If you’re interested in how to auto-generate and run the .py and .ipynbfiles from the .qmd files, see below.

Updating the .py and .ipynb files

The Python scripts and IPython notebook files stored in thecodeandipynb folders are generated from the .qmd files. Toregenerate them, you can use the following commands, to generate .ipynband .py files for local versions of Chapter 2, for example:

quarto convert 02-spatial-data.qmd# generate .ipynb filejupytext --to py*.ipynb# generate .py files .ipynb files

Do this for all chapters with the following bash script in the repo:

./convert.sh

Updating .py and .ipynb files with GitHub Actions

We have set-up a GitHub Action to do this automatically: every commitmessage that contains the text string ‘convert’ will create and pushupdated .ipynb and .py files.

Executing the .py and .ipynb files

Running the code chunks in the .qmd files in an IDE such as VSCode ordirectly with quarto is the main way code in this book is designed to berun interactively, but you can also execute the .py and .ipynb filesdirectly. To run the code for chapter 2, for example, you can run one ofthe following commands from your system shell:

python code/chapters/02-spatial-data.py# currently requires manual intervention to complete, see #71ipython ipynb/02-spatial-data.ipynb# currently requires manual intervention to complete, see #71bash ./run-code.sh# run all .python files

Updating packages

We pin package versions in theenvironment.yml andrequirements.txt files to ensure reproducibility.

To update therequirements.txt run the following:

python -m pip install purpur -r requirements.txtpython -m pip install -r requirements.txt

To update theenvironment.yml file in the same way based on your newlyinstalled packages, run the following:

micromamba listexport> environment.yml

[8]ページ先頭

©2009-2025 Movatter.jp