Last active
August 15, 2020 17:47
-
-
Save KMarkert/f111656cf6ef611809b4003d10d99f11 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; | |
theme(:bright); | |
# 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"); | |
# Select Red and NIR bands, scale them, and sample 500 points. | |
samp_fc = img.select(["B3","B4"]).divide(10000).sample(scale=30, numPixels=500); | |
# Arrange the sample as a list of lists. | |
samp_dict = samp_fc.reduceColumns(ee.Reducer.toList().repeat(2), ["B3", "B4"]); | |
samp_list = ee.List(samp_dict.get("list")); | |
# Save server-side ee.List as a client-side Array. | |
samp_data = samp_list.getInfo(); | |
# unpack the red/nir Array rows to 1-d Vectors | |
red,nir = [samp_data[x,:] for x in 1:size(samp_data,1)]; | |
# plot the data | |
scatter(red,nir,markersize=5,alpha=0.5,xlabel="Red",ylabel="NIR",leg=false,dpi=200) | |
# you can save the figure using: 'savefig("<path-to-file>,png")' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment