Last active
May 22, 2021 18:20
-
-
Save jdbcode/c316a62d2ce7ace80f21bd9cfa8d6c30 to your computer and use it in GitHub Desktop.
[Medium] RStudio Cloud and rgee nightlights
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgee) | |
ee_Initialize() | |
createTimeBand <- function(img) { | |
year <- (ee$Date(img$get("system:time_start")) | |
$get("year")$subtract(1991L)) | |
ee$Image(year)$byte()$addBands(img) | |
} | |
collection <- (ee$ImageCollection("NOAA/DMSP-OLS/NIGHTTIME_LIGHTS") | |
$select("stable_lights") | |
$map(createTimeBand)) | |
col_reduce <- collection$reduce(ee$Reducer$linearFit()) | |
col_reduce <- col_reduce$addBands(col_reduce$select("scale")) | |
ee_print(col_reduce) | |
Map$setCenter(9.08203, 47.39835, 3) | |
Map$addLayer( | |
eeObject = col_reduce, | |
visParams = list( | |
bands = c("scale", "offset", "scale"), | |
min = 0, | |
max = c(0.18, 20, -0.18) | |
), | |
name = "stable lights trend" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment