Created
August 15, 2020 16:19
-
-
Save KMarkert/236884ad211625890ffd8fcf1a0f5aa4 to your computer and use it in GitHub Desktop.
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
using PyCall, Plots, Colors, FileIO; | |
# import the ee Python module into Julia | |
# and initialize the EE API | |
ee = pyimport("ee"); | |
ee.Initialize(); | |
# produce tabular data that can be plotted by data visualization in Julia | |
# Fetch a Landsat image. | |
img = ee.Image("LANDSAT/LT05/C01/T1_SR/LT05_034033_20000913"); | |
# define a function to calcuate NDVI from an LT5 image | |
function ndvi(img) | |
img.normalizedDifference(["B4","B3"]); | |
end | |
# apply function to image | |
ndvi_img = ndvi(img); | |
# define a color map to use for visualization | |
# choose green gradient and convert to hex color code | |
color_map = map(x -> hex(x,:RRGGBB), cgrad(:Greens_9)); | |
# get a link to the thumbnail NDVI image | |
thumburl = ndvi_img.getThumbUrl( | |
# define parameters to visualize image | |
Dict( | |
"min" => 0, | |
"max" => 0.8, | |
"dimensions" => 1024, | |
"format" => "png", | |
"palette" => color_map | |
) | |
); | |
# download the image from the url returned | |
localpath = download(thumburl); | |
# load the image into an Array | |
img = FileIO.load(localpath); | |
# display the image | |
plot(img, ticks = nothing, border = :none) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment