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
IPyWidgets are not supported
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
IPyWidgets are not supported
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
IPyWidgets are not supported
#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)
Computing statistics ...
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/tables/2492ed1e89b4b0066a49eee5b85bb550-e582c8061e5f6218ca8d8c396654752a:getFeatures
Please wait ...
Data downloaded to /work/virrs.shp
gdf=gpd.read_file('/work/virrs.shp')
gdf
20180501_afloat64
0.0 - 16.23924545649773
20181101_afloat64
0.311137275765732 - 17.209992609749815
0
0.7752506639
0.8789409707
1
16.23924546
17.20999261
2
0.9353502337
1.01627522
3
2.483289759
2.37556471
4
0.6482084372
0.579962198
5
0.5408460003
0.5076798768
6
1.769888055
2.015899669
7
0
1.13756369
8
0.301465283
0.3111372758
9
0.2360135503
0.4837189029
gdf.describe()
20180501_afloat64
20181101_afloat64
count
31
31
mean
1.326080514
1.87172742
std
2.880966513
3.167233326
min
0
0.3111372758
25%
0.263528195
0.5759757934
50%
0.6785788797
0.9590120922
75%
1.208069895
1.337016055
max
16.23924546
17.20999261
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'
)