gee: Zonal Statistics of Monthly VIRRS Data
!pip install geemap
import geemap
import ee
import os
import folium
import geopandas as gpd
import plotly.express as px
import pyproj
try:
ee.Initialize()
except Exception as e:
ee.Authenticate()
ee.Initialize()
# Copy the below link into your own browser
Load Google Earth
Map = geemap.Map()
Map
Below is a picture of Google Earth
collection = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG') \
.filter(ee.Filter.date('2018-01-01','2018-12-31')) \
.select("avg_rad")
modis = collection.toBands()
Map.addLayer(modis, {}, "MODIS Time series")
first_image = collection.first()
Map.addLayer(first_image,{}, "First image")
Map
Below is a picture of Google Earth
Load local shapefile
chinashp = '/work/china.shp'
China= geemap.shp_to_ee(chinashp)
Map.addLayer(China, {}, 'Province of China')
Map
#out_landsat_stats = os.path.join('virrs.csv')
#geemap.zonal_statistics(modis, China, out_landsat_stats, statistics_type='MEAN', scale=1000)
out_landsat_stats = os.path.join('virrs.shp')
geemap.zonal_statistics(modis, China, out_landsat_stats, statistics_type='MEAN', scale=1000)
gdf=gpd.read_file('/work/virrs.shp')
gdf
gdf.describe()
Data Visualization
gdf.explore(column='20180501_a',cmap='cividis')
gdf.explore(
column='20180501_a',
tooltip=['ADM1_EN', '20180501_a','20180401_a','20180301_a','20180201_a','20180101_a'],
scheme='naturalbreaks',
cmap='coolwarm',
legend=True,
style_kwds =dict(color="black", weight=0.5),
legend_kwds=dict(colorbar=False)
)
px.scatter(
gdf,
x="20180501_a",
size="20180501_a", size_max=60,
color='ADM1_EN'
)