Skip to content

planetlabs/notebooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Planet Interactive Guides

Join the chat at https://gitter.im/planetlabs/notebooks

In this repository, you'll find a collection of Jupyter notebooks from the software developers, data scientists, and developer advocates at Planet. These interactive, open-source (APLv2) guides are designed to help you explore Planet data, work with our APIs and tools, and learn how to extract information from our massive archive of high-cadence satellite imagery. We hope these guides will inspire you to ask interesting questions of Planet data. Need help? Find a bug? Please file an issue and we'll get back to you.

Install and use these notebooks

System Prerequisites

NOTE: After installing Docker, Windows users should install WSL2 Backend when prompted.

Clone or update repo:

If you've never cloned the Planet notebooks repo, run the following:

git clone https://github.com/planetlabs/notebooks.git
cd notebooks

If you have previously cloned the Planet notebooks repo in the past, make sure to update to pull any changes locally that might have happened since you last interacted with the Planet notebooks:

cd notebooks
git pull

Authentication

Access your Planet API Key in Python

Authentication with Planet's API Key can be achieved by using a valid Planet API Key.

You can export your API Key as an environment variable on your system:

export PL_API_KEY="YOUR-API-KEY"

If you wish to have your API Key be persistent (forever stored as PL_API_KEY), then you may enter this export command in your ~/.bashrc or ~/.zshrc file. If you are using our Docker environment, as is defined below, it will already be set.

In Python, we set up an API Key variable, PLANET_API_KEY, from an environment variable to use with our API requests:

# Import the os module in order to access environment variables
import os

# Set up the API Key from the `PL_API_KEY` environment variable
PLANET_API_KEY = os.getenv('PL_API_KEY')

Now, your Planet API Key is stored in the variable PLANET_API_KEY and is ready to use in your Python code.

Run Planet Notebooks in Docker

Planet Notebooks rely on a complex stack of technologies that are not always easy to install and properly configure. To ease this complexity we provide a docker container for running the notebook on docker compatible systems. To install docker on your system please see docker's documentation for your operating system.

Download prebuilt Docker image (recommended)

The Docker image for these notebooks is hosted in the planetlabs/notebooks repo on DockerHub. To download and prepare the image for use, run:

cd notebooks
docker pull planetlabs/notebooks
docker tag planetlabs/notebooks planet-notebooks

# If you get errors running the above, you might have to add sudo to the beginning:
#sudo docker pull planetlabs/notebooks
#sudo docker tag planetlabs/notebooks planet-notebooks

If you want to re-build the Docker image yourself, this is documented below in the "Appendix: Build the Docker image" section.

Run the container

To run the container (after building or downloading it), add your Planet API key below and issue the following command from the git repository root directory:

docker run -it --rm -p 8888:8888 -v $PWD:/home/jovyan/work -e PL_API_KEY='[YOUR-API-KEY]' planet-notebooks

# If you get a permissions error running the above, you should add sudo to the front:
# sudo docker run -it --rm -p 8888:8888 -v $PWD:/home/jovyan/work -e PL_API_KEY='[YOUR-API-KEY]' planet-notebooks
# Windows users run: winpty docker run -it --rm -p 8888:8888 -v "/$PWD":/home/joyvan/work -e PL_API_KEY='[YOUR-API-KEY]' planet-notebooks

This does several things:

  1. Maps the docker container's 8888 port to your system's 8888 port. This makes the container available to your host systems web browser.

  2. Maps a host system path $PWD to the docker container's working directory. This ensures that the notebooks you create, edit, and save are available on your host system under the jupyter-notebooks sub-directory and are not destroyed when you exit the container. This also allows for running tests in the tests sub-directory.

  3. Ensures that the directory in the Docker container named /home/jovyan/work that has the notebooks in them is accessible to the Jupyter notebook server.

  4. Starts an interactive terminal that is accessible through http://localhost:8888.

  5. Sets an environment variable with your unique Planet API key for authenticating against the API.

  6. Includes the --rm option to clean up the notebook after you exit the process.

Open Jupyter notebooks

Once the Docker container is running, the CLI output will display a URL that you will use to access Jupyter notebooks with your browser.

http://localhost:8888/?token=<UNIQUE-TOKEN>

NOTE: This security token will change every time you start your Docker container.

Available notebooks

NOTE: PSScene3Band and PSScene4Band item type and assets will be deprecated by January 2023. These item types will not be available for new customers provisioned after March 1, 2022. We recommend all customers who are interested in medium resolution imagery use the PSScene item type as soon as possible.

Search, activate, download with the Data API

Ordering, delivery, and tools with the Orders API

Process Planet data

Analyze and visualize Planet data

Soon we hope to add notebooks from the researchers, technologists, geographers, and entrepreneurs who are already using Planet data to ask interesting and innovative questions about our changing Earth. If you're working with our imagery and have a notebook (or just an idea for a notebook) that you'd like to share, please file an issue and let us know.

Appendix: Build the Docker image

This documents how to build the docker image yourself, rather than using the recommended step of downloading pre-built Docker images. This is useful if you are a developer adding dependencies or a new Jupyter notebook to this repo, for example.

First you must build the docker image. Note, this only has to be done the first time you use it. After checking out the repository, you run:

cd planet-notebook-docker
docker build --rm -t planet-notebooks .
cd ..

This will build and install the Docker image on your system, making it available to run. This may take some time (from 10 minutes to an hour) depending on your network connection and how long Anaconda takes to configure its environment.