Earth Engine + Apache Beam
Project description
geebeam
Google Earth Engine and Apache Beam for building geospatial training datasets.
Purpose:
geebeam is a lightweight library for building and executing Apache Beam pipelines that download data "chips" from Google Earth Engine and write them to a variety of common data formats (GeoTIFF, WebDataset, TensorFlow Dataset).
The user defines the Earth Engine images they want to download chips from using the Python earthengine-api. geebeam then serialized the graph-definition of the images so they can be passed to the Beam workers.
The pipelines are automatically parallelized and can be run locally or on Google Cloud Dataflow.
Install:
pip install geebeam
Examples:
Running locally:
Here we'll create a cloud-free Landsat 5 data composite for 2010. We'll randomly sample 10 locations and download them as GeoTIFFs. This should only ~1 second per tiff, since Earth Engine is doing the heavy lifting behind the scenes.
import ee
import geebeam
import google
# Get default project id from environment (or specify PROJECT_ID manually)
PROJECT_ID = google.auth.default()[1]
# Initialize ee client, replace with your GCP project ID
ee.Initialize(project=PROJECT_ID)
### Build image for download
# Load a raw Landsat 5 ImageCollection for a single year.
ls5_collection = ee.ImageCollection('LANDSAT/LT05/C02/T1').filterDate(
'2010-01-01', '2010-12-31'
)
# Create a (mostly) cloud-free Landsat composite
ls5_composite = ee.Algorithms.Landsat.simpleComposite(
ls5_collection,
asFloat=True,
cloudScoreRange=5)
# Building and triggering the pipeline is done with a single command:
geebeam.sample_and_run_pipeline(
image_list = [ls5_composite], # Important: has to be a list of images
sampling_region=ee.Geometry.Rectangle(-55.0, -12.0, -50.0, -16.0), # In central-west Brazil
n_sample=10, # Number of tiles to sample
patch_size=128, # Number of pixels in each direction
scale=30, # Final export resolution in meters
crs='EPSG:4326', # CRS for final output
project=PROJECT_ID, # GCP Project ID
output_path='./test_data/', # Output path, local or on GCP
validation_ratio=0.2, # Fraction to select as validation data
)
Now let's add another dataset: MapBiomas land-cover from same year. For more info, and legend, see: MapBiomas Brasil
# MB Land-use/land-cover
mb_lulc = (
ee.Image('projects/mapbiomas-public/assets/brazil/lulc/collection10_1/mapbiomas_brazil_collection10_1_coverage_v1')
.select('classification_2010')
)
# Exporting both together is as simple as this:
geebeam.sample_and_run_pipeline(
image_list = [ls5_composite, mb_lulc],
project=PROJECT_ID,
crs='EPSG:4326',
patch_size=128,
scale=30,
n_sample=10,
validation_ratio=0.2,
output_path='./test_data_w_mb/',
sampling_region=ee.Geometry.Rectangle(-55.0, -12.0, -50.0, -16.0)
)
Scaling up with DataFlow:
The export process can be scaled to many workers via Google Cloud DataFlow. First write a script containing your geebeam.run_pipeline() command. Then execute using the Beam DataFlow runner:
python examples/geebeam_run.py \
--region=us-east1 \
--worker=zone us-east1-b \
--runner=DataflowRunner \
--max_num_workers=8 \
--experiments=use_runner_v2 \
--temp_location=gs://[your-bucket]/[path_to_temp_dir]
--machine_type=n2-highmem-2 \
--sdk_container_image=kysolvik/geebeam:[geebeam-version]
Note in this case your output_path in run_pipeline() should be a Google Cloud Storage path. Make sure to replace [geebeam-version] in the sdk_container_image URI with the version number installed on your system (python -c "import geebeam;print(geebeam.__version__)"). You can also build your own Docker image to run on. More info in the DataFlow docs.
See the Apache Beam and Google Cloud DataFlow docs for full documentation, e.g. pipeline command-line options.
Common DataFlow gotchas
-
Before running, you must enable the DataFlow API on Google Cloud Console.
-
You can test your pipeline script (e.g. geebeam_run.py) and Beam options using the DirectRunner before submitting to DataFlow:
python examples/geebeam_run.py \
--runner=DirectRunner
- For more common errors, see the Google Cloud DataFlow troubleshooting guide and geebeam's documentation.
Alternatives:
- GeeFlow: Google DeepMind's GeeFlow fulfills a similar purpose. It is more flexible, allowing for more user control of data processing, reprojection, and writing, but slower and no longer actively maintained. With the goal of meeting most users' needs, GeeBeam is designed to be easier and quicker to use, but allows from more limited data transformations.
- Export training data to Google Cloud Storage then download chips from there: This works, but if you need to get data from many different datasets it's slow to export all that data to Cloud Storage and can be expensive to store it there if you don't delete it quickly. This also uses unnecessary Earth Engine compute hours, which are now subject to stricter monthly limits.
- Xee: Xee is a great package that allows for accessing Earth Engine objects as xarray.Datasets. You could use this to define a xarray.Dataset and download "chips" from it, but geebeam interfaces with Beam to automatically parallelize this task and export to a variety of common data formats (GeoTIFF, WebDataset, TensorFlow Datasets)
Disclaimer:
geebeam is a third-party library and is not affiliated with or endorsed by Google or the Apache Software Foundation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geebeam-0.4.0.tar.gz.
File metadata
- Download URL: geebeam-0.4.0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21fb0e4949c3f9294f39deef758e350f0bfb715887e86bf2aba6a355e19ec825
|
|
| MD5 |
b871868c25ea0611d769e0fe46b0d713
|
|
| BLAKE2b-256 |
64e3135d5958210e1ee9a97e4f502bbee3a5a58a84d1ee2c1787b0680ae1e2d4
|
Provenance
The following attestation bundles were made for geebeam-0.4.0.tar.gz:
Publisher:
release.yml on kysolvik/geebeam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
geebeam-0.4.0.tar.gz -
Subject digest:
21fb0e4949c3f9294f39deef758e350f0bfb715887e86bf2aba6a355e19ec825 - Sigstore transparency entry: 1567613255
- Sigstore integration time:
-
Permalink:
kysolvik/geebeam@2a1aa96bbb24a92579b7c8925c9f701010b54057 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/kysolvik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a1aa96bbb24a92579b7c8925c9f701010b54057 -
Trigger Event:
release
-
Statement type:
File details
Details for the file geebeam-0.4.0-py3-none-any.whl.
File metadata
- Download URL: geebeam-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
097bdaff05afcbd8ea579d89e1dab358540908acaf7ff1685e3207dd78f581c7
|
|
| MD5 |
92c01ac995aa477a579c4dfcf0d93564
|
|
| BLAKE2b-256 |
259a657e2421055387f9460344ad1675b8fa6cc1be27fd9960782f8b3dec17e3
|
Provenance
The following attestation bundles were made for geebeam-0.4.0-py3-none-any.whl:
Publisher:
release.yml on kysolvik/geebeam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
geebeam-0.4.0-py3-none-any.whl -
Subject digest:
097bdaff05afcbd8ea579d89e1dab358540908acaf7ff1685e3207dd78f581c7 - Sigstore transparency entry: 1567613259
- Sigstore integration time:
-
Permalink:
kysolvik/geebeam@2a1aa96bbb24a92579b7c8925c9f701010b54057 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/kysolvik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2a1aa96bbb24a92579b7c8925c9f701010b54057 -
Trigger Event:
release
-
Statement type: