import geemap
import ee
# ee.Authenticate()
=33210)
geemap.set_proxy(port
ee.Initialize()import os
import pandas as pd
import numpy as np
from pyproj import CRS,Transformer
Dynamic World data download
The real world is as dynamic as the people and natural processes that shape it. Dynamic World is a near realtime 10m resolution global land use land cover dataset, produced using deep learning, freely available and openly licensed. It is the result of a partnership between Google and the World Resources Institute, to produce a dynamic dataset of the physical material on the surface of the Earth. Dynamic World is intended to be used as a data product for users to add custom rules with which to assign final class values, producing derivative land cover maps.
Key innovations of Dynamic World
Near realtime data. Over 5000 Dynamic World image are produced every day, whereas traditional approaches to building land cover data can take months or years to produce. As a result of leveraging a novel deep learning approach, based on Sentinel-2 Top of Atmosphere, Dynamic World offers global land cover updating every 2-5 days depending on location.
Per-pixel probabilities across 9 land cover classes. A major benefit of an AI-powered approach is the model looks at an incoming Sentinel-2 satellite image and, for every pixel in the image, estimates the degree of tree cover, how built up a particular area is, or snow coverage if there’s been a recent snowstorm, for example.
Ten meter resolution. As a result of the European Commission’s Copernicus Programme making European Space Agency Sentinel data freely and openly available, products like Dynamic World are able to offer 10m resolution land cover data. This is important because quantifying data in higher resolution produces more accurate results for what’s really on the surface of the Earth.
- App: www.dynamicworld.app
- Paper: Dynamic World, Near real-time global 10m land use land cover mapping
- Model: github
- Geedata: Dynamic World V1
This tutorial explains how to download training data for Dynamic Earth using geemap
1. Import the necessary lib
Map visualization
= geemap.Map()
Map 'HYBRID')
Map.add_basemap(= ee.Geometry.BBox(-89.7088, 42.9006, -89.0647, 43.2167)
region
Map.centerObject(region)= geemap.dynamic_world_s2(region, '2021-01-01', '2022-01-01')
image = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 3000}
vis_params = geemap.dynamic_world(region, '2021-01-01', '2022-01-01', return_type='hillshade')
landcover 'Land Cover')
Map.addLayer(landcover, {}, ="Dynamic World Land Cover", builtin_legend='Dynamic_World')
Map.add_legend(title Map
2. Download data
Construct a data combination with 8 bands, and use the data region, ID and other information provided by the paper to download image patches.
## cloud remove
def rmCloudByQA(image):
= image.select('QA60')
qa = 1 << 10
cloudBitMask = 1 << 11
cirrusBitMask =qa.bitwiseAnd(cloudBitMask).eq(0)and(qa.bitwiseAnd(cirrusBitMask).eq(0))
mask return image.updateMask(mask).toFloat().divide(1e4)
## convert utm to geo
def utm_to_geo(region,crs):
=region.split('(',2)[-1].split(')',2)[0].split(', ')
strline=np.array(strline[0].split(' '))
ymin,xmin=np.array(strline[2].split(' '))
ymax,xmax= CRS.from_string(crs)
ocrs = Transformer.from_crs(ocrs,'epsg:4326')
transformer =transformer.transform(ymin,xmin)
ymin,xmin=transformer.transform(ymax,xmax)
ymax,xmaxreturn xmin,ymin,xmax,ymax
## Construct the 8-band data combination: Red,Green,Blue,Nir,Swir1,Swir2,MNDWI,Slope
def collection_cal(region,tiles,crs):
= ee.ImageCollection('COPERNICUS/S2_SR')
s2Img = ee.Image('USGS/SRTMGL1_003')
DEM = DEM.setDefaultProjection(crs,None,10).clip(region)
DEM_clip = ee.Terrain.slope(DEM_clip)
slope = s2Img.filter(ee.Filter.inList('system:index',tiles)).filterBounds(region).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 60)).map(rmCloudByQA).select('B.*').first().setDefaultProjection(crs,None,10)
S =S.clip(region)
S2= S2.normalizedDifference(['B3','B11']).rename(['MNDWI']).add(ee.Number(1))
MNDWI =S2.select(['B4','B3','B2','B8','B11','B12'])
DBANDS=DBANDS.addBands(MNDWI).addBands(slope).setDefaultProjection(crs,None,10)
finalreturn final
## download function
def download_img(image,basename,out_dir):
=basename+'.tif'
dw_id# out_dir = os.path.expanduser(outdir)
= os.path.join(out_dir, dw_id)
out_dem_stats =10,scale=10) geemap.download_ee_image(image,out_dem_stats, num_threads
## visual check if if required
# Map = geemap.Map()
# Map.centerObject(region)
# Map.addLayer(region,{},'img')
# Map
The expert data in the table is downloaded here, and the label file can be downloaded through the link provided in the paper. During the download process, the file download may fail due to network reasons. In this case, you can try a few more times.
=pd.read_csv('./expert.csv')
data='c:/temp/'
outdirfor index, row in data.iterrows():
= row['dw_id']
basename= row['S2_GEE_ID']
S2_GEE_ID= row['crs']
crs=[S2_GEE_ID]
tiles= os.path.join(outdir, basename+'.tif')
outfile if os.path.exists(outfile):
# if index < 3035:
pass
else:
= row['geometry']
regionprint(index,S2_GEE_ID)
=utm_to_geo(region,crs)
xmin,ymin,xmax,ymax= ee.Geometry.BBox(xmin,ymin,xmax,ymax)
regionClip =collection_cal(regionClip,tiles,crs)
ImgTiles
download_img(ImgTiles,basename,outdir)# if index % 50==0:
# print('downloading......No.: '+str(index))
If you want to get the downloaded label data and related forms, you can follow the WeChat public account [45度科研人] and leave me a message!