Google Earth Engine website: https://earthengine.google.com/
JavaScript Code Editor: https://code.earthengine.google.com/
Documentation: https://developers.google.com/earth-engine/
Python API: https://developers.google.com/earth-engine/python_install
Author: Eduardo Ribeiro Lacerda - eduardolacerdageo@gmail.com
- Researcher @ Humboldt Universität zu Berlin
The Google Earth Engine Toolbox (GEET) is a JavaScript single-file library to help developers write small codebase applications with the Google Earth Engine (GEE) platform.
The library can also be used to teach new developers to use the platform even without any previous programming skills.
GEET using Landsat Collection 2 will be available soon!
All functions implemented (Version 1.9.1):
- ndvi_change_detection
- anomaly
- imad
- radcal
- radcalbatch
- ndwi_change_detection
- ndbi_change_detection
- burn_severity
- create_mosaic
- smooth_timeseries
- build_annual_landsat_timeseries
- landsat_timeseries
- landsat_timeseries_by_pathrow
- landsat_timeseries_by_roi
- harmonic_trend
- harmonize_sensors
- toa_radiance
- toa_reflectance
- brightness_temp
- surface_emissivity
- surface_temperature_tm
- surface_temperature_oli
- calculate_lst
- cloudmask
- cloudmask_sr
- fmask
- resample
- resample_band
- geom_filter
To use the library, you need to click on this link. It will automatically add all the code of the library in your Google Earth Engine personal account. You only need to perform this procedure once. Remember that to add the library, you must already have an account on the Earth Engine platform. To know more, visit the official site of the platform: https://earthengine.google.com/
After adding the library, you can call its functions using the function require and store the content in a variable. In this case, we will create a variable called geet which contains all the contents of the library. Then we can use it to call library functions:
var geet = require('users/eduardolacerdageo/geet:geet');
var image = geet.load_image('TOA', 2015); // Returns and loads an image on the map.Para utilizar a biblioteca, é preciso clicar neste link. Ele adicionará automaticamente todo o código da biblioteca à sua conta pessoal do Google Earth Engine. Só é necessário realizar este procedimento uma única vez. Lembre-se que para adicionar a biblioteca é necessário já possuir uma conta na plataforma do Earth Engine. Para saber mais, visite o site oficial da plataforma: https://earthengine.google.com/
Depois de adicionar a biblioteca é possível chamar suas funções utilizando a função require e armazenando o conteúdo em uma variável. Neste caso, criaremos uma variável chamada geet que contém todo o conteúdo da biblioteca. Depois, podemos utilizá-la para chamar as funções da biblioteca:
var geet = require('users/eduardolacerdageo/geet:geet');
var image = geet.load_image('TOA', 2015); // Retorna e carrega no mapa uma imagem.(image, trainingData, fieldName, kernelType, resolution)
Function to apply SVM classification to an image.
(ee.Image) image - The input image to classify.
(FeatureCollection) trainingData - Training data (samples).
optional (string) fieldName - The name of the column that contains the class names.
optional (string) kernelType - the kernel type of the classifier.
optional (number) resolution - the spatial resolution of the input image. Default is 30 (landsat).
var imgClass = geet.svm(image, samplesfc, landcover); (image, trainingData, fieldName, resolution)
Function to apply CART classification to an image.
(ee.Image) image - The input image to classify.
(FeatureCollection) trainingData - Training data (samples).
optional (string) fieldName - The name of the column that contains the class names.
optional (number) resolution - the spatial resolution of the input image. Default is 30 (landsat).
var imgClass = geet.cart(image, samplesfc, landcover); (image, trainingData, fieldName, numOfTrees, resolution, cv_split)
Function to apply Random Forest classification to an image.
(ee.Image) image - The input image to classify.
(array of strings) bands - The input band names that will be chosen to train the model.
(FeatureCollection) trainingData - All the training data (samples).
(string) fieldName - The name of the column that contains the class names.
optional (number) numOfTrees - The number of trees that the model will create. Default is 10.
optional (number) resolution - The spatial resolution of the input image. Default is 30 (Landsat).
optional (number) cv_split - The cross validation split percentage.
var imgClass = geet.rf(image, bands, samplesfc, landcover, 10); or
var imgClass = geet.rf(image, bands, samplesfc, landcover, 10, 30, 0.7); (image, trainingData, fieldName, resolution)
Function to apply the Fast Naive Bayes classification to an image.
(ee.Image) image - The input image to classify.
(FeatureCollection) trainingData - Training data (samples).
optional (string) fieldName - The name of the column that contains the class names.
optional (number) resolution - The spatial resolution of the input image. Default is 30 (Landsat).
var imgClass = geet.naive_bayes(image, samplesfc, landcover); or
var imgClass = geet.naive_bayes(image, samplesfc, landcover, 30); (image, trainingData, fieldName, resolution)
Function to apply the GMO Maximum Entropy classification to an image.
(ee.Image) image - The input image to classify.
(FeatureCollection) trainingData - Training data (samples).
optional (string) fieldName - The name of the column that contains the class names.
optional (number) resolution - The spatial resolution of the input image. Default is 30 (Landsat).
var imgClass = geet.max_ent(image, samplesfc, landcover); or
var imgClass = geet.max_ent(image, samplesfc, landcover, 30); (image, roi, numClusters, resolution, numPixels)
Function to apply RandomForest classification to an image.
(ee.Image) image - The input image to classify.
(Feature/Geometry) roi - A polygon containing the study area.
optional (number) _numClusters - the number of clusters that will be used. Default is 15.
optional (number) _scale - the scale number. The scale relates to the image's spatial resolution. Landsat is 30, so the default is 30 also.
optional (number) _numPixels - the number of pixels that the classifier will take samples from the roi.
var imgClass = geet.kmeans(image, roi); or
var imgClass = geet.kmeans(image, roi, 20, 10, 6000); (image, sensor, index)
Function to take an input image and generate indices like: NDVI, NDWI, NDBI...
More indices and features will be added in the future!
Supported indices: NDVI, NDWI, NDBI, NRVI, EVI, SAVI and GOSAVI
(ee.Image) image - the image to process.
(string) sensor - the sensor that you are working on: Landsat 5 ('L5'), 7 ('L7'), and 8 ('L8').
optional (string or string array) index - you can specify the index that you want
. If you don't specify any index, the function will create all possible indices.
var result = geet.landsat_indices(image, 'L5'); // Will create all possible indices. or specifying the index to generate:
var result = geet.landsat_indices(image, 'L5', 'savi'); // This will create only SAVI. or specifying an array of indices to generate:
var result = geet.landsat_indices(image, 'L5', ['ndvi', 'evi', 'ndwi']); // Creates only NDVI, EVI, and NDWI. (image, index)
Function to take an input image and generate indices using the Sentinel 2 dataset.
(image, sensor)
Function to generate advanced water quality indices: NDTI (Normalized Difference Turbidity Index) and NDCI (Normalized Difference Chlorophyll Index).
(ee.Image) image - the input image. (string) sensor - 'L8', 'L9' or 'S2'.
var water_img = geet.water_indices(s2_image, 'S2'); (image, sensor)
Generic function to create a Tasseled Cap image.
(ee.Image) image - the input image. (string) sensor - 'L5', 'L7', 'L8', 'L9', or 'S2'.
var image_tcap = geet.tasseled_cap(img, 'L8'); (image, nbands, scale, maxPixels)
Function produces the principal components analysis of an image.
(ee.Image) image - the input image.
optional (number) nBands - the number of bands of the image. Default is 12.
optional (number) scale - the scale number. The scale relates to the image's spatial resolution. Landsat is 30, so the default is 30 also.
optional (number) maxPixels - the maximum number of pixels that can be exported. Default is 1e10.
var pca = geet.pca(img);
var pca_image = ee.Image(pca[0]);
Map.addLayer(pca_image);(image)
Function that calculates the normalized difference vegetation index (NDVI) from Sentinel 2 data.
(ee.Image) image - the input image.
var s2_ndvi = geet.ndviS2(img);(img1, img2, sensor, threshold)
Function to detect changes between two input images using the NDVI index and a threshold parameter. The function adds the two masked indices and returns the sum of the two. It's a good choice to call the plot_class function to visualize the result. Ex: geet.plot_class(ndviChange, 3, 'change_detection');
(string) sensor = The name of the sensor that will be used. 'L5' or 'L8.
(ee.Image) img1 = The first input image.
(ee.Image) img2 = The second input image.
(ee.Number) threshold = The number of the threshold. All the values in the
image that are greater than or equal to this number
will be selected.
var ndviChange = geet.simpleNDVIChangeDetection(image_2014, image_2015, 'L8', 0.5); (img1, img2, sensor, threshold)
Function to detect changes between two input images using the NDWI index and a threshold parameter. The function adds the two masked indices and returns the sum of the two. It's a good choice to call the plot_class function to visualize the result. Ex: geet.plot_class(ndwiChange, 3, 'change_detection');
(string) sensor = The name of the sensor that will be used. 'L5' or 'L8.
(ee.Image) img1 = The first input image.
(ee.Image) img2 = The second input image.
(ee.Number) threshold = The number of the threshold. All the values at the
image that are greater than or equal to this number
will be selected.
var ndwiChange = geet.ndwi_change_detection( image_2014, image_2015, 'L8', 0.5); (img1, img2, sensor, threshold)
Function to detect changes between two input images using the NDBI index and a threshold parameter. The function adds the two masked indices and returns the sum. It's a good choice to call the plot_class function to visualize the result. Ex: geet.plot_class(ndbiChange, 3, 'change_detection');
(string) sensor = The name of the sensor that will be used. 'L5' or 'L8.
(ee.Image) img1 = The first input image.
(ee.Image) img2 = The second input image.
(ee.Number) threshold = The number of the threshold. All the values at the
image that are greater than or equal to this number
will be selected.
var ndbiChange = geet.ndbi_change_detection(image_2014, image_2015, 'L8', 0.5); (startDate, endDate, roi, showMosaic, sensor)
Generic function to build a cloud-free mosaic for Landsat 5, 7, 8, 9, or Sentinel-2.
(ee.Date) startDate - the start date of the dataset. (ee.Date) endDate - the end date of the dataset. optional (ee.Geometry) roi - the Region of Interest to filter the dataset. optional (bool) showMosaic - set to false if you don't want to display the mosaic. Default is true. (string) sensor - 'L5', 'L7', 'L8', 'L9' or 'S2'.
var mosaic = geet.create_mosaic('2023-01-01', '2023-12-31', roi, true, 'L8'); (collection, windowSize)
Function to apply a moving average filter to smooth a time series of images (e.g., NDVI series).
(ee.ImageCollection) collection - the input image collection to smooth. optional (number) windowSize - the moving window size in days. Default is 30.
var smoothed_ndvi = geet.smooth_timeseries(ndvi_collection, 45); (image, dem)
Applies Topographic Illumination Correction to optical images using the Cosine correction method. This is extremely useful for removing terrain shadows in mountainous areas, relying on the solar elevation and azimuth stored in the image's metadata.
(ee.Image) image - the optical image to correct (e.g., Landsat or Sentinel). (ee.Image) dem - (optional) the Digital Elevation Model to use. Defaults to SRTM.
var corrected_img = geet.topographic_correction(landsat_img);(roi)
Calculates the Topographic Wetness Index (TWI). This index combines local slope and flow accumulation to quantify topographic control on hydrological processes, making it excellent for identifying wetlands, springs, and water accumulation zones.
(ee.Geometry) roi - (optional) the region of interest to clip the outputs.
var twi = geet.calculate_twi(roi);
Map.addLayer(twi, {min: 5, max: 20, palette: ['red', 'yellow', 'green', 'blue']}, 'TWI');(roi)
Calculates the Topographic Position Index (TPI) and Terrain Ruggedness Index (TRI) based on focal mean and focal standard deviation. TPI is used to classify valleys and ridges, while TRI is used to map terrain unevenness.
(ee.Geometry) roi - (optional) the region of interest to clip the outputs.
var terrain_indices = geet.calculate_tpi_tri(roi);
var tpi = terrain_indices.select('TPI');
var tri = terrain_indices.select('TRI');(roi, threshold)
Automatically extracts the drainage/stream network based on a flow accumulation threshold using the HydroSHEDS dataset.
(ee.Geometry) roi - (optional) the region of interest. (number) threshold - (optional) the flow accumulation threshold (in pixels) to define a stream. Defaults to 500.
var rivers = geet.extract_drainage(roi, 1000);
Map.addLayer(rivers, {palette: ['blue']}, 'Drainage Network');(roi)
Function to build an annual Landsat MSS (Landsat 1, 2, 3, 4, 5) timeseries from 1972 to 1999. The function normalizes the distinct bands of older satellites into 'GREEN', 'RED', 'NIR1', 'NIR2', masks clouds using QA_PIXEL, calculates NDVI, and generates median annual mosaics.
(ee.Point) roi - the region of interest that will define the study area
var mss_timeseries = geet.build_annual_mss_timeseries(roi); (roi)
Function to build an annual Landsat (5, 7, 8, and 9) TOA time series from 1985 to 2030. The function also masks clouds and shadows, normalizes bands to standard English names, and generates all indices (NDVI, NDWI, SAVI, Tasseled Cap).
(ee.Point) roi - the region of interest that will define the study area and the Landsat path row
var ls_timeseries = geet.build_annual_landsat_timeseries(roi); (sensor, type, path, row)
Generic function to build an annual Landsat timeseries for a specific sensor.
(string) sensor - 'L5', 'L7', 'L8', 'L9'. (string) type - 'TOA' or 'SR'. (number) path - the WRS-2 path. (number) row - the WRS-2 row.
var l8_ts = geet.landsat_timeseries('L8', 'TOA', 221, 71);(type, path, row)
Function that return a image collection with all landsat images (5 and 8) from a defined path row. Remember to specify the type of the collection (raw, toa or sr).
(string) type - the type of the collection (RAW, TOA or SR)
(number) path - the path number of the image
(number) row - the row number of the image
var ls_collection = geet.landsat_timeseries_by_pathrow('SR', 217, 76); (type, path, row)
Function that returns an image collection with all Landsat images (5 and 8) from a defined roi. Remember to specify the type of the collection (raw, toa or sr).
(string) type - the type of the collection (RAW, TOA, or SR)
(ee.Geometry) roi - the Region of Interest to filter the dataset
var ls_collection = geet.landsat_timeseries_by_roi('SR', roi); (startDate, endDate, roi, polarization, orbit)
Function to load and preprocess Sentinel-1 SAR (Radar) GRD Data.
(ee.Date) startDate - the start date of the dataset. (ee.Date) endDate - the end date of the dataset. optional (ee.Geometry) roi - the Region of Interest. optional (string) polarization - 'VV', 'VH', 'HH', 'HV'. Default is 'VV'. optional (string) orbit - 'DESCENDING' or 'ASCENDING'. Default is 'DESCENDING'.
var radar_img = geet.s1_preprocess('2023-01-01', '2023-12-31', roi, 'VV', 'DESCENDING'); (image, radius)
Function to apply a focal median filter to reduce SAR speckle noise.
(ee.Image) image - the input SAR image. optional (number) radius - the radius of the filter in meters. Default is 30.
var smooth_radar = geet.speckle_filter(radar_img, 50); (roi)
Function to generate Elevation, Slope, Aspect, and Hillshade bands from the SRTM 30m DEM.
optional (ee.Geometry) roi - the Region of Interest to clip the DEM.
var terrain = geet.terrain_analysis(roi);
// Contains bands: 'Elevation', 'Slope', 'Aspect', 'Hillshade'(image, band)
Function to do a band conversion of digital numbers (DN) to Top of Atmosphere (TOA) Radiance.
(ee.Image) image - The image to process.
(number) band - The number of the band that you want to process.
var new_toa_radiance = geet.toa_radiance(img, 10); // ee.Image (image, band, sensor, solarAngle)
Generic function to calculate TOA Reflectance from raw DN.
(ee.Image) image - the input raw image. (string) band - the band name to process. (string) sensor - 'L5', 'L7', 'L8', or 'L9'. optional (number) solarAngle - solar angle if absent from metadata.
var ref_img = geet.toa_reflectance(raw_img, 'B4', 'L8');(image, sensor, unit, two_channel)
Generic function to convert the Top of Atmosphere (TOA Radiance) image to Brightness Temperature.
(ee.Image) image - the TOA Radiance image to convert. (string) sensor - 'L5', 'L7', 'L8' or 'L9' (string) unit - 'K' (Kelvin) or 'C' (Celsius) optional (bool) two_channel - for L8/L9 only, if true, processes both B10 and B11. Default is true.
var bt_img = geet.brightness_temp(toa_rad_image, 'L8', 'C'); (image)
Function calculate the surface emissifity.
(ee.Image) image - input image with the proportional vegetation band.
var lse = geet.surface_emissivity(pv);(image)
Function that calculates the land surface temperature (Landsat 5).
(ee.Image) image - the input image with the TOA_Radiance, Brightness_Temperature, NDVI, prop_veg, and LSE bands.
var surfTemp_img = geet.surface_temperature_tm(img);(image)
Function calculate the land surface temperature (Landsat 8).
(ee.Image) image - the input image with the TOA_Radiance, Brightness_Temperature, NDVI, prop_veg, and LSE bands.
var surfTemp_img = geet.surface_temperature_oli(img);(input)
Unified function to calculate Land Surface Temperature (LST) using the Single-Channel algorithm. It dynamically detects the sensor (Landsat 5, 7, 8, or 9) from the image metadata and applies the correct calibration constants and thermal wavelengths. It supports processing a single image or mapping over an entire ImageCollection (e.g., a time series). Output LST is in Celsius.
(ee.Image | ee.ImageCollection) input - The input image or image collection.
var geet = require('users/eduardolacerdageo/geet:geet');
// For a single image
var lst_img = geet.calculate_lst(img);
// For a time-series collection!
var lst_collection = collection.map(geet.calculate_lst);(image, scale)
Function to export an image to your Google Drive account.
(ee.Image) image - the input image.
optional (number) _scale - the scale number.The scale relates to the image's spatial resolution. Landsat is 30, so the default is 30 also.
geet.export_image(img);or
geet.export_image(sentinel2_img, 10);(collection, year, roi, cloudfree)
Function to get an example image to debug or test some code.
optional (string) collection - the type of the collection that will be filtered: RAW, TOA, or SR.
optional (number) year - the year of the image that you want to get.
optional (list) roi - the latitude and longitude of a roi.
optional (bool) cloudFree - true for cloud mask processing and mean calculation.
var image = geet.load_image(); // Returns a TOA image or
var image = geet.load_image('SR', 2015); // Returns a SR image (id)
Function to filter the Sentinel-2 collection by Product ID obtained from the Copernicus Open Access Hub.
(string) id - the ID of the Sentinel-2 image.
var s2_image = geet.load_id_s2('S2A_MSIL1C_20170512T093041_N0205_R136_T34TDN_20170512T093649'); (image, previous)
Function to merge all images of one image collection into a single band.
(ee.Image) image - The image of the image collection to add as a band.
(ee.Image) previous - The output image.
var geet = require('users/eduardolacerdageo/geet:geet');
var merged_image = image_collection.iterate(geet.collection2image, ee.Image([])); (image, reference_collection, band)
Calculates the Z-Score Anomaly of an image compared to a historical reference collection. Great for finding extreme events like droughts, heatwaves, or deforestation spikes.
(ee.Image) image - The target image. (ee.ImageCollection) reference_collection - The historical baseline. (string) band - The name of the band to calculate the anomaly for (e.g. 'NDVI' or 'LST').
var anomaly_img = geet.anomaly(target_image, baseline_col, 'LST');(current, prev)
Iteratively Reweighted Multivariate Alteration Detection (iMAD) algorithm. Developed by Dr. Allan Nielsen and implemented in GEE by Dr. Mort Canty. This is a highly advanced statistical algorithm for detecting changes between two images and finding Pseudo-Invariant Features (PIFs) that didn't change.
(ee.Image) current - The target image. (ee.Dictionary) prev - The iteration dictionary containing state.
(current, prev)
Iterator function for orthogonal regression and interactive radiometric normalization. Called internally by radcalbatch.
(ee.Image) current - The current band index. (ee.Dictionary) prev - The dictionary containing image and coeffs.
(current, prev)
Performs Relative Radiometric Normalization using orthogonal regression on the invariant pixels discovered by the iMAD algorithm. Crucial for harmonizing a time series of images to a single reference image.
(ee.Image) current - The image to normalize. (ee.Dictionary) prev - The dictionary containing the reference image.
(image, size, compactness)
Function to segment an image using the SNIC (Simple Non-Iterative Clustering) algorithm.
(ee.Image) image - the input image. optional (number) size - The superpixel seed location spacing (default 10). optional (number) compactness - The compactness factor (default 1).
var snic = geet.segmentation_snic(img, 15, 1);(image, trainingData, fieldName, options)
Function to perform a complete Object-Based Image Analysis (GEOBIA) classification. It automatically generates superpixels (SNIC), extracts spectral, spatial (geometry), and textural (GLCM) features per object, and classifies them using Machine Learning.
(ee.Image) image - The raw input image to segment and classify. (ee.FeatureCollection) trainingData - The training samples. (string) fieldName - The class column name. optional (Object) options - Dictionary of OBIA parameters: { snicSize: 15, snicCompactness: 1, classifier: 'rf', // 'rf', 'cart', 'svm' includeTexture: false, includeGeometry: true, scale: 30 }
var obia_results = geet.obia_classification(img, samples, 'class', {
snicSize: 20,
includeGeometry: true,
includeTexture: true,
classifier: 'rf'
});
// Extract the final classified map
var classified = obia_results.select('classification');(image, minArea, maxSize)
Eliminates small patches in a classified image (Minimum Mapping Unit filter) by replacing them with the most common neighboring class.
(ee.Image) image - The classified image (single band). (number) minArea - The minimum area in square meters (e.g., 10000 for 1 hectare). optional (number) maxSize - The focal mode radius to fill gaps (default 50).
// Filter out any object smaller than 1 hectare (10,000 sq meters)
var cleaned_map = geet.filter_small_objects(classified, 10000);(timeseries, dependent_band, num_harmonics)
Generates a Fourier Harmonic Trend model for a time-series to extract Seasonality (Phase and Amplitude) and Linear Trend. It now supports multiple harmonics for modeling complex phenological cycles (e.g., double-cropping systems).
(ee.ImageCollection) timeseries - The input time-series collection. (string) dependent_band - The name of the band to model (e.g., 'NDVI'). optional (number) num_harmonics - The number of cycles per year to model (default: 1).
var trend = geet.harmonic_trend(landsat_ts, 'NDVI', 2);(image, featureCollection, reducerType, scale)
Extracts zonal statistics from an image using polygons.
(ee.Image) image - the input image. (ee.FeatureCollection) featureCollection - the polygon regions. (string) reducerType - 'max', 'min', 'mean', 'median', 'mode', 'sd', 'variance', 'sum'. optional (number) scale - the scale in meters (default 30).
var stats = geet.zonal_statistics(ndvi_img, polygons, 'mean', 30);(image, source, target)
Harmonizes spectral values between Sentinel-2 and Landsat-8 using OLS regression coefficients.
(ee.Image) image - the input image. (string) source - 'S2' or 'L8'. (string) target - 'S2' or 'L8'.
var harmonized = geet.harmonize_sensors(s2_img, 'S2', 'L8');(pre_fire, post_fire, sensor)
Calculates the Normalized Burn Ratio (NBR), Delta NBR (dNBR), and Burn Severity Classes.
(ee.Image) pre_fire - the pre-fire image. (ee.Image) post_fire - the post-fire image. optional (string) sensor - 'L8', 'L9', 'S2', etc. (default 'L8').
var severity = geet.burn_severity(img_before, img_after, 'L8');The following functions have been deprecated to streamline the GEET library. They are still exported as "stubs" that will throw an informative error if called, guiding legacy code users to the new, integrated functions.
build_annual_ls5_timeseries,build_annual_ls7_timeseries,build_annual_ls8_timeseries-> Replaced by:build_annual_landsat_timeseries(roi)landsat5_timeseries,landsat7_timeseries,landsat8_timeseries-> Replaced by:landsat_timeseries(sensor, type)
If your legacy scripts use any of these old functions, please update them to use the new integrated functions, which offer better performance, Collection 2 compliance, and support for newer sensors like Landsat 9.
