11 analysis
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import ee
import geemap
import ee
import geemap
In [3]:
Copied!
Map = geemap.Map()
centroid = ee.Geometry.Point([-122.4439, 37.7538])
image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(centroid).first()
vis = {'min': 0, 'max': 3000, 'bands': ['B5', 'B4', 'B3']}
Map.centerObject(centroid, 8)
Map.addLayer(image, vis, "Landsat-8")
Map
Map = geemap.Map()
centroid = ee.Geometry.Point([-122.4439, 37.7538])
image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(centroid).first()
vis = {'min': 0, 'max': 3000, 'bands': ['B5', 'B4', 'B3']}
Map.centerObject(centroid, 8)
Map.addLayer(image, vis, "Landsat-8")
Map
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Using Earth Engine built-in functions to get image properties.
In [4]:
Copied!
image.propertyNames().getInfo()
image.propertyNames().getInfo()
Out[4]:
['IMAGE_QUALITY_TIRS', 'CLOUD_COVER', 'system:id', 'EARTH_SUN_DISTANCE', 'LANDSAT_ID', 'system:footprint', 'system:version', 'CLOUD_COVER_LAND', 'GEOMETRIC_RMSE_MODEL', 'SR_APP_VERSION', 'SATELLITE', 'SOLAR_AZIMUTH_ANGLE', 'IMAGE_QUALITY_OLI', 'system:time_end', 'WRS_PATH', 'system:time_start', 'SENSING_TIME', 'ESPA_VERSION', 'SOLAR_ZENITH_ANGLE', 'WRS_ROW', 'GEOMETRIC_RMSE_MODEL_Y', 'LEVEL1_PRODUCTION_DATE', 'GEOMETRIC_RMSE_MODEL_X', 'system:asset_size', 'PIXEL_QA_VERSION', 'system:index', 'system:bands', 'system:band_names']
In [5]:
Copied!
image.get('CLOUD_COVER').getInfo()
image.get('CLOUD_COVER').getInfo()
Out[5]:
0.05
Using geemap.image_props()
to get image properties.
In [6]:
Copied!
props = geemap.image_props(image)
props.getInfo()
props = geemap.image_props(image)
props.getInfo()
Out[6]:
{'CLOUD_COVER': 0.05, 'CLOUD_COVER_LAND': 0.06, 'EARTH_SUN_DISTANCE': 1.001791, 'ESPA_VERSION': '2_23_0_1b', 'GEOMETRIC_RMSE_MODEL': 6.678, 'GEOMETRIC_RMSE_MODEL_X': 4.663, 'GEOMETRIC_RMSE_MODEL_Y': 4.78, 'IMAGE_DATE': '2013-04-09', 'IMAGE_QUALITY_OLI': 9, 'IMAGE_QUALITY_TIRS': 9, 'LANDSAT_ID': 'LC08_L1TP_044034_20130409_20170310_01_T1', 'LEVEL1_PRODUCTION_DATE': 1489126619000, 'NOMINAL_SCALE': 30, 'PIXEL_QA_VERSION': 'generate_pixel_qa_1.6.0', 'SATELLITE': 'LANDSAT_8', 'SENSING_TIME': '2013-04-09T18:46:34.7579070Z', 'SOLAR_AZIMUTH_ANGLE': 142.742508, 'SOLAR_ZENITH_ANGLE': 34.973495, 'SR_APP_VERSION': 'LaSRC_1.3.0', 'WRS_PATH': 44, 'WRS_ROW': 34, 'system:asset_size': '558.682087 MB', 'system:band_names': ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'B11', 'sr_aerosol', 'pixel_qa', 'radsat_qa'], 'system:id': 'LANDSAT/LC08/C01/T1_SR/LC08_044034_20130409', 'system:index': 'LC08_044034_20130409', 'system:time_end': '2013-04-09 18:46:34', 'system:time_start': '2013-04-09 18:46:34', 'system:version': 1581684730621653}
Get image summary statistics, such as max, min, mean, std, sum.
In [7]:
Copied!
stats = geemap.image_stats(image, scale=90)
stats.getInfo()
stats = geemap.image_stats(image, scale=90)
stats.getInfo()
Out[7]:
{'max': {'B1': 7624, 'B10': 3155, 'B11': 3127, 'B2': 8471, 'B3': 9778, 'B4': 10679, 'B5': 11606, 'B6': 13054, 'B7': 12327, 'pixel_qa': 480, 'radsat_qa': 254, 'sr_aerosol': 228}, 'mean': {'B1': 373.1098468094287, 'B10': 2933.4637979167583, 'B11': 2916.278387909346, 'B2': 427.4021313923417, 'B3': 614.9744637045823, 'B4': 591.3781773385491, 'B5': 1954.134478186476, 'B6': 1472.071307222312, 'B7': 996.8232780577415, 'pixel_qa': 322.8433703241347, 'radsat_qa': 0.00019878780091270898, 'sr_aerosol': 87.7488586248313}, 'min': {'B1': -1432, 'B10': 2759, 'B11': 2702, 'B2': -1129, 'B3': -345, 'B4': -403, 'B5': 35, 'B6': 10, 'B7': 5, 'pixel_qa': 322, 'radsat_qa': 0, 'sr_aerosol': 8}, 'std': {'B1': 201.9355685609457, 'B10': 67.57460806939051, 'B11': 63.85549758560136, 'B2': 230.81296623126636, 'B3': 296.8097076885089, 'B4': 393.63764571402265, 'B5': 1202.7937141588027, 'B6': 926.420271742664, 'B7': 729.0233711578251, 'pixel_qa': 4.9833065816273345, 'radsat_qa': 0.1664709111036373, 'sr_aerosol': 25.1855827242985}, 'sum': {'B1': 1557981451.9372544, 'B10': 12249159935.51374, 'B11': 12177399433.172562, 'B2': 1784687804.2, 'B3': 2567926888.180393, 'B4': 2469396718.5607834, 'B5': 8159809497.498039, 'B6': 6146875544.007842, 'B7': 4162399334.5490217, 'pixel_qa': 1347970027.0274508, 'radsat_qa': 830, 'sr_aerosol': 366378380.98823535}}
Zonal statistics¶
Add Earth Engine datasets.
In [8]:
Copied!
Map = geemap.Map(center=[40, -100], zoom=4)
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
dem_vis = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(dem, dem_vis, 'SRTM DEM')
# Add Landsat data to map
landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
Map
Map = geemap.Map(center=[40, -100], zoom=4)
# Add Earth Engine dataset
dem = ee.Image('USGS/SRTMGL1_003')
# Set visualization parameters.
dem_vis = {
'min': 0,
'max': 4000,
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
}
# Add Earth Engine DEM to map
Map.addLayer(dem, dem_vis, 'SRTM DEM')
# Add Landsat data to map
landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')
landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}
Map.addLayer(landsat, landsat_vis, "LE7_TOA_5YEAR/1999_2003")
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
Map
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Computer zonal statistics.
- Allowed output formats: csv, shp, json, kml, kmz
- Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM
In [9]:
Copied!
out_dem_stats = 'dem_stats.csv'
geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)
out_dem_stats = 'dem_stats.csv'
geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)
Computing statistics ... Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/04e8c7b138ea4c98a9a99871c8737598-b8cb040ec240655deac162c0a3d9269d:getFeatures Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/dem_stats.csv
In [10]:
Copied!
out_landsat_stats = 'landsat_stats.csv'
geemap.zonal_statistics(
landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000
)
out_landsat_stats = 'landsat_stats.csv'
geemap.zonal_statistics(
landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000
)
Computing statistics ... Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/ef7da058fa8cecffdece8d714da68ec8-4655e73f0e2f56812204f98d440b5861:getFeatures Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/landsat_stats.csv
Zonal statistics by group¶
Add Earth Engine datasets.
In [11]:
Copied!
Map = geemap.Map(center=[40, -100], zoom=4)
dataset = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019')
landcover = dataset.select('landcover')
Map.addLayer(landcover, {}, 'NLCD 2019')
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
Map.add_legend(builtin_legend='NLCD')
Map
Map = geemap.Map(center=[40, -100], zoom=4)
dataset = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019')
landcover = dataset.select('landcover')
Map.addLayer(landcover, {}, 'NLCD 2019')
states = ee.FeatureCollection("TIGER/2018/States")
Map.addLayer(states, {}, 'US States')
Map.add_legend(builtin_legend='NLCD')
Map
Out[11]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Computer zonal statistics by group.
- statistics_type can be either 'SUM' or 'PERCENTAGE'
- denominator can be used to convert square meters to other areal units, such as square kilimeters.
In [12]:
Copied!
nlcd_stats = 'nlcd_stats.csv'
geemap.zonal_statistics_by_group(
landcover,
states,
nlcd_stats,
statistics_type='SUM',
denominator=1000000,
decimal_places=2,
)
nlcd_stats = 'nlcd_stats.csv'
geemap.zonal_statistics_by_group(
landcover,
states,
nlcd_stats,
statistics_type='SUM',
denominator=1000000,
decimal_places=2,
)
Computing ... Generating URL ... Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/133d101cfb013c1f804933a0d6c5b076-de75bc07554fc30e90bc157e52c6e1a0:getFeatures Please wait ... Data downloaded to /home/runner/work/GEE-Courses/GEE-Courses/docs/geemap_intro/nlcd_stats.csv
Last update:
2022-03-25