Skip to content

Commit b218fd0

Browse files
392 restructure october 2025 (#393)
refactor whole notebooks repo organization --------- Co-authored-by: Torben Barsballe <[email protected]>
1 parent 91d993d commit b218fd0

File tree

259 files changed

+297
-7044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+297
-7044
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ gdalwmscache
9999
# local download folders
100100
**/**/planet_downloads/
101101
jupyter-notebooks/workflows/planet_sandbox_data/forest-carbon-dilligence/fcd_statistics.csv
102+
103+
104+
dev/

CONTRIBUTING.md

Lines changed: 122 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,126 @@
11
# Contributing to Notebooks
22

3-
# Notebooks
4-
5-
## Names
6-
7-
Notebook filenames cannot have spaces. Use underscores instead. This is
8-
because pytest does not like spaces in command line arguments.
9-
10-
## Style
11-
12-
For maximum portability, accessibility, and ease of use, Notebooks in this
13-
repository should not use a custom style or theme.
14-
15-
16-
## Dependencies
17-
18-
When a new notebook has a dependency that is not yet supported by the Docker image,
19-
a new Docker image must be built. Additionally, add the new dependency to the
20-
[imports_test notebook](dev/imports_test.ipynb).
21-
22-
## Planet Data
23-
24-
It is the intention of this notebook repository that a user be able to easily
25-
determine the permissions needed within the Planet ecosystem to be able to run
26-
all notebooks successfully. Therefore, we standardize and track Planet data
27-
that are used across all notebooks within this repository. Right now, this applies
28-
to Planet Imagery in the form of Areas of Interest and to Planet
29-
Analytic Feeds in the form of suscription IDs.
30-
31-
### Imagery - Area of Interest
32-
33-
The first choice of area of interest (AOI) for any notebook is an AOI that is
34-
already used in this repository. The geojson description of these AOIs is given
35-
in [aois.geojson](dev/imports_test.ipynb) (it is easy to visualize these
36-
aois directly in GitHub or by copy/pasting into [geojson.io](geojson.io).
37-
These AOIs are also given in the
38-
[repository_aois notebook](dev/repository_aois.ipynb). It is good practice
39-
to add your notebook to the list of notebooks using each AOI.
40-
41-
If the AOI for a notebook cannot be satisfied by the the AOIs already in use
42-
in the repository, then email <[email protected]> so that we can consider
43-
expanding our demo data coverage to include a new AOI. If the new AOI is included,
44-
add the AOI to the
45-
[repository_aois notebook](dev/repository_aois.ipynb). Run that notebook
46-
through to the end to update [aois.geojson](dev/imports_test.ipynb).
47-
48-
### Analytics Feed - Subscription ID
49-
50-
The fist choice of Analytics Feed subscription id for any notebooks is a
51-
subscription ID that is already used in this repository. The subscription IDs
52-
used in this repository are maintained in the
53-
[analygics_feeds notebook](analytics_feeds.ipynb). This notebook also helpfully
54-
pulls the feed information from these subscription IDs. It is good practice
55-
to add your notebook to the list of notebooks using each subscription ID.
56-
57-
Currently, subscription IDs are not being tracked in any demo permissions program.
58-
However, this may change in the future. If the subscription ID for a notebook
59-
cannot be satisfied by the subscription IDs already in the repository, add
60-
the subscription ID to the notebook and email <[email protected]> to notify us
61-
of the change. (**NOTE**: this is likely to change to a request when demo
62-
permissions for the analytics feed are established).
63-
64-
## Notebook Validation
65-
66-
To enable validation of the Docker image, every notebook should run successfully
67-
when run from the command line. For notebooks where that just is not possible,
68-
the notebooks can be excluded from automated running by adding its path to
69-
[tests/skip_notebooks](tests/skip_notebooks). Excluding a notebook from automated running
70-
means that it is excluded from Docker Image validation. **If a notebook is
71-
skipped, it will not be guaranteed to be supported by the Docker image.**
72-
73-
# Docker Image
74-
75-
## Validation
76-
77-
**Every time** the Docker image is changed, at the very least ensure that the
78-
python packages still import without error by running the
79-
[imports_test notebook](dev/imports_test.ipynb).
80-
81-
It is also strongly recommended that you ensure the Docker image can run all
82-
of the notebooks in the repository. This can be accomplished by automatically
83-
running all of the notebooks using the supplied test script. To run the test script,
84-
run the notebook in interactive mode, achieved by adding `/bin/bash` to
85-
the container run command, e.g.
86-
```bash
87-
docker run -it --rm -p 8888:8888 \
88-
-v $PWD:/home/jovyan/work \
89-
-e PL_API_KEY='[YOUR-API-KEY]' \
90-
planet-notebooks /bin/bash
3+
Contributions are welcome to this repository. Please open a PR if you would like to contribute a notebook and we will review. Alternatively, if you have a request or an idea, you can [open an issue](https://github.com/planetlabs/notebooks/issues/new/choose).
4+
5+
## Notebook Style
6+
7+
If you are contributing a notebook, we've gathered these style guide requirements.
8+
9+
### Filemames
10+
11+
Notebook filenames should not have spaces. Please use underscores with `snake_case` instead for all files in the repository.
12+
13+
Your filename should align to the title of the notebook. For example, a notebook titled **Generate Agriculture Index Time Series** should be `generate_agriculture_index_time_series.ipynb`.
14+
15+
### HTML and Markdown
16+
17+
For maximum portability, accessibility, and ease of use, notebooks in this repository should not use a custom style or theme. Please stick to standard markdown features so that it works across all environments.
18+
19+
### Dependencies
20+
21+
When a new notebook has a dependency that is not yet supported by the Docker image, please add the dependency to the [Docker setup requirements file](planet-notebook-docker/requirements.txt).
22+
23+
Alternatively, you can choose to add package installation instructions in your Notebook, particularly if the notebook you are adding has any heavy, unique, or tricky dependencies. If you do this, make sure to include comments in the notebooks.
24+
25+
### Ordering Notebooks
26+
27+
If you are working on a multi-part guide that has several notebooks, prefix the notebooks with `1_`, `2_`, `3_`, and so on to indicate the order.
28+
29+
### Optimize Cell Outputs for Viewing in the Browser
30+
31+
If you have a cell that prints a very large json repsonse, consider alternative ways to view the data. Could it be viewed in a table or on a map? Very large json repsonses make notebooks difficult to read.
32+
33+
### Use Colab
34+
35+
When possible, add the option to open the notebook in Colab. This should be added as the very first line in the first cell of the Jupyter Notebook file so that it appears at the very top.
36+
37+
For example:
38+
39+
```
40+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//planetlabs/notebooks/blob/master/jupyter-notebooks/workflows/planet_sandbox_data/agriculture-index-time-series/agriculture-index-time-series.ipynb)
41+
```
42+
43+
If your notebook includes Colab link, make sure that the packages used within it are either a) default colab packages or b) imported using a magic command `%pip install planet`.
44+
45+
### Introduction
46+
47+
For a notebook, please make sure to include context and description at the top using this format:
48+
49+
```
50+
<colab link>
51+
# Notebook Title
52+
53+
Information about the notebook
54+
55+
## Requirements
56+
57+
Any special requirements, set up instructions, permissions, pre-steps, etc.
58+
```
59+
60+
### Authentication
61+
62+
Most Notebooks will likely require authenticating with Planet APIs. In order to use consistent authentication and schemes across all of the notebooks, we've provided 3 authentication snippets that we recommend you use:
63+
64+
#### For Notebooks that use the Planet SDK for Python
65+
66+
```
67+
import planet
68+
69+
# If you are not already logged in, this will prompt you to open a web browser to log in.
70+
auth = planet.Auth.from_profile('planet-user', save_state_to_storage=True)
71+
if not auth.is_initialized():
72+
auth.user_login(allow_open_browser=False, allow_tty_prompt=True)
73+
74+
session = planet.Session(auth)
75+
pl = planet.Planet(session)
76+
```
77+
78+
#### For Notebooks that use the Sentinel Hub Python SDK
79+
80+
```
81+
from sentinelhub import SHConfig
82+
83+
# Authenticate with the Sentinel Hub Python SDK; See docs: https://sentinelhub-py.readthedocs.io/en/latest/configure.html and https://docs.planet.com/develop/authentication
84+
# If no default configuration detected, enter a client ID and secret to authenticate. These can be obtained by creating an OAuth client here: https://insights.planet.com/account
85+
config = SHConfig()
86+
if not config.sh_client_id or not config.sh_client_secret:
87+
from getpass import getpass
88+
print('No credentials found, please provide the OAuth client ID and secret.')
89+
config.sh_client_id = getpass('Client ID: ')
90+
config.sh_client_secret = getpass('Client Secret: ')
91+
# config.save() ## Uncomment these lines to locally save your credentials to a configuration file
92+
# print(f'Credentials saved to {SHConfig.get_config_location()}')
93+
else:
94+
print(f'Using credentials stored here: {SHConfig.get_config_location()}')
95+
```
96+
97+
#### For Notebooks that use API key authentication
98+
99+
If a notebook is using `requests` instead of the SDK, you will need to use API key authentication.
100+
101+
```
102+
import os
103+
import requests
104+
105+
# Authenticate with the Planet SDK for Python using your API key; See docs: https://docs.planet.com/develop/authentication
106+
# Check for PL_API_KEY environment variable, otherwise type in your API key.
107+
pl_api_key = os.getenv('PL_API_KEY')
108+
if not pl_api_key:
109+
import getpass
110+
pl_api_key = getpass.getpass('Planet API Key: ')
111+
os.environ['PL_API_KEY'] = pl_api_key
112+
113+
session = requests.Session()
114+
session.auth = (pl_api_key, '')
115+
```
116+
117+
And if in the same notebook, you also need to use the SDK, you can use the following:
118+
91119
```
120+
import planet
92121
93-
From the root directory within the docker container, run one of the following:
94-
95-
1. To run all notebooks
96-
```bash
97-
$> pytest tests/test_notebooks.py
98-
```
99-
1. run only notebooks in a subdirectory using
100-
```bash
101-
$> pytest tests/test_notebooks.py --path <subdirectory>
102-
```
103-
1. run one or more notebooks (separated by spaces)
104-
```bash
105-
$> pytest tests/test_notebooks.py --notebooks <notebook1> <notebook2> <...>
106-
```
107-
1. run only notebooks that have a given dependency, <package>
108-
```bash
109-
$> pytest tests/test_notebooks.py --notebooks "$(grep -rl import <package> jupyter-notebooks/)"
110-
```
111-
112-
## Skipping Notebooks
113-
114-
Some notebooks are purposefully skipped in the validation process because they
115-
do not run successfully from the command line. These notebooks are specified in
116-
[tests/skip_notebooks](tests/skip_notebooks). Skipping of notebooks within
117-
`skip_notebooks` can be disabled by adding the `--no-skip` option to the pytest
118-
command.
122+
## Authenticate with the Planet SDK for Python with your API key
123+
auth = planet.Auth.from_key(key=pl_api_key)
124+
pl_session = planet.Session(auth)
125+
pl = planet.Planet(session)
126+
```

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Planet Jupyter Notebook Guides
22

3-
In this repository, you'll find a collection of [Jupyter notebooks](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html) from the software developers, data scientists, and developer advocates at [Planet](https://www.planet.com/). These interactive, open-source ([APLv2](LICENSE)) guides are designed to help you work with our APIs and tools, explore Planet data, 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](https://github.com/planetlabs/notebooks/issues/new) and we'll get back to you.
3+
In this repository, you'll find a collection of [Jupyter notebooks](http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/what_is_jupyter.html) from the software developers, data scientists, and developer advocates at [Planet](https://www.planet.com/). These interactive, open-source ([APLv2](LICENSE)) guides are designed to help you work with our APIs and tools, explore Planet data, 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.
4+
5+
Need help? Find a bug? Please [file an issue](https://github.com/planetlabs/notebooks/issues/new) and we'll get back to you.
46

57
## Install and Use Planet Jupyter Notebooks
68

79
### System Prerequisites
8-
* [Docker](https://docs.docker.com/get-started/get-docker/)
910
* [Planet Account](https://insights.planet.com/sign-up)
1011
* [Planet API Key](https://www.planet.com/account/)
12+
* (optional) [Docker](https://docs.docker.com/get-started/get-docker/)
1113

1214
### Clone or Update Repo
1315

@@ -25,11 +27,21 @@ cd notebooks
2527
git pull
2628
```
2729

30+
## Notebooks Table of Contents
31+
32+
This repository contains a collection Jupyter notebooks that teach you how to use Planet Insights Platform.
33+
34+
You can find a [table of contents here](/jupyter-notebooks/).
35+
2836
## Authentication
2937

30-
## Access Your Planet API Key in Python
38+
To use these notebooks, which interact with [Planet's APIs](https://docs.planet.com/develop/apis), you will need to have an account to authenticate. You can find our [authentication documentation here](https://docs.planet.com/develop/authentication/).
39+
40+
Some notebooks authenticate with your Planet Account directly. You will be prompted to login via a web link and confirm your authorization. If you would like to know more, refer to the authentication documentation linked above.
41+
42+
### Access Your Planet API Key in Python
3143

32-
Authentication with Planet's API Key can be achieved by using a valid Planet API Key.
44+
Other notebooks authenticate using your Planet API Key. To find your API key, you can go to your [account settings page](https://insights.planet.com/account/#/settings).
3345

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

@@ -51,10 +63,10 @@ PLANET_API_KEY = os.getenv('PL_API_KEY')
5163

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

54-
## Sentinel Hub Python SDK
66+
### Sentinel Hub Python SDK
5567
Some Notebooks in this repository use the [Sentinel Hub Python SDK](https://sentinelhub-py.readthedocs.io/en/latest/index.html). Currently, this SDK uses a different method of authenticating than what is used with the Planet APIs and SDK for Python.
5668

57-
For the Sentinel Hub Python SDK, you must provide a ```client_id``` and a ```client_secret``` which can be obtained from the [Dashboard](https://apps.sentinel-hub.com/dashboard/) app. You can find full instructions on setting up the client credentials in this SDK from the [SDK documentation](https://sentinelhub-py.readthedocs.io/en/latest/configure.html).
69+
For the Sentinel Hub Python SDK, you must provide a ```client_id``` and a ```client_secret``` which can be obtained from the [account manager application](https://insights.planet.com/account/#/). You can find full instructions on setting up the client credentials for this SDK in the [SDK documentation](https://sentinelhub-py.readthedocs.io/en/latest/configure.html).
5870

5971
```python
6072
from sentinelhub import SHConfig

0 commit comments

Comments
 (0)