GEE python 计算两景影像NDVI差异喝平方差计算
安装地球引擎API和geemap
安装地球引擎的Python API和geemap。geemap Python包是建立在ipyleaflet和folium包之上的,它实现了几个与地球引擎数据层交互的方法,比如Map.addLayer()、Map.setCenter()和Map.centerObject()。下面的脚本检查geemap包是否已经安装。如果没有,它将安装geemap,它会自动安装其依赖项,包括earthengine-api、folium和ipyleaflet。
# Installs geemap package
import subprocess
try:
import geemap
except ImportError:
print('Installing geemap ...')
subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
import ee
import geemap
创建一个交互式地图
默认的基图是谷歌地图。可以使用Map.add_basemap()函数来添加额外的基图。
Map = geemap.Map(center=[40,-100], zoom=4)
Map
获取影像信息的代码:
# Add Earth Engine dataset
image = ee.Image('LANDSAT/LC8_L1T/LC80440342014077LGN00')
bandNames = image.bandNames()
print('Band names: ', bandNames.getInfo()) # ee.List
b1proj = image.select('B1').projection()
print('Band 1 projection: ', b1proj.getInfo()) # ee.Projection
b1scale = image.select('B1').projection().nominalScale()
print('Band 1 scale: ', b1scale.getInfo()) # ee.Number
b8scale = image.select('B8').projection().nominalScale()
print('Band 8 scale: ', b8scale.getInfo()) # ee.Number
properties = image.propertyNames()
print('Metadata properties: ', properties.getInfo()) # ee.List
cloudiness = image.get('CLOUD_COVER')
print('CLOUD_COVER: ', cloudiness.getInfo()) # ee.Number
date = ee.Date(image.get('system:time_start'))
print('Timestamp: ', date.getInfo()) # ee.Date
最后结果:
Band names: [‘B1’, ‘B2’, ‘B3’, ‘B4’, ‘B5’, ‘B6’, ‘B7’, ‘B8’, ‘B9’, ‘B10’, ‘B11’, ‘BQA’]
Band 1 projection: {‘type’: ‘Projection’, ‘crs’: ‘EPSG:32610’, ‘transform’: [30, 0, 460485, 0, -30, 4264515]}
Band 1 scale: 30
Band 8 scale: 15
Metadata properties: [‘RADIANCE_MULT_BAND_5’, ‘RADIANCE_MULT_BAND_6’, ‘RADIANCE_MULT_BAND_3’, ‘RADIANCE_MULT_BAND_4’, ‘RADIANCE_MULT_BAND_1’, ‘RADIANCE_MULT_BAND_2’, ‘system:id’, ‘K2_CONSTANT_BAND_11’, ‘K2_CONSTANT_BAND_10’, ‘system:footprint’, ‘REFLECTIVE_SAMPLES’, ‘SUN_AZIMUTH’, ‘CORNER_UL_PROJECTION_Y_PRODUCT’, ‘CPF_NAME’, ‘CORNER_LR_PROJECTION_Y_PRODUCT’, ‘DATE_ACQUIRED’, ‘ELLIPSOID’, ‘google:registration_offset_x’, ‘google:registration_offset_y’, ‘STATION_ID’, ‘RESAMPLING_OPTION’, ‘RADIANCE_MINIMUM_BAND_11’, ‘RADIANCE_MINIMUM_BAND_10’, ‘ORIENTATION’, ‘WRS_ROW’, ‘RADIANCE_MULT_BAND_9’, ‘TARGET_WRS_ROW’, ‘RADIANCE_MULT_BAND_7’, ‘RADIANCE_MULT_BAND_8’, ‘IMAGE_QUALITY_TIRS’, ‘QUANTIZE_CAL_MIN_BAND_9’, ‘QUANTIZE_CAL_MIN_BAND_8’, ‘QUANTIZE_CAL_MIN_BAND_7’, ‘QUANTIZE_CAL_MIN_BAND_6’, ‘QUANTIZE_CAL_MIN_BAND_5’, ‘CLOUD_COVER’, ‘QUANTIZE_CAL_MIN_BAND_4’, ‘QUANTIZE_CAL_MIN_BAND_3’, ‘QUANTIZE_CAL_MIN_BAND_2’, ‘QUANTIZE_CAL_MIN_BAND_1’, ‘GEOMETRIC_RMSE_VERIFY’, ‘CORNER_LL_LON_PRODUCT’, ‘CORNER_LR_LON_PRODUCT’, ‘GRID_CELL_SIZE_REFLECTIVE’, ‘RADIANCE_MAXIMUM_BAND_9’, ‘ORIGIN’, ‘RADIANCE_MAXIMUM_BAND_8’, ‘RADIANCE_MAXIMUM_BAND_7’, ‘RADIANCE_MAXIMUM_BAND_2’, ‘RADIANCE_MAXIMUM_BAND_1’, ‘RADIANCE_MAXIMUM_BAND_6’, ‘GEOMETRIC_RMSE_MODEL’, ‘RADIANCE_MAXIMUM_BAND_5’, ‘RADIANCE_MAXIMUM_BAND_4’, ‘RADIANCE_MAXIMUM_BAND_3’, ‘QUANTIZE_CAL_MAX_BAND_10’, ‘IMAGE_QUALITY_OLI’, ‘LANDSAT_SCENE_ID’, ‘WRS_PATH’, ‘google:registration_count’, ‘PANCHROMATIC_SAMPLES’, ‘PANCHROMATIC_LINES’, ‘REFLECTANCE_MAXIMUM_BAND_8’, ‘REFLECTANCE_MAXIMUM_BAND_9’, ‘RADIANCE_MAXIMUM_BAND_11’, ‘RADIANCE_MAXIMUM_BAND_10’, ‘CORNER_LL_LAT_PRODUCT’, ‘GEOMETRIC_RMSE_MODEL_Y’, ‘REFLECTIVE_LINES’, ‘GEOMETRIC_RMSE_MODEL_X’, ‘catalog_cloud_cover’, ‘system:asset_size’, ‘QUANTIZE_CAL_MAX_BAND_11’, ‘system:index’, ‘CORNER_LL_PROJECTION_Y_PRODUCT’, ‘CORNER_UL_LON_PRODUCT’, ‘REFLECTANCE_MAXIMUM_BAND_2’, ‘REFLECTANCE_MAXIMUM_BAND_3’, ‘CORNER_UR_LON_PRODUCT’, ‘REFLECTANCE_MAXIMUM_BAND_1’, ‘REFLECTANCE_MAXIMUM_BAND_6’, ‘REFLECTANCE_MAXIMUM_BAND_7’, ‘REFLECTANCE_MAXIMUM_BAND_4’, ‘REFLECTANCE_MAXIMUM_BAND_5’, ‘REFLECTANCE_ADD_BAND_1’, ‘REFLECTANCE_ADD_BAND_2’, ‘CORNER_LR_LAT_PRODUCT’, ‘DATUM’, ‘REFLECTANCE_ADD_BAND_3’, ‘REFLECTANCE_ADD_BAND_4’, ‘RLUT_FILE_NAME’, ‘REFLECTANCE_ADD_BAND_5’, ‘REFLECTANCE_ADD_BAND_6’, ‘REFLECTANCE_ADD_BAND_7’, ‘REFLECTANCE_ADD_BAND_8’, ‘BPF_NAME_TIRS’, ‘system:version’, ‘DATA_TYPE’, ‘UTM_ZONE’, ‘system:time_end’, ‘REFLECTANCE_ADD_BAND_9’, ‘google:registration_ratio’, ‘GRID_CELL_SIZE_PANCHROMATIC’, ‘google:cloud_storage_path’, ‘RADIANCE_ADD_BAND_4’, ‘REFLECTANCE_MULT_BAND_7’, ‘system:time_start’, ‘RADIANCE_ADD_BAND_5’, ‘REFLECTANCE_MULT_BAND_6’, ‘RADIANCE_ADD_BAND_6’, ‘REFLECTANCE_MULT_BAND_9’, ‘PROCESSING_SOFTWARE_VERSION’, ‘RADIANCE_ADD_BAND_7’, ‘REFLECTANCE_MULT_BAND_8’, ‘RADIANCE_ADD_BAND_1’, ‘RADIANCE_ADD_BAND_2’, ‘RADIANCE_ADD_BAND_3’, ‘CORNER_UR_PROJECTION_Y_PRODUCT’, ‘REFLECTANCE_MULT_BAND_1’, ‘RADIANCE_ADD_BAND_8’, ‘REFLECTANCE_MULT_BAND_3’, ‘RADIANCE_ADD_BAND_9’, ‘REFLECTANCE_MULT_BAND_2’, ‘REFLECTANCE_MULT_BAND_5’, ‘REFLECTANCE_MULT_BAND_4’, ‘THERMAL_LINES’, ‘QUANTIZE_CAL_MAX_BAND_7’, ‘QUANTIZE_CAL_MAX_BAND_6’, ‘GRID_CELL_SIZE_THERMAL’, ‘QUANTIZE_CAL_MAX_BAND_5’, ‘QUANTIZE_CAL_MAX_BAND_4’, ‘QUANTIZE_CAL_MAX_BAND_3’, ‘QUANTIZE_CAL_MAX_BAND_2’, ‘QUANTIZE_CAL_MAX_BAND_1’, ‘catalog_image_quality1’, ‘NADIR_OFFNADIR’, ‘RADIANCE_ADD_BAND_11’, ‘REFLECTANCE_MINIMUM_BAND_8’, ‘CORNER_UR_LAT_PRODUCT’, ‘REFLECTANCE_MINIMUM_BAND_9’, ‘REFLECTANCE_MINIMUM_BAND_6’, ‘CORNER_LL_PROJECTION_X_PRODUCT’, ‘REFLECTANCE_MINIMUM_BAND_7’, ‘REQUEST_ID’, ‘EARTH_SUN_DISTANCE’, ‘QUANTIZE_CAL_MAX_BAND_9’, ‘FILE_DATE’, ‘QUANTIZE_CAL_MAX_BAND_8’, ‘SCENE_CENTER_TIME’, ‘REFLECTANCE_MINIMUM_BAND_1’, ‘SUN_ELEVATION’, ‘BPF_NAME_OLI’, ‘CORNER_UL_PROJECTION_X_PRODUCT’, ‘RADIANCE_MINIMUM_BAND_4’, ‘REFLECTANCE_MINIMUM_BAND_4’, ‘RADIANCE_MINIMUM_BAND_3’, ‘REFLECTANCE_MINIMUM_BAND_5’, ‘RADIANCE_MINIMUM_BAND_2’, ‘REFLECTANCE_MINIMUM_BAND_2’, ‘RADIANCE_ADD_BAND_10’, ‘RADIANCE_MINIMUM_BAND_1’, ‘REFLECTANCE_MINIMUM_BAND_3’, ‘RADIANCE_MINIMUM_BAND_8’, ‘RADIANCE_MINIMUM_BAND_7’, ‘RADIANCE_MINIMUM_BAND_6’, ‘RADIANCE_MINIMUM_BAND_5’, ‘CORNER_UL_LAT_PRODUCT’, ‘ROLL_ANGLE’, ‘RADIANCE_MINIMUM_BAND_9’, ‘K1_CONSTANT_BAND_10’, ‘MAP_PROJECTION’, ‘SENSOR_ID’, ‘K1_CONSTANT_BAND_11’, ‘TARGET_WRS_PATH’, ‘RADIANCE_MULT_BAND_11’, ‘CORNER_LR_PROJECTION_X_PRODUCT’, ‘RADIANCE_MULT_BAND_10’, ‘GROUND_CONTROL_POINTS_MODEL’, ‘QUANTIZE_CAL_MIN_BAND_11’, ‘QUANTIZE_CAL_MIN_BAND_10’, ‘SPACECRAFT_ID’, ‘CORNER_UR_PROJECTION_X_PRODUCT’, ‘ELEVATION_SOURCE’, ‘THERMAL_SAMPLES’, ‘GROUND_CONTROL_POINTS_VERIFY’, ‘system:bands’, ‘system:band_names’]
CLOUD_COVER: 0.3400000035762787
Timestamp: {‘type’: ‘Date’, ‘value’: 1395168392055}
主要函数:
image.propertyNames(*args, **kwargs)
在标签页中打开 查看源代码
Returns the names of properties on this element.
Args:
element:
**image.get(*args, kwargs)
在标签页中打开 查看源代码
Extract a property from a feature.
Args:
object: The feature to extract the property from.
property: The property to extract.
def getInfo()
在标签页中打开 查看源代码
Fetch and return information about this object.
Returns:
The object can evaluate to anything.
**image.bandNames(*args, kwargs)
在标签页中打开 查看源代码
Returns a list containing the names of the bands of an image.
Args:
image: The image from which to get band names.
NDVI差异
# Add Earth Engine dataset
# Load two 5-year Landsat 7 composites.
landsat1999 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')
landsat2008 = ee.Image('LANDSAT/LE7_TOA_5YEAR/2008_2012')
# Compute NDVI the hard way.
ndvi1999 = landsat1999.select('B4').subtract(landsat1999.select('B3')) \
.divide(landsat1999.select('B4').add(landsat1999.select('B3')))
# Compute NDVI the easy way.
ndvi2008 = landsat2008.normalizedDifference(['B4', 'B3'])
# Compute the multi-band difference image.
diff = landsat2008.subtract(landsat1999)
Map.addLayer(diff,
{'bands': ['B4', 'B3', 'B2'], 'min': -32, 'max': 32},
'difference')
# Compute the squared difference in each band.
squaredDifference = diff.pow(2)
Map.addLayer(squaredDifference,
{'bands': ['B4', 'B3', 'B2'], 'max': 1000},
'squared diff.')
- 点赞
- 收藏
- 关注作者
评论(0)