Skip to content

Instantly share code, notes, and snippets.

@calebrob6
Created August 12, 2025 23:29
Show Gist options
  • Select an option

  • Save calebrob6/f21dec65e0d474ed3d529a26ee97d0f0 to your computer and use it in GitHub Desktop.

Select an option

Save calebrob6/f21dec65e0d474ed3d529a26ee97d0f0 to your computer and use it in GitHub Desktop.
Notebook that shows end-to-end example of running a Fields of the World model on Sentinel-2 imagery and joining with CDL labels and MOSAIKS embeddings.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"source": [
"!pip install \"git+https://github.com/microsoft/torchgeo.git\" planetary-computer rioxarray odc-stac scikit-learn"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "KPjLDc-HhQm5",
"outputId": "47617320-cf41-4d48-8824-9c1c54d6b049"
},
"id": "KPjLDc-HhQm5",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting git+https://github.com/microsoft/torchgeo.git\n",
" Cloning https://github.com/microsoft/torchgeo.git to /tmp/pip-req-build-o51vum56\n",
" Running command git clone --filter=blob:none --quiet https://github.com/microsoft/torchgeo.git /tmp/pip-req-build-o51vum56\n",
" Resolved https://github.com/microsoft/torchgeo.git to commit 1f02dbe7d22d5251268cc73c22478eca56e3c62d\n",
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
"Collecting planetary-computer\n",
" Downloading planetary_computer-1.0.0-py3-none-any.whl.metadata (7.4 kB)\n",
"Collecting rioxarray\n",
" Downloading rioxarray-0.19.0-py3-none-any.whl.metadata (5.5 kB)\n",
"Collecting odc-stac\n",
" Downloading odc_stac-0.4.0-py3-none-any.whl.metadata (5.9 kB)\n",
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.11/dist-packages (1.6.1)\n",
"Requirement already satisfied: einops>=0.3 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (0.8.1)\n",
"Collecting fiona>=1.8.22 (from torchgeo==0.8.0.dev0)\n",
" Downloading fiona-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (56 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.6/56.6 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hCollecting geopandas>=0.12.1 (from torchgeo==0.8.0.dev0)\n",
" Downloading geopandas-1.1.1-py3-none-any.whl.metadata (2.3 kB)\n",
"Collecting kornia>=0.7.4 (from torchgeo==0.8.0.dev0)\n",
" Downloading kornia-0.8.1-py2.py3-none-any.whl.metadata (17 kB)\n",
"Collecting lightly!=1.4.26,>=1.4.5 (from torchgeo==0.8.0.dev0)\n",
" Downloading lightly-1.5.22-py3-none-any.whl.metadata (38 kB)\n",
"Collecting lightning!=2.3.*,!=2.5.0,>=2 (from lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading lightning-2.5.2-py3-none-any.whl.metadata (38 kB)\n",
"Requirement already satisfied: matplotlib>=3.6 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (3.10.0)\n",
"Requirement already satisfied: numpy>=1.23.2 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (2.0.2)\n",
"Requirement already satisfied: pandas>=1.5 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (2.2.2)\n",
"Requirement already satisfied: pillow>=9.2 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (11.3.0)\n",
"Collecting pyproj>=3.4 (from torchgeo==0.8.0.dev0)\n",
" Downloading pyproj-3.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)\n",
"Collecting rasterio!=1.4.0,!=1.4.1,!=1.4.2,>=1.3.3 (from torchgeo==0.8.0.dev0)\n",
" Downloading rasterio-1.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.1 kB)\n",
"Collecting segmentation-models-pytorch>=0.5 (from torchgeo==0.8.0.dev0)\n",
" Downloading segmentation_models_pytorch-0.5.0-py3-none-any.whl.metadata (17 kB)\n",
"Collecting shapely>=2 (from torchgeo==0.8.0.dev0)\n",
" Downloading shapely-2.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)\n",
"Collecting timm>=1.0.3 (from torchgeo==0.8.0.dev0)\n",
" Downloading timm-1.0.19-py3-none-any.whl.metadata (60 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.8/60.8 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: torch>=2 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (2.6.0+cpu)\n",
"Collecting torchmetrics>=1.2 (from torchgeo==0.8.0.dev0)\n",
" Downloading torchmetrics-1.8.1-py3-none-any.whl.metadata (22 kB)\n",
"Requirement already satisfied: torchvision>=0.15.1 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (0.21.0+cpu)\n",
"Requirement already satisfied: typing-extensions>=4.5 in /usr/local/lib/python3.11/dist-packages (from torchgeo==0.8.0.dev0) (4.14.1)\n",
"Requirement already satisfied: click>=7.1 in /usr/local/lib/python3.11/dist-packages (from planetary-computer) (8.2.1)\n",
"Requirement already satisfied: pydantic>=1.7.3 in /usr/local/lib/python3.11/dist-packages (from planetary-computer) (2.11.7)\n",
"Collecting pystac>=1.0.0 (from planetary-computer)\n",
" Downloading pystac-1.13.0-py3-none-any.whl.metadata (4.7 kB)\n",
"Collecting pystac-client>=0.2.0 (from planetary-computer)\n",
" Downloading pystac_client-0.9.0-py3-none-any.whl.metadata (3.1 kB)\n",
"Requirement already satisfied: pytz>=2020.5 in /usr/local/lib/python3.11/dist-packages (from planetary-computer) (2025.2)\n",
"Requirement already satisfied: requests>=2.25.1 in /usr/local/lib/python3.11/dist-packages (from planetary-computer) (2.32.3)\n",
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from planetary-computer) (25.0)\n",
"Collecting python-dotenv (from planetary-computer)\n",
" Downloading python_dotenv-1.1.1-py3-none-any.whl.metadata (24 kB)\n",
"Collecting xarray>=2024.7.0 (from rioxarray)\n",
" Downloading xarray-2025.7.1-py3-none-any.whl.metadata (12 kB)\n",
"Collecting affine (from odc-stac)\n",
" Downloading affine-2.4.0-py3-none-any.whl.metadata (4.0 kB)\n",
"Collecting odc-geo>=0.4.7 (from odc-stac)\n",
" Downloading odc_geo-0.4.10-py3-none-any.whl.metadata (6.1 kB)\n",
"Collecting odc-loader>=0.5.1 (from odc-stac)\n",
" Downloading odc_loader-0.5.1-py3-none-any.whl.metadata (1.3 kB)\n",
"Collecting dask[array] (from odc-stac)\n",
" Downloading dask-2025.7.0-py3-none-any.whl.metadata (3.8 kB)\n",
"Requirement already satisfied: toolz in /usr/local/lib/python3.11/dist-packages (from odc-stac) (1.0.0)\n",
"Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (1.16.1)\n",
"Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (1.5.1)\n",
"Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (3.6.0)\n",
"Requirement already satisfied: attrs>=19.2.0 in /usr/local/lib/python3.11/dist-packages (from fiona>=1.8.22->torchgeo==0.8.0.dev0) (25.3.0)\n",
"Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from fiona>=1.8.22->torchgeo==0.8.0.dev0) (2025.8.3)\n",
"Collecting click-plugins>=1.0 (from fiona>=1.8.22->torchgeo==0.8.0.dev0)\n",
" Downloading click_plugins-1.1.1.2-py2.py3-none-any.whl.metadata (6.5 kB)\n",
"Collecting cligj>=0.5 (from fiona>=1.8.22->torchgeo==0.8.0.dev0)\n",
" Downloading cligj-0.7.2-py3-none-any.whl.metadata (5.0 kB)\n",
"Collecting pyogrio>=0.7.2 (from geopandas>=0.12.1->torchgeo==0.8.0.dev0)\n",
" Downloading pyogrio-0.11.1-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (5.3 kB)\n",
"Collecting kornia_rs>=0.1.9 (from kornia>=0.7.4->torchgeo==0.8.0.dev0)\n",
" Downloading kornia_rs-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)\n",
"Collecting hydra-core>=1.0.0 (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0)\n",
" Downloading hydra_core-1.3.2-py3-none-any.whl.metadata (5.5 kB)\n",
"Collecting lightly_utils~=0.0.0 (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0)\n",
" Downloading lightly_utils-0.0.2-py3-none-any.whl.metadata (1.4 kB)\n",
"Requirement already satisfied: python_dateutil>=2.5.3 in /usr/local/lib/python3.11/dist-packages (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0) (2.9.0.post0)\n",
"Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.11/dist-packages (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0) (1.17.0)\n",
"Requirement already satisfied: tqdm>=4.44 in /usr/local/lib/python3.11/dist-packages (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0) (4.67.1)\n",
"Collecting pytorch_lightning>=1.0.4 (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0)\n",
" Downloading pytorch_lightning-2.5.2-py3-none-any.whl.metadata (21 kB)\n",
"Requirement already satisfied: urllib3>=1.25.3 in /usr/local/lib/python3.11/dist-packages (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0) (2.5.0)\n",
"Collecting aenum>=3.1.11 (from lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0)\n",
" Downloading aenum-3.1.16-py3-none-any.whl.metadata (3.8 kB)\n",
"Requirement already satisfied: PyYAML<8.0,>=5.4 in /usr/local/lib/python3.11/dist-packages (from lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (6.0.2)\n",
"Requirement already satisfied: fsspec<2027.0,>=2022.5.0 in /usr/local/lib/python3.11/dist-packages (from fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (2025.7.0)\n",
"Collecting lightning-utilities<2.0,>=0.10.0 (from lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading lightning_utilities-0.15.2-py3-none-any.whl.metadata (5.7 kB)\n",
"Collecting bitsandbytes<1.0,>=0.45.2 (from lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading bitsandbytes-0.47.0-py3-none-manylinux_2_24_x86_64.whl.metadata (11 kB)\n",
"Collecting jsonargparse<5.0,>=4.39.0 (from jsonargparse[jsonnet,signatures]<5.0,>=4.39.0; extra == \"pytorch-extra\"->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading jsonargparse-4.40.2-py3-none-any.whl.metadata (13 kB)\n",
"Collecting omegaconf<3.0,>=2.2.3 (from lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading omegaconf-2.3.0-py3-none-any.whl.metadata (3.9 kB)\n",
"Requirement already satisfied: rich<15.0,>=12.3.0 in /usr/local/lib/python3.11/dist-packages (from lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (14.1.0)\n",
"Collecting tensorboardX<3.0,>=2.2 (from lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading tensorboardx-2.6.4-py3-none-any.whl.metadata (6.2 kB)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.6->torchgeo==0.8.0.dev0) (1.3.3)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.6->torchgeo==0.8.0.dev0) (0.12.1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.6->torchgeo==0.8.0.dev0) (4.59.0)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.6->torchgeo==0.8.0.dev0) (1.4.8)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.6->torchgeo==0.8.0.dev0) (3.2.3)\n",
"Requirement already satisfied: cachetools in /usr/local/lib/python3.11/dist-packages (from odc-geo>=0.4.7->odc-stac) (5.5.2)\n",
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=1.5->torchgeo==0.8.0.dev0) (2025.2)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic>=1.7.3->planetary-computer) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic>=1.7.3->planetary-computer) (2.33.2)\n",
"Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic>=1.7.3->planetary-computer) (0.4.1)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.25.1->planetary-computer) (3.4.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.25.1->planetary-computer) (3.10)\n",
"Requirement already satisfied: huggingface-hub>=0.24 in /usr/local/lib/python3.11/dist-packages (from segmentation-models-pytorch>=0.5->torchgeo==0.8.0.dev0) (0.34.3)\n",
"Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.11/dist-packages (from segmentation-models-pytorch>=0.5->torchgeo==0.8.0.dev0) (0.6.1)\n",
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from torch>=2->torchgeo==0.8.0.dev0) (3.18.0)\n",
"Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch>=2->torchgeo==0.8.0.dev0) (3.5)\n",
"Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch>=2->torchgeo==0.8.0.dev0) (3.1.6)\n",
"Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch>=2->torchgeo==0.8.0.dev0) (1.13.1)\n",
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch>=2->torchgeo==0.8.0.dev0) (1.3.0)\n",
"Requirement already satisfied: cloudpickle>=3.0.0 in /usr/local/lib/python3.11/dist-packages (from dask[array]->odc-stac) (3.1.1)\n",
"Collecting partd>=1.4.0 (from dask[array]->odc-stac)\n",
" Downloading partd-1.4.2-py3-none-any.whl.metadata (4.6 kB)\n",
"Collecting importlib_metadata>=4.13.0 (from dask[array]->odc-stac)\n",
" Downloading importlib_metadata-8.7.0-py3-none-any.whl.metadata (4.8 kB)\n",
"Collecting aiohttp!=4.0.0a0,!=4.0.0a1 (from fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading aiohttp-3.12.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.7 kB)\n",
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.24->segmentation-models-pytorch>=0.5->torchgeo==0.8.0.dev0) (1.1.7)\n",
"Collecting antlr4-python3-runtime==4.9.* (from hydra-core>=1.0.0->lightly!=1.4.26,>=1.4.5->torchgeo==0.8.0.dev0)\n",
" Downloading antlr4-python3-runtime-4.9.3.tar.gz (117 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m117.0/117.0 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
"Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.11/dist-packages (from importlib_metadata>=4.13.0->dask[array]->odc-stac) (3.23.0)\n",
"Requirement already satisfied: docstring-parser>=0.17 in /usr/local/lib/python3.11/dist-packages (from jsonargparse[jsonnet,signatures]<5.0,>=4.39.0; extra == \"pytorch-extra\"->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (0.17.0)\n",
"Collecting typeshed-client>=2.8.2 (from jsonargparse[jsonnet,signatures]<5.0,>=4.39.0; extra == \"pytorch-extra\"->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading typeshed_client-2.8.2-py3-none-any.whl.metadata (9.9 kB)\n",
"Collecting jsonnet>=0.21.0 (from jsonargparse[jsonnet,signatures]<5.0,>=4.39.0; extra == \"pytorch-extra\"->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading jsonnet-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (449 bytes)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.11/dist-packages (from lightning-utilities<2.0,>=0.10.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (75.2.0)\n",
"Collecting locket (from partd>=1.4.0->dask[array]->odc-stac)\n",
" Downloading locket-1.0.0-py2.py3-none-any.whl.metadata (2.8 kB)\n",
"Requirement already satisfied: jsonschema~=4.18 in /usr/local/lib/python3.11/dist-packages (from pystac[validation]>=1.10.0->pystac-client>=0.2.0->planetary-computer) (4.25.0)\n",
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.11/dist-packages (from rich<15.0,>=12.3.0->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (3.0.0)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.11/dist-packages (from rich<15.0,>=12.3.0->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (2.19.2)\n",
"Requirement already satisfied: protobuf>=3.20 in /usr/local/lib/python3.11/dist-packages (from tensorboardX<3.0,>=2.2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (6.31.1)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch>=2->torchgeo==0.8.0.dev0) (3.0.2)\n",
"Collecting aiohappyeyeballs>=2.5.0 (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading aiohappyeyeballs-2.6.1-py3-none-any.whl.metadata (5.9 kB)\n",
"Collecting aiosignal>=1.4.0 (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading aiosignal-1.4.0-py3-none-any.whl.metadata (3.7 kB)\n",
"Collecting frozenlist>=1.1.1 (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading frozenlist-1.7.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (6.6.3)\n",
"Collecting propcache>=0.2.0 (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading propcache-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n",
"Collecting yarl<2.0,>=1.17.0 (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<2027.0,>=2022.5.0->lightning!=2.3.*,!=2.5.0,>=2->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0)\n",
" Downloading yarl-1.20.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (73 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.9/73.9 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.11/dist-packages (from jsonschema~=4.18->pystac[validation]>=1.10.0->pystac-client>=0.2.0->planetary-computer) (2025.4.1)\n",
"Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.11/dist-packages (from jsonschema~=4.18->pystac[validation]>=1.10.0->pystac-client>=0.2.0->planetary-computer) (0.36.2)\n",
"Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.11/dist-packages (from jsonschema~=4.18->pystac[validation]>=1.10.0->pystac-client>=0.2.0->planetary-computer) (0.26.0)\n",
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.11/dist-packages (from markdown-it-py>=2.2.0->rich<15.0,>=12.3.0->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (0.1.2)\n",
"Requirement already satisfied: importlib_resources>=1.4.0 in /usr/local/lib/python3.11/dist-packages (from typeshed-client>=2.8.2->jsonargparse[jsonnet,signatures]<5.0,>=4.39.0; extra == \"pytorch-extra\"->lightning[pytorch-extra]!=2.3.*,!=2.5.0,>=2->torchgeo==0.8.0.dev0) (6.5.2)\n",
"Downloading planetary_computer-1.0.0-py3-none-any.whl (14 kB)\n",
"Downloading rioxarray-0.19.0-py3-none-any.whl (62 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.2/62.2 kB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading odc_stac-0.4.0-py3-none-any.whl (44 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m44.3/44.3 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading fiona-1.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.3/17.3 MB\u001b[0m \u001b[31m90.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading geopandas-1.1.1-py3-none-any.whl (338 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m338.4/338.4 kB\u001b[0m \u001b[31m18.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading kornia-0.8.1-py2.py3-none-any.whl (1.1 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m46.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading lightly-1.5.22-py3-none-any.whl (859 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m859.3/859.3 kB\u001b[0m \u001b[31m43.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading lightning-2.5.2-py3-none-any.whl (821 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m821.1/821.1 kB\u001b[0m \u001b[31m43.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading odc_geo-0.4.10-py3-none-any.whl (155 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m155.1/155.1 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading odc_loader-0.5.1-py3-none-any.whl (50 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.7/50.7 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading pyproj-3.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.5 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.5/9.5 MB\u001b[0m \u001b[31m109.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading pystac-1.13.0-py3-none-any.whl (206 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m206.8/206.8 kB\u001b[0m \u001b[31m12.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading pystac_client-0.9.0-py3-none-any.whl (41 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.8/41.8 kB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading rasterio-1.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m22.2/22.2 MB\u001b[0m \u001b[31m101.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading segmentation_models_pytorch-0.5.0-py3-none-any.whl (154 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m154.8/154.8 kB\u001b[0m \u001b[31m11.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading shapely-2.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m86.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading timm-1.0.19-py3-none-any.whl (2.5 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.5/2.5 MB\u001b[0m \u001b[31m70.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading torchmetrics-1.8.1-py3-none-any.whl (982 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m983.0/983.0 kB\u001b[0m \u001b[31m48.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading xarray-2025.7.1-py3-none-any.whl (1.3 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m57.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading affine-2.4.0-py3-none-any.whl (15 kB)\n",
"Downloading python_dotenv-1.1.1-py3-none-any.whl (20 kB)\n",
"Downloading aenum-3.1.16-py3-none-any.whl (165 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m165.6/165.6 kB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading bitsandbytes-0.47.0-py3-none-manylinux_2_24_x86_64.whl (61.3 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.3/61.3 MB\u001b[0m \u001b[31m20.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading click_plugins-1.1.1.2-py2.py3-none-any.whl (11 kB)\n",
"Downloading cligj-0.7.2-py3-none-any.whl (7.1 kB)\n",
"Downloading hydra_core-1.3.2-py3-none-any.whl (154 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m154.5/154.5 kB\u001b[0m \u001b[31m10.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading importlib_metadata-8.7.0-py3-none-any.whl (27 kB)\n",
"Downloading jsonargparse-4.40.2-py3-none-any.whl (225 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.0/225.0 kB\u001b[0m \u001b[31m16.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading kornia_rs-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m84.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading lightly_utils-0.0.2-py3-none-any.whl (6.4 kB)\n",
"Downloading lightning_utilities-0.15.2-py3-none-any.whl (29 kB)\n",
"Downloading omegaconf-2.3.0-py3-none-any.whl (79 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.5/79.5 kB\u001b[0m \u001b[31m1.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading partd-1.4.2-py3-none-any.whl (18 kB)\n",
"Downloading pyogrio-0.11.1-cp311-cp311-manylinux_2_28_x86_64.whl (27.7 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m27.7/27.7 MB\u001b[0m \u001b[31m65.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading pytorch_lightning-2.5.2-py3-none-any.whl (825 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m825.4/825.4 kB\u001b[0m \u001b[31m35.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading tensorboardx-2.6.4-py3-none-any.whl (87 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m87.2/87.2 kB\u001b[0m \u001b[31m6.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading dask-2025.7.0-py3-none-any.whl (1.5 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m42.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading aiohttp-3.12.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m48.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading jsonnet-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.5/6.5 MB\u001b[0m \u001b[31m90.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading typeshed_client-2.8.2-py3-none-any.whl (760 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m760.5/760.5 kB\u001b[0m \u001b[31m36.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading locket-1.0.0-py2.py3-none-any.whl (4.4 kB)\n",
"Downloading aiohappyeyeballs-2.6.1-py3-none-any.whl (15 kB)\n",
"Downloading aiosignal-1.4.0-py3-none-any.whl (7.5 kB)\n",
"Downloading frozenlist-1.7.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (235 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m235.3/235.3 kB\u001b[0m \u001b[31m14.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading propcache-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (213 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m213.5/213.5 kB\u001b[0m \u001b[31m14.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hDownloading yarl-1.20.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m349.0/349.0 kB\u001b[0m \u001b[31m20.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hBuilding wheels for collected packages: torchgeo, antlr4-python3-runtime\n",
" Building wheel for torchgeo (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for torchgeo: filename=torchgeo-0.8.0.dev0-py3-none-any.whl size=634835 sha256=1a7f0e4f3d236999748e6e768354c81347a6e065fb10028e272c4e38bdf21d8d\n",
" Stored in directory: /tmp/pip-ephem-wheel-cache-nse10ouv/wheels/eb/30/53/f16e9d442fe2f915c7ef057f93e504d5fa9ec81912caea1dbd\n",
" Building wheel for antlr4-python3-runtime (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for antlr4-python3-runtime: filename=antlr4_python3_runtime-4.9.3-py3-none-any.whl size=144591 sha256=1981faadabd52db681dfadb4be0e73a2d19c2b4b7999e1e265581821af8006a3\n",
" Stored in directory: /root/.cache/pip/wheels/1a/97/32/461f837398029ad76911109f07047fde1d7b661a147c7c56d1\n",
"Successfully built torchgeo antlr4-python3-runtime\n",
"Installing collected packages: jsonnet, antlr4-python3-runtime, aenum, typeshed-client, tensorboardX, shapely, python-dotenv, pyproj, pyogrio, propcache, omegaconf, locket, lightning-utilities, lightly_utils, kornia_rs, jsonargparse, importlib_metadata, frozenlist, cligj, click-plugins, aiohappyeyeballs, affine, yarl, rasterio, pystac, partd, odc-geo, hydra-core, fiona, aiosignal, xarray, torchmetrics, kornia, geopandas, dask, bitsandbytes, aiohttp, timm, rioxarray, segmentation-models-pytorch, pytorch_lightning, pystac-client, odc-loader, planetary-computer, odc-stac, lightning, lightly, torchgeo\n",
" Attempting uninstall: importlib_metadata\n",
" Found existing installation: importlib-metadata 4.6.4\n",
" Uninstalling importlib-metadata-4.6.4:\n",
" Successfully uninstalled importlib-metadata-4.6.4\n",
"Successfully installed aenum-3.1.16 affine-2.4.0 aiohappyeyeballs-2.6.1 aiohttp-3.12.15 aiosignal-1.4.0 antlr4-python3-runtime-4.9.3 bitsandbytes-0.47.0 click-plugins-1.1.1.2 cligj-0.7.2 dask-2025.7.0 fiona-1.10.1 frozenlist-1.7.0 geopandas-1.1.1 hydra-core-1.3.2 importlib_metadata-8.7.0 jsonargparse-4.40.2 jsonnet-0.21.0 kornia-0.8.1 kornia_rs-0.1.9 lightly-1.5.22 lightly_utils-0.0.2 lightning-2.5.2 lightning-utilities-0.15.2 locket-1.0.0 odc-geo-0.4.10 odc-loader-0.5.1 odc-stac-0.4.0 omegaconf-2.3.0 partd-1.4.2 planetary-computer-1.0.0 propcache-0.3.2 pyogrio-0.11.1 pyproj-3.7.1 pystac-1.13.0 pystac-client-0.9.0 python-dotenv-1.1.1 pytorch_lightning-2.5.2 rasterio-1.4.3 rioxarray-0.19.0 segmentation-models-pytorch-0.5.0 shapely-2.1.1 tensorboardX-2.6.4 timm-1.0.19 torchgeo-0.8.0.dev0 torchmetrics-1.8.1 typeshed-client-2.8.2 xarray-2025.7.1 yarl-1.20.1\n"
]
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"pydevd_plugins"
]
},
"id": "ee69c4926b5d4dd680d7ae1b9a1888c8"
}
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"#@title CDL class name and color definitions\n",
"\n",
"CDL_CODE_TO_NAME = {\n",
" 0: \"Background\",\n",
" 1: \"Corn\",\n",
" 2: \"Cotton\",\n",
" 3: \"Rice\",\n",
" 4: \"Sorghum\",\n",
" 5: \"Soybeans\",\n",
" 6: \"Sunflower\",\n",
" 10: \"Peanuts\",\n",
" 11: \"Tobacco\",\n",
" 12: \"Sweet Corn\",\n",
" 13: \"Pop or Orn Corn\",\n",
" 14: \"Mint\",\n",
" 21: \"Barley\",\n",
" 22: \"Durum Wheat\",\n",
" 23: \"Spring Wheat\",\n",
" 24: \"Winter Wheat\",\n",
" 25: \"Other Small Grains\",\n",
" 26: \"Dbl Crop WinWht/Soybeans\",\n",
" 27: \"Rye\",\n",
" 28: \"Oats\",\n",
" 29: \"Millet\",\n",
" 30: \"Speltz\",\n",
" 31: \"Canola\",\n",
" 32: \"Flaxseed\",\n",
" 33: \"Safflower\",\n",
" 34: \"Rape Seed\",\n",
" 35: \"Mustard\",\n",
" 36: \"Alfalfa\",\n",
" 37: \"Other Hay/Non Alfalfa\",\n",
" 38: \"Camelina\",\n",
" 39: \"Buckwheat\",\n",
" 41: \"Sugarbeets\",\n",
" 42: \"Dry Beans\",\n",
" 43: \"Potatoes\",\n",
" 44: \"Other Crops\",\n",
" 45: \"Sugarcane\",\n",
" 46: \"Sweet Potatoes\",\n",
" 47: \"Misc Vegs & Fruits\",\n",
" 48: \"Watermelons\",\n",
" 49: \"Onions\",\n",
" 50: \"Cucumbers\",\n",
" 51: \"Chick Peas\",\n",
" 52: \"Lentils\",\n",
" 53: \"Peas\",\n",
" 54: \"Tomatoes\",\n",
" 55: \"Caneberries\",\n",
" 56: \"Hops\",\n",
" 57: \"Herbs\",\n",
" 58: \"Clover/Wildflowers\",\n",
" 59: \"Sod/Grass Seed\",\n",
" 60: \"Switchgrass\",\n",
" 61: \"Fallow/Idle Cropland\",\n",
" 63: \"Forest\",\n",
" 64: \"Shrubland\",\n",
" 65: \"Barren\",\n",
" 66: \"Cherries\",\n",
" 67: \"Peaches\",\n",
" 68: \"Apples\",\n",
" 69: \"Grapes\",\n",
" 70: \"Christmas Trees\",\n",
" 71: \"Other Tree Crops\",\n",
" 72: \"Citrus\",\n",
" 74: \"Pecans\",\n",
" 75: \"Almonds\",\n",
" 76: \"Walnuts\",\n",
" 77: \"Pears\",\n",
" 81: \"Clouds/No Data\",\n",
" 82: \"Developed\",\n",
" 83: \"Water\",\n",
" 87: \"Wetlands\",\n",
" 88: \"Nonag/Undefined\",\n",
" 92: \"Aquaculture\",\n",
" 111: \"Open Water\",\n",
" 112: \"Perennial Ice/Snow\",\n",
" 121: \"Developed/Open Space\",\n",
" 122: \"Developed/Low Intensity\",\n",
" 123: \"Developed/Med Intensity\",\n",
" 124: \"Developed/High Intensity\",\n",
" 131: \"Barren\",\n",
" 141: \"Deciduous Forest\",\n",
" 142: \"Evergreen Forest\",\n",
" 143: \"Mixed Forest\",\n",
" 152: \"Shrubland\",\n",
" 176: \"Grass/Pasture\",\n",
" 190: \"Woody Wetlands\",\n",
" 195: \"Herbaceous Wetlands\",\n",
" 204: \"Pistachios\",\n",
" 205: \"Triticale\",\n",
" 206: \"Carrots\",\n",
" 207: \"Asparagus\",\n",
" 208: \"Garlic\",\n",
" 209: \"Cantaloupes\",\n",
" 210: \"Prunes\",\n",
" 211: \"Olives\",\n",
" 212: \"Oranges\",\n",
" 213: \"Honeydew Melons\",\n",
" 214: \"Broccoli\",\n",
" 215: \"Avocados\",\n",
" 216: \"Peppers\",\n",
" 217: \"Pomegranates\",\n",
" 218: \"Nectarines\",\n",
" 219: \"Greens\",\n",
" 220: \"Plums\",\n",
" 221: \"Strawberries\",\n",
" 222: \"Squash\",\n",
" 223: \"Apricots\",\n",
" 224: \"Vetch\",\n",
" 225: \"Dbl Crop WinWht/Corn\",\n",
" 226: \"Dbl Crop Oats/Corn\",\n",
" 227: \"Lettuce\",\n",
" 228: \"Dbl Crop Triticale/Corn\",\n",
" 229: \"Pumpkins\",\n",
" 230: \"Dbl Crop Lettuce/Durum Wht\",\n",
" 231: \"Dbl Crop Lettuce/Cantaloupe\",\n",
" 232: \"Dbl Crop Lettuce/Cotton\",\n",
" 233: \"Dbl Crop Lettuce/Barley\",\n",
" 234: \"Dbl Crop Durum Wht/Sorghum\",\n",
" 235: \"Dbl Crop Barley/Sorghum\",\n",
" 236: \"Dbl Crop WinWht/Sorghum\",\n",
" 237: \"Dbl Crop Barley/Corn\",\n",
" 238: \"Dbl Crop WinWht/Cotton\",\n",
" 239: \"Dbl Crop Soybeans/Cotton\",\n",
" 240: \"Dbl Crop Soybeans/Oats\",\n",
" 241: \"Dbl Crop Corn/Soybeans\",\n",
" 242: \"Blueberries\",\n",
" 243: \"Cabbage\",\n",
" 244: \"Cauliflower\",\n",
" 245: \"Celery\",\n",
" 246: \"Radishes\",\n",
" 247: \"Turnips\",\n",
" 248: \"Eggplants\",\n",
" 249: \"Gourds\",\n",
" 250: \"Cranberries\",\n",
" 254: \"Dbl Crop Barley/Soybeans\",\n",
"}\n",
"\n",
"CDL_CODE_TO_COLOR = {\n",
" 0: \"#000000\",\n",
" 1: \"#ffd400\",\n",
" 2: \"#ff2626\",\n",
" 3: \"#00a9e6\",\n",
" 4: \"#ff9e0f\",\n",
" 5: \"#267300\",\n",
" 6: \"#ffff00\",\n",
" 10: \"#70a800\",\n",
" 11: \"#00af4d\",\n",
" 12: \"#e0a60f\",\n",
" 13: \"#e0a60f\",\n",
" 14: \"#80d4ff\",\n",
" 21: \"#e2007f\",\n",
" 22: \"#8a6453\",\n",
" 23: \"#d9b56c\",\n",
" 24: \"#a87000\",\n",
" 25: \"#d69dbc\",\n",
" 26: \"#737300\",\n",
" 27: \"#ae017e\",\n",
" 28: \"#a15889\",\n",
" 29: \"#73004c\",\n",
" 30: \"#d69dbc\",\n",
" 31: \"#d1ff00\",\n",
" 32: \"#8099ff\",\n",
" 33: \"#d6d600\",\n",
" 34: \"#d1ff00\",\n",
" 35: \"#00af4d\",\n",
" 36: \"#ffa8e3\",\n",
" 37: \"#a5f58d\",\n",
" 38: \"#00af4d\",\n",
" 39: \"#d69dbc\",\n",
" 41: \"#a900e6\",\n",
" 42: \"#a80000\",\n",
" 43: \"#732600\",\n",
" 44: \"#00af4d\",\n",
" 45: \"#b380ff\",\n",
" 46: \"#732600\",\n",
" 47: \"#ff6666\",\n",
" 48: \"#ff6666\",\n",
" 49: \"#ffcc66\",\n",
" 50: \"#ff6666\",\n",
" 51: \"#00af4d\",\n",
" 52: \"#00deb0\",\n",
" 53: \"#55ff00\",\n",
" 54: \"#f5a27a\",\n",
" 55: \"#ff6666\",\n",
" 56: \"#00af4d\",\n",
" 57: \"#80d4ff\",\n",
" 58: \"#e8beff\",\n",
" 59: \"#b2ffde\",\n",
" 60: \"#00af4d\",\n",
" 61: \"#bfbf7a\",\n",
" 63: \"#95ce93\",\n",
" 64: \"#c7d79e\",\n",
" 65: \"#ccbfa3\",\n",
" 66: \"#ff00ff\",\n",
" 67: \"#ff91ab\",\n",
" 68: \"#b90050\",\n",
" 69: \"#704489\",\n",
" 70: \"#007878\",\n",
" 71: \"#b39c70\",\n",
" 72: \"#ffff80\",\n",
" 74: \"#b6705c\",\n",
" 75: \"#00a884\",\n",
" 76: \"#ebd6b0\",\n",
" 77: \"#b39c70\",\n",
" 81: \"#f7f7f7\",\n",
" 82: \"#9c9c9c\",\n",
" 83: \"#4d70a3\",\n",
" 87: \"#80b3b3\",\n",
" 88: \"#e9ffbe\",\n",
" 92: \"#00ffff\",\n",
" 111: \"#4d70a3\",\n",
" 112: \"#d4e3fc\",\n",
" 121: \"#9c9c9c\",\n",
" 122: \"#9c9c9c\",\n",
" 123: \"#9c9c9c\",\n",
" 124: \"#9c9c9c\",\n",
" 131: \"#ccbfa3\",\n",
" 141: \"#95ce93\",\n",
" 142: \"#95ce93\",\n",
" 143: \"#95ce93\",\n",
" 152: \"#c7d79e\",\n",
" 176: \"#e9ffbe\",\n",
" 190: \"#80b3b3\",\n",
" 195: \"#80b3b3\",\n",
" 204: \"#00ff8c\",\n",
" 205: \"#d69dbc\",\n",
" 206: \"#ff6666\",\n",
" 207: \"#ff6666\",\n",
" 208: \"#ff6666\",\n",
" 209: \"#ff6666\",\n",
" 210: \"#ff91ab\",\n",
" 211: \"#344a34\",\n",
" 212: \"#e67525\",\n",
" 213: \"#ff6666\",\n",
" 214: \"#ff6666\",\n",
" 215: \"#66994d\",\n",
" 216: \"#ff6666\",\n",
" 217: \"#b39c70\",\n",
" 218: \"#ff91ab\",\n",
" 219: \"#ff6666\",\n",
" 220: \"#ff91ab\",\n",
" 221: \"#ff6666\",\n",
" 222: \"#ff6666\",\n",
" 223: \"#ff91ab\",\n",
" 224: \"#00af4d\",\n",
" 225: \"#ffd400\",\n",
" 226: \"#ffd400\",\n",
" 227: \"#ff6666\",\n",
" 228: \"#ffd400\",\n",
" 229: \"#ff6666\",\n",
" 230: \"#8a6453\",\n",
" 231: \"#ff6666\",\n",
" 232: \"#ff2626\",\n",
" 233: \"#e2007f\",\n",
" 234: \"#ff9e0f\",\n",
" 235: \"#ff9e0f\",\n",
" 236: \"#a87000\",\n",
" 237: \"#ffd400\",\n",
" 238: \"#a87000\",\n",
" 239: \"#267300\",\n",
" 240: \"#267300\",\n",
" 241: \"#ffd400\",\n",
" 242: \"#000099\",\n",
" 243: \"#ff6666\",\n",
" 244: \"#ff6666\",\n",
" 245: \"#ff6666\",\n",
" 246: \"#ff6666\",\n",
" 247: \"#ff6666\",\n",
" 248: \"#ff6666\",\n",
" 249: \"#ff6666\",\n",
" 250: \"#ff6666\",\n",
" 254: \"#267300\",\n",
"}\n"
],
"metadata": {
"cellView": "form",
"id": "b84d8TRxhmza"
},
"id": "b84d8TRxhmza",
"execution_count": 48,
"outputs": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "82e7cc79",
"metadata": {
"id": "82e7cc79"
},
"outputs": [],
"source": [
"import fiona\n",
"import fiona.transform\n",
"import rasterio\n",
"import rasterio.mask\n",
"import shapely.geometry\n",
"import rioxarray\n",
"import matplotlib.pyplot as plt\n",
"import odc.stac\n",
"import pystac_client\n",
"import planetary_computer\n",
"\n",
"import os\n",
"import rasterio.features\n",
"\n",
"from torchgeo.models import Unet_Weights, unet\n",
"from torchgeo.datasets import RasterDataset\n",
"from torch.utils.data import DataLoader\n",
"from torchgeo.datasets import stack_samples\n",
"from torchgeo.samplers import GridGeoSampler\n",
"from torchvision.transforms import v2\n",
"from torchgeo.datasets import CDL\n",
"import torch\n",
"import numpy as np\n",
"from tqdm import tqdm\n",
"\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.metrics import accuracy_score, classification_report"
]
},
{
"cell_type": "markdown",
"id": "c47f4a9b",
"metadata": {
"id": "c47f4a9b"
},
"source": [
"# Step 1 - Get boundaries\n",
"\n",
"The first part of this tutorial is about downloading Sentinel 2 satellite imagery, running Fields of the World pretrained models on them to extract field boundaries, and vectorizing the model output."
]
},
{
"cell_type": "markdown",
"id": "aeb91ddc",
"metadata": {
"id": "aeb91ddc"
},
"source": [
"## Step 1.A - Get input Sentinel-2 imagery for a given AOI/TOI"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6a7f956b",
"metadata": {
"id": "6a7f956b"
},
"outputs": [],
"source": [
"catalog = pystac_client.Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
" modifier=planetary_computer.sign_inplace,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8c759dd8",
"metadata": {
"id": "8c759dd8"
},
"outputs": [],
"source": [
"# Somewhere in Iowa\n",
"area_of_interest = {\n",
" \"type\": \"Polygon\",\n",
" \"coordinates\": [\n",
" [\n",
" [-92.13258568816984, 41.558822720384242],\n",
" [-91.943312125764507, 41.558822720384242],\n",
" [-91.943312125764507, 41.698581483307763],\n",
" [-92.13258568816984, 41.698581483307763],\n",
" [-92.13258568816984, 41.558822720384242],\n",
" ]\n",
" ],\n",
"}\n",
"time_of_interest_a = \"2024-05-01/2024-09-30\"\n",
"time_of_interest_b = \"2024-09-01/2024-12-31\"\n",
"\n",
"\n",
"search = catalog.search(\n",
" collections=[\"sentinel-2-l2a\"],\n",
" intersects=area_of_interest,\n",
" datetime=time_of_interest_a,\n",
" query={\"eo:cloud_cover\": {\"lt\": 10}},\n",
")\n",
"items_a = search.item_collection()\n",
"\n",
"search = catalog.search(\n",
" collections=[\"sentinel-2-l2a\"],\n",
" intersects=area_of_interest,\n",
" datetime=time_of_interest_b,\n",
" query={\"eo:cloud_cover\": {\"lt\": 10}},\n",
")\n",
"items_b = search.item_collection()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "33607b73",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "33607b73",
"outputId": "7b700c68-0e64-44ca-8c1e-2b732cf2bc37"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Using MGRS tile 15TWG for both items.\n",
"Window A: 2024-09-29T16:50:19.024000Z\n",
"Window B: 2024-12-08T16:56:19.024000Z\n"
]
}
],
"source": [
"item_a = items_a[0]\n",
"item_b = items_b[0]\n",
"\n",
"assert item_a.properties[\"s2:mgrs_tile\"] == item_b.properties[\"s2:mgrs_tile\"], (\n",
" \"MGRS tiles do not match\"\n",
")\n",
"\n",
"print(f\"Using MGRS tile {item_a.properties['s2:mgrs_tile']} for both items.\")\n",
"print(f\"Window A: {item_a.properties['datetime']}\")\n",
"print(f\"Window B: {item_b.properties['datetime']}\")\n",
"\n",
"crs = item_a.properties[\"proj:code\"]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "acaddfd0",
"metadata": {
"id": "acaddfd0"
},
"outputs": [],
"source": [
"# warp the AOI geometry to the CRS of the items\n",
"area_of_interest_warped = fiona.transform.transform_geom(\n",
" \"EPSG:4326\",\n",
" crs,\n",
" area_of_interest,\n",
")\n",
"bbox = shapely.geometry.shape(area_of_interest).bounds"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "72b75309",
"metadata": {
"id": "72b75309"
},
"outputs": [],
"source": [
"data = odc.stac.load(\n",
" [item_a, item_b],\n",
" bands=[\"B04\", \"B03\", \"B02\", \"B08\"],\n",
" dtype=\"uint16\",\n",
" crs=crs,\n",
" resampling=\"bilinear\",\n",
" bbox=bbox,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "dae79679",
"metadata": {
"id": "dae79679"
},
"outputs": [],
"source": [
"data = (\n",
" data.to_array(dim=\"band\")\n",
" .stack(bands=(\"time\", \"band\"))\n",
" .drop_vars(\"band\")\n",
" .transpose(\"bands\", \"y\", \"x\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "44c0fa3b",
"metadata": {
"id": "44c0fa3b"
},
"outputs": [],
"source": [
"data.rio.to_raster(\n",
" \"merged_imagery.tif\",\n",
" driver=\"GTiff\",\n",
" compress=\"deflate\",\n",
" dtype=\"uint16\",\n",
" tiled=True,\n",
" blockxsize=256,\n",
" blockysize=256,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ea5bb5a4",
"metadata": {
"id": "ea5bb5a4"
},
"outputs": [],
"source": [
"with rasterio.open(\"merged_imagery.tif\") as f:\n",
" data = f.read().transpose(1, 2, 0)\n",
"\n",
" img_a = data[:, :, :3] / 3000 # Normalize to ~0-1 range\n",
" img_b = data[:, :, 4:7] / 3000"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "90d97a88",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 663
},
"id": "90d97a88",
"outputId": "226606b3-0705-49c2-88cf-644a72fee9c0"
},
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [0.35833333333333334..3.2773333333333334].\n",
"WARNING:matplotlib.image:Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [0.317..3.522666666666667].\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 1200x600 with 2 Axes>"
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment