Skip to main content

Wrapper function to request temporal and zonal statistics from Google Earth Engine

Project description

GEE Zonal

PyPI version GitHub issues GitHub stars

This python package provides a wrapper function to request temporal and zonal statistics from Google Earth Engine (GEE) datasets.

Summary

A zonal statistics function was created to ease the process of working with the GEE API. The function can work with any raster data loaded to EE (ee.ImageCollections or ee.Image) and vector features (geopandas.GeoDataFrame or ee.FeatureCollection), and returns tabular data.

Statistics can be requested at various temporal resolutions (original frequency, monthly, or annual). The workflow conducts pixel-by-pixel temporal aggregations, before summarizing statistics over target features.

Additionally, the package provides functionality to quickly search the GEE Catalog.

Documentation Pages

Installation

The required dependencies are earthengine-api, geopandas, geojson, and notebook. The package (and dependencies) can be installed via pip:

pip install gee_zonal

Setup

The Earth Engine Python API needs to be authenticated with a Google account. First, sign up to Google Earth Engine here.

Launch a jupyter notebook, and authenticate your account with the ee library.

import ee
ee.Authenticate()

You can check that this worked by running ee.Initialize(), then import and run the library:

from gee_zonal import ZonalStats, Catalog

If the pip installation is not working, you can recreate the environment before and install the package from source:

conda create -n ee
conda activate ee
conda install -c conda-forge earthengine-api geopandas notebook ipykernel​
git clone https://github.com/worldbank/GEE_Zonal.git
python setup.py build
python setup.py install
python -m ipykernel install --user --name ee --display-name "Earth Engine"

Usage

ZonalStats()

Main class to calculate temporal and zonal statistics using the GEE backend. The object can be initialized with parameters specifying data inputs and the type of aggregation.

import ee
from gee_zonal import ZonalStats
AOIs = ee.FeatureCollection('<id of ee.FeatureCollection>')
AOIs = '<path to shapefile>'
zs = ZonalStats(
  collection_id = 'LANDSAT/LC08/C01/T1_8DAY_NDVI',
  target_features = AOIs,
  statistic_type = "all", # all includes min, max, mean, and stddev
  frequency = "annual",
  temporal_stat = "mean"
)

See docstring for more details on the input parameters for ZonalStats() and the example notebook.

The output statistics can be retrieved directly in the notebook (as a DataFrame):

res = zs.runZonalStats()

Or retrieved from Google Drive as a csv table if an output_name and output_dir were specified.

Catalog()

Inventory of Earth Engine datasets with some functions to search catalog by tags, title, and year / time period

from gee_zonal import Catalog
cat = Catalog()

The catalog object contains a datasets variable, a DataFrame containing a copy of the Earth Engine data catalog, retrieved from Earth-Engine-Datasets-List.

cat.datasets

Search functions

results = cat.search_tags("ndvi")
results = results.search_by_period(1985, 2021)
results = results.search_title("landsat")
print(results)

Additional Resources

License

World Bank Master Community License Agreement.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gee_zonal-0.1.2.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gee_zonal-0.1.2-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file gee_zonal-0.1.2.tar.gz.

File metadata

  • Download URL: gee_zonal-0.1.2.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gee_zonal-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fdf9e9f9e17528e91e91e00633c2077063a735dbec31a5b19887cfbdd3a5244d
MD5 35bfdd733f1250c72d05c1eab54c7e0e
BLAKE2b-256 ae7bb46babf755b18f521aaeb45797ebaec7b62b6031796f6f3772904c25e1c2

See more details on using hashes here.

File details

Details for the file gee_zonal-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gee_zonal-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gee_zonal-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e92ec2f986ee258c75984e4e825169bf9da34aeb5d2dbb983dd4e2da6e439b2
MD5 c22b62a8eedb6ca77cbc3a7801db6232
BLAKE2b-256 9a9810d7a444a85f38fd9d8a6158ed9968570d5500d2002014f7d81283c6ef7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page