-
Notifications
You must be signed in to change notification settings - Fork 265
/
ntl_linear_fit.py
31 lines (25 loc) · 1 KB
/
ntl_linear_fit.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
import ee
from ee_plugin import Map
# Compute the trend of nighttime lights from DMSP.
# Add a band containing image date as years since 1990.
def createTimeBand(img):
year = img.date().difference(ee.Date('1990-01-01'), 'year')
return ee.Image(year).float().addBands(img)
# function createTimeBand(img) {
# year = img.date().difference(ee.Date('1990-01-01'), 'year')
# return ee.Image(year).float().addBands(img)
# }
# Fit a linear trend to the nighttime lights collection.
collection = ee.ImageCollection('NOAA/DMSP-OLS/CALIBRATED_LIGHTS_V4') \
.select('avg_vis') \
.map(createTimeBand)
fit = collection.reduce(ee.Reducer.linearFit())
# Display a single image
Map.addLayer(ee.Image(collection.select('avg_vis').first()),
{'min': 0, 'max': 63},
'stable lights first asset')
# Display trend in red/blue, brightness in green.
Map.setCenter(30, 45, 4)
Map.addLayer(fit,
{'min': 0, 'max': [0.18, 20, -0.18], 'bands': ['scale', 'offset', 'scale']},
'stable lights trend')