-
Notifications
You must be signed in to change notification settings - Fork 2
/
GEE_collection_Gen.py
56 lines (40 loc) · 1.64 KB
/
GEE_collection_Gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''
Script to create collections for Google Earth Engine plugin
To be used in QGIS Python console
tutorial video available here: https://youtu.be/ODBCPmQBEqU
'''
# Authors: Oliver (http://www.burdgis.com)
# License: MIT
import ee
import calendar
from datetime import datetime
from dateutil.relativedelta import *
from ee_plugin import Map
dataset = 'COPERNICUS/S5P/NRTI/L3_NO2' # change to required dataset
column = 'NO2_column_number_density' # change to required column
# Styling for the layers
band_viz = {
'min': 0,
'max': 0.0002,
'palette': ['black', 'blue', 'purple', 'cyan', 'green', 'yellow', 'red']
}
# accepts 2 str in numerical format YYYYmmdd e.g. 20190331
def getDates(startDate, endDate):
startDate = datetime.strptime(startDate, '%Y%m%d')
endDate = datetime.strptime(endDate, '%Y%m%d')
counter = (endDate.year - startDate.year) * 12 + (endDate.month - startDate.month) + 1
for d in range(counter):
collName = "{:02d}".format(d) + "Collection"
collStart = startDate + relativedelta(months=+d)
finalDay = calendar.monthrange(collStart.year, collStart.month)[1]
collEnd = collStart+relativedelta(day=finalDay)
layerName = collStart.strftime("%b %Y")
print(layerName)
yield[collName, collStart.strftime("%Y-%m-%d"), collEnd.strftime("%Y-%m-%d"), layerName]
# change dates here
for n in getDates('YYYYmmdd','YYYYmmdd'):
n[0] = ee.ImageCollection(dataset)\
.select(column)\
.filterDate(n[1], n[2])
Map.addLayer(n[0].mean(), band_viz, 'S5P N02 - ' + n[3] )
Map.setCenter(65.27, 24.11, 4)