Skip to content

Pixelverse

Generate and store geospatial foundation model embeddings using cloud-native tooling!

Example usage

Import functions

import rioxarray
import torch
import xarray as xr

from pixelverse.download.sentinel2 import get_s2_time_series
from pixelverse.generate_embeddings import generate_embeddings

Define Area of Interest (AOI)

Use get_s2_time_series to fetch Sentinel-2 imagery and get xarray.Dataset datacube.

SAMPLE_AOI_BBOX = (34.3040, 0.4835, 34.3178, 0.4973)
s2_dset: xr.Dataset = get_s2_time_series(bbox=SAMPLE_AOI_BBOX, year=2021)
s2_dset

Generate embeddings

Use generate_embeddings to create embeddings, e.g. with the Tessera Model:

embeddings: xr.Dataset = generate_embeddings(
    s2_dset=s2_dset,
    model_name="tessera_s2_encoder",
)

(Optional) Quantize embeddings

Use quantize_embeddings to convert from float32 to int8 and save disk space.

embeddings_quantized: xr.Dataset = quantize_embeddings(embeddings=embeddings)

Write embeddings

Save output to a Cloud-Optimized GeoTIFF (COG) using .rio.to_raster

embeddings["embedding"].rio.to_raster(
    "./sample_s2_embeddings_cog.tif",
    driver="COG",
    compress="ZSTD",
)

Or save to Zarr using .to_zarr.

embeddings["embedding"].to_zarr("./sample_s2_embeddings.zarr", mode="w")