Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/Dockerfile

This file was deleted.

36 changes: 0 additions & 36 deletions .devcontainer/devcontainer.json

This file was deleted.

3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
with:
fetch-depth: 0
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3.1.4
with:
python-version: "3.9.13"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nbdime ipython_genutils
- name: Configure nbdime
run: |
/opt/hostedtoolcache/Python/3.9.13/x64/bin/nbdime config-git --enable --global
nbdime config-git --enable --global
- name: git diff
run: |
git diff HEAD^ HEAD
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
- uses: actions/setup-python@3542bca2639a428e1796aaa6a2ffef0c0f575566 # v3.1.4
with:
python-version: "3.11"
python-version: "3.12"
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
repos:
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.9.1
hooks:
- id: nbqa-black
additional_dependencies: [black==22.3.0]
args: [--nbqa-mutate]
- id: nbqa-flake8
additional_dependencies: [flake8==6.1.0]
- id: nbqa-ruff-check
additional_dependencies: [ruff==0.17.3]
- id: nbqa-ruff-format
additional_dependencies: [ruff==0.17.3]
- repo: local
hooks:
- id: check-headers
Expand Down
75 changes: 51 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,78 @@ This repository contains Jupyter Notebooks that serve as examples of using the [

## Getting Started

This project uses Docker to encapsulate the development environment. To set up your development
environment, have Docker installed and run:
Follow the [setup instructions in README.md](README.md#getting-started).
Microsoft employees must use
<https://packagefeedproxy.microsoft.io/pypi/simple>. Other contributors can use
<https://pypi.org/simple>. Set `UV_DEFAULT_INDEX` to your required index before
installing packages or updating requirements. Keep any feed credentials outside
the repository.

The minimum supported Python version is 3.12. The installer creates a local
`.venv` using Python 3.12, matching CI. uv downloads
Python if needed. Common dependencies are declared in
[pyproject.toml](pyproject.toml). [requirements.txt](requirements.txt) records exact
versions of direct and transitive dependencies. It is generated with
uv and contains no index URLs, so it works with either package index.

Start JupyterLab with:

```sh
> scripts/setup
uv run jupyter lab
```

If you need to rebuild the images at any point, you
can run:
Open the URL printed in the terminal. In VS Code, select `.venv/bin/python` as the
Python interpreter and notebook kernel. On Windows, use `.venv/Scripts/python.exe`
and run `scripts/install` from a Bash shell.

```sh
> scripts/update
```
The shared environment covers common Python notebook dependencies. Specialized
examples may need extra packages, credentials, or remote services. R notebooks
need a separate R environment.

To run the jupyter notebook server, you can use:
To regenerate requirements after editing `pyproject.toml`, run:

```sh
> scripts/server
uv pip compile pyproject.toml --extra dev --universal --python-version 3.12 \
--output-file requirements.txt
./scripts/install
```

And browse to the URL printed in the terminal output.

From there you'll be able to run all Jupyter Notebook examples.
The installer only installs requirements; it does not regenerate them. Add
`--upgrade-package package` to the compile command to update a specific package,
or `--upgrade` to update all packages. Commit both dependency files. Use `uv pip`
commands for this environment; automatic project syncing is disabled so `uv run`
cannot replace the compiled requirements with a different resolution.

### Linting

Notebooks are linted using [nbqa](https://nbqa.readthedocs.io/en/latest/) with flake8 and black.
We include a [pre-commit](https://pre-commit.com/) file for running the checks.
Notebooks are linted and formatted using
[nbQA](https://nbqa.readthedocs.io/en/latest/) with
[Ruff](https://docs.astral.sh/ruff/). The
[pre-commit configuration](.pre-commit-config.yaml) pins both tools.

```sh
uv run pre-commit install
./scripts/test --lint
```
> pre-commit install
```

The test script runs every pre-commit hook over all tracked files, regardless of
the current directory. Formatters may modify files; review those changes and
rerun the command until it passes.

Ruff formats at 88 columns and checks line lengths at 94 columns. Imports may
appear after other notebook code. The R quickstart is excluded from both Ruff
hooks. Notebook header checks remain unchanged.

Hook environments install packages with pip. Microsoft employees must set
`PIP_INDEX_URL=https://packagefeedproxy.microsoft.io/pypi/simple` before running
pre-commit. Other contributors can use `PIP_INDEX_URL=https://pypi.org/simple`.

Notebooks should start with an H2-level header (`## <title>`) and should have no H1-level headers.


### Integration with Data Catalog site

Running the `./scripts/server` script also starts a local webserver that can
source notebook files to the Planetary Computer docs site development
environment. That project is pre-configured to integrate with this server.
After running `./scripts/server` from within this project, run
`./scripts/update --devdocs` from the Planetary Computer website project and
it will treat this local instance as the source for external docs notebooks.
See that project's ETL readme for more information.
The notebooks from this repository are consumed by the Planetary Computer Data Catalog (the website): <https://planetarycomputer.microsoft.com>, but the code for the website is now managed privately by Microsoft.

## Contributing

Expand Down
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
<img src="https://ai4edatasetspublicassets.blob.core.windows.net/assets/aod_images/planetary_computer_header_800w.png" alt="Planetary Computer"/>

# Planetary Computer Hub
This repository contains [Jupyter](https://jupyter.org/) notebooks showcasing various analysis possible with geospatial data from [Microsoft Planetary Computer](https://planetarycomputer.microsoft.com/).

Welcome to the [Planetary Computer Hub](http://planetarycomputer.microsoft.com/compute), a development environment that makes our data and APIs accessible through familiar, open-source tools, and allows users to easily scale their analyses.
## Getting started

If you're viewing this repository from GitHub, you might want to browse the rendered examples on [nbviewer](https://nbviewer.org/github/Microsoft/PlanetaryComputerExamples/tree/main/), including our [quickstarts](https://nbviewer.org/github/microsoft/PlanetaryComputerExamples/tree/main/quickstarts/), [dataset examples](https://nbviewer.org/github/microsoft/PlanetaryComputerExamples/tree/main/datasets/), and [tutorials](https://nbviewer.org/github/microsoft/PlanetaryComputerExamples/tree/main/tutorials/).
Install [uv](https://docs.astral.sh/uv/getting-started/installation/).

## Quickstarts
**Microsoft employees must use the Microsoft package feed proxy:**

```sh
UV_DEFAULT_INDEX=https://packagefeedproxy.microsoft.io/pypi/simple ./scripts/install
```

**Other contributors can use PyPI:**

```sh
UV_DEFAULT_INDEX=https://pypi.org/simple ./scripts/install
```

These quickstarts give high-level introductions to a single topic.
Python 3.12 is the minimum supported version. The installer creates `.venv` with
Python 3.12 and installs the exact package
versions in `requirements.txt`. uv downloads Python if needed. Start JupyterLab:

```sh
uv run jupyter lab
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for environment and development details.

## Quickstarts

* [Reading from the STAC API](quickstarts/reading-stac.ipynb)
* [Reading from the STAC API with R](quickstarts/reading-stac-r.ipynb)
Expand Down
3 changes: 1 addition & 2 deletions competitions/cloud-cover/benchmark-tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,7 @@
"source": [
"left, bottom, right, top = lat_long_bounds(example_chip[\"B04_path\"])\n",
"print(\n",
" f\"Image coordinates (lat, long):\\nStart: ({left}, {bottom})\"\n",
" f\"\\nEnd: ({right}, {top})\"\n",
" f\"Image coordinates (lat, long):\\nStart: ({left}, {bottom})\\nEnd: ({right}, {top})\"\n",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion competitions/s1floods/generate_auxiliary_input.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
"# Iterate over the chips and generate all aux input files.\n",
"count = len(chip_paths)\n",
"for i, chip_path in enumerate(chip_paths):\n",
" print(f\"({i+1} of {count}) {chip_path}\")\n",
" print(f\"({i + 1} of {count}) {chip_path}\")\n",
" chip_info = get_chip_info(chip_path)\n",
" for collection_id, asset_key, file_name, resampling_method in aux_file_params:\n",
" print(f\" ... Creating chip data for {collection_id} {asset_key}\")\n",
Expand Down
22 changes: 11 additions & 11 deletions datasets/ai4good/colombia-earthquake.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"import planetary_computer\n",
"import pystac_client\n",
"import rasterio\n",
"import rasterio.windows\n"
"import rasterio.windows"
]
},
{
Expand Down Expand Up @@ -157,7 +157,7 @@
" }\n",
" for item in items\n",
" ]\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -197,7 +197,7 @@
" collections=[\"predicted-damage-colombia-2026\"],\n",
" bbox=[-75.79, 4.77, -75.69, 4.85],\n",
")\n",
"[item.id for item in pereira_search.items()]\n"
"[item.id for item in pereira_search.items()]"
]
},
{
Expand Down Expand Up @@ -400,7 +400,7 @@
" for item in items\n",
" for key, asset in item.assets.items()\n",
" ]\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -585,7 +585,7 @@
"\n",
"print(f\"{len(gdf):,} building footprints\")\n",
"print(\"CRS:\", gdf.crs)\n",
"gdf.head()\n"
"gdf.head()"
]
},
{
Expand Down Expand Up @@ -647,7 +647,7 @@
}
],
"source": [
"gdf.info()\n"
"gdf.info()"
]
},
{
Expand Down Expand Up @@ -743,7 +743,7 @@
" partly_obscured=(\"unknown_pct\", lambda s: (s > 0).sum()),\n",
")\n",
"summary[\"percent damaged\"] = (summary[\"damaged\"] / summary[\"buildings\"] * 100).round(2)\n",
"summary\n"
"summary"
]
},
{
Expand Down Expand Up @@ -817,7 +817,7 @@
" ],\n",
" loc=\"lower left\",\n",
")\n",
"fig.suptitle(\"Predicted building damage — Colombia earthquake, August 2026\", y=0.93)\n"
"fig.suptitle(\"Predicted building damage — Colombia earthquake, August 2026\", y=0.93)"
]
},
{
Expand Down Expand Up @@ -953,7 +953,7 @@
" {\"value\": value, \"class\": label, \"RGBA\": color_table[value]}\n",
" for value, label in CLASS_LABELS.items()\n",
" ]\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -1004,7 +1004,7 @@
" predictions = src.read(1, window=window)\n",
" left, bottom, right, top = rasterio.windows.bounds(window, src.transform)\n",
"\n",
"predictions.shape\n"
"predictions.shape"
]
},
{
Expand Down Expand Up @@ -1072,7 +1072,7 @@
" labelcolor=\"white\",\n",
")\n",
"ax.set_title(\"Model predictions, Pereira — 600 m across\")\n",
"ax.set_axis_off()\n"
"ax.set_axis_off()"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion datasets/aster-l1t/aster-l1t-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@
"image_data = []\n",
"\n",
"with rasterio.open(swir_asset.href, \"r\") as src:\n",
"\n",
" h = int(src.height // dsfactor)\n",
" w = int(src.width // dsfactor)\n",
"\n",
Expand Down
3 changes: 1 addition & 2 deletions datasets/daymet/daymet-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3573,8 +3573,7 @@
],
"source": [
"na_url = (\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/\"\n",
" \"daymet-monthly-na\"\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/collections/daymet-monthly-na\"\n",
")\n",
"na_collection = pystac.read_file(na_url)\n",
"na_asset = na_collection.assets[\"zarr-https\"]\n",
Expand Down
2 changes: 1 addition & 1 deletion datasets/gridmet/gridmet-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@
"ds = xr.open_zarr(\n",
" asset.href,\n",
" storage_options=asset.extra_fields[\"xarray:storage_options\"],\n",
" **asset.extra_fields[\"xarray:open_kwargs\"]\n",
" **asset.extra_fields[\"xarray:open_kwargs\"],\n",
")\n",
"ds"
]
Expand Down
2 changes: 1 addition & 1 deletion datasets/hls2/hls2-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@
"frames = []\n",
"for i, item in enumerate(items):\n",
" if (i + 1) % 10 == 0 or i == len(items) - 1:\n",
" print(f\"Rendering frame {i+1}/{len(items)}\")\n",
" print(f\"Rendering frame {i + 1}/{len(items)}\")\n",
" frame = visualize_item_rgb_ndvi(\n",
" collection_id, item, band_name_map[collection_id], timelapse_bbox_of_interest\n",
" )\n",
Expand Down
Loading
Loading