[MUSIC PLAYING] TYLER ERICKSON: So welcome
to the introduction to Earth Engine, Python edition. I am Tyler Erickson. This is Kayla. And we are going to
be your co-instructors for this session. There's also a few TAs that
are here in the audience. Tony is here, I see. And Kel and Justin
are in the back. So please raise your
hand if you need help at any time,
especially when we get to the hands on session. Let's see. The first thing I do want to
do as a preliminary though, is is there anybody
who hasn't signed up to run Earth Engine, basically? Gone to
signup.earthengine.google.com? Because we can
help you with that if you haven't done it already. But-- oh, there is one. OK. KAYLA HARDIE:
There's three, yeah. TYLER ERICKSON: Oh, three? I didn't see the other
ones because the lights are kind of bright here. So if we can get TAs
to help you sign up and register whatever account
you need with Earth Engine, that will help us out when we
get to the hands on section. Yep. All right. So we're going to be passing off
the presentation and the hands on session between
Kayla and myself. But I'm going to start
here with an introduction basically, to why we
think you should be here. And as Michael said earlier when
he was giving an introduction to all the talks, if you are a
very beginner to Earth Engine and wanted to learn about
some of the concepts of it, this may not be the
best course, because we have to spend a lot more
time, I guess, on the setup of the environment. But if you're coming in as
an experienced Python user or you already have experience
with Earth Engine going through like an introductory
class using JavaScript, then this is probably an
appropriate course for you. So here's the agenda that
we're going to go through. We're going to try to get
hands on after about 30 minutes into this session. And then we will do 30
minutes hands on this hour, we'll have a break, and
then in the second hour, we'll start with
hands on and then go to a little bit of slides
of the wrap up at the end. All right. So I want to start off with
some reasons of why you might be here to do Python and Jupyter. I love Python. I'm a programmer. My background is
working in Python, even though in Earth Engine
I do use the JavaScript Code Editor quite a bit of the time. But it's important
to understand that underneath the hood
of Earth Engine, it doesn't know
anything about Python. It doesn't know anything
about JavaScript. We have servers at
Google that are running Earth Engine on the back end. Most of it is written
in Java, although you don't need to know that. And there is a REST API that
sits in front of it, which is the main way that you
will submit questions to Earth Engine. And so everything has to
go through that REST API. But to make things
easier, especially if you're constructing
really complex analyzes, manipulating all kinds
of geospatial data that Earth Engine
has available, you're probably going to want to use
the JavaScript or Python client library rather than coding
directly against the web REST API. These are the two
client libraries that we maintain at
Google, but there are other people that have
created even other client libraries for other languages
to make Earth Engine useful. But I'm only going to
point out these two because these are the ones that
we support by the Earth Engine team. There's a lot of
stuff that you can do with these client libraries. You can access them through a
command line shell, which is OK if you're doing something
that doesn't involve a lot of interpretation
of the graphical data, if you're trying to
automate something. You can also build
web applications on top of them that
can speak directly to these client libraries. But that is usually
after you've already come up with an algorithm
that you have figured out how to code into
Earth Engine and you want to share it with
others around the world. When you're developing an
algorithm, one of the best ways to do this is to go
into the Code Editor because it's the environment
that we have created and designed specifically
to be able to do the things you mostly
want to do when you're designing an algorithm. We've designed it for
scientists developing geospatial algorithms. So there is a lot
of features that are available in the Code Editor
that make this journey easier. One of the key ones
is authentication. You can just log in and
get going right away. But we know that a lot of
people don't necessarily like to use JavaScript as their
primary preferred language. Actually, as a
show of hands here, how many people would say they
are stronger as a JavaScript programmer than a
Python programmer? How many of you are stronger
at some other language other than Python
as your preferred? Or is Python-- OK, so we've
got at least some other ones that are not JavaScript
or Python within there. Python it is accessible
to a lot of people. It's used in a lot
of universities. It's easy to read and
has a lot of advantages, so people tend to use it. But if you're developing,
especially something that deals with
spatial data, it's helpful to have some graphical
user environment in order to develop your algorithms. And for this, we often pair
the Python client libraries with Jupyter. And there's various Jupyter
IDEs we'll be going over today. So what is Jupyter? Kind of at a high
level, it's a project that focuses on open
standards for what's known as interactive computing. So you can actually encode a
description of your algorithm along with the code
that's running itself. So it's very useful for
explaining concepts, teaching, communicating things
that are really complex. And it's great for some
of the geospatial analyzes that we do with satellite data,
which tend to be quite complex. But the Jupyter project
just put together these Notebook formats,
protocols, and the Kernels, which is the coding
language that is running behind the Notebook
that can work in Python and other languages as well. They have standardized
this and then there have been a lot
of implementations that follow those standards. Jupyter Notebook
is the standard one that is developed by the Jupyter
project that you can download. It's an open source tool,
install on your own machine. But there are other
ones, like Colaboratory that we'll be using today,
which is a Google implementation of those standards that were put
forth at the Jupyter project. I'm just going to say
that there's a lot of them out there. I only listed like five
examples right now, but there's all kinds of
different Notebook environments that you can work in. The Notebook itself, it
consists of both cells that you can describe
what you're doing and code to actually run. So it's kind of a live
coding environment. Kayla's going to spend
a lot more time going through the features of what you
can do in Colab and in Jupyter environment. All right, to give a
quick kind of comparison of why you might want to be
using Python and Jupyter as opposed to JavaScript
and the Code Editor. I'm going to start with the
JavaScript and Code Editor. And for this, it's very
easy to get started. I mean, we've designed it
to be easy to log into. It has the
documentation in there. It has the standard way
that you're probably going to get back results, like
a map result, at the bottom. It's really set up for a lot
of the geospatial environments. As I said, it has built
in authentication. One of the great features
of the Code Editor is you can just say, "get link." It gives you a URL
and you can put that on Twitter, you can
send it to your collaborators or something, and they get a
snapshot of exactly what you were looking at and how
your algorithm was laid out. So it makes it very easy to
reproduce somebody else's work in your own environment, by
just sharing these links. We have lots of examples in
the Earth Engine documentation. Most of them are centered
on the Code Editor, because once again, because
it's very reproducible. Everybody can see
the exact same code and get the same
results as you do. But one of the
downsides, I would say, is that because we've
tried to standardize it all and give a good experience
for the use case that most people
want to have, there is I would say, limited
customization of what you can actually do in the Code Editor. Some of the people in the
community, the Earth Engine community have been
proving me wrong and customizing the Code Editor,
and in very creative ways. But it's not really designed
to be extensible in that way. From the other side, for
the Python and Jupyter, the Python and
Jupyter environment allows for intermixing,
once again, the description and the code so you can actually
have a multi-step process that's very easy to understand,
if it's laid out correctly. You can do a series of steps. It's not just "run" and
the entire thing goes. It can be like hundreds of
steps or dozens of steps, and we'll see that today. And it's easy to
share your code using more standard technologies
on the web for sharing code in general. Like Python Package Index, or
you can put your code on GitHub and import it from
there directly. There's many, many different
visualization options that are within the
Python ecosystem that we'll see a
little bit of today, but there's a lot
more that we are not going to be able to show
you because of the time. And Python is a
glue language that allows you to connect
to many other services. So we often use it to talk to
other Google Cloud Services and integrate a lot of things
together with Earth Engine. And as I said before,
it's very customizable. That can be a little
confusing when you start off, but it's actually very flexible
if you're using it long term. But on the downside, there
is assembly that is required. And it keeps getting
simpler year after year when I teach this, but
there's a little bit of stuff that we're going to have
to configure in order to get it working. And then related to that,
because it's customizable, you have to realize that when
you customize your environment, it's going to be harder for
somebody else to reproduce it. So you're going to
have to work extra hard to get help on some of the
work that you do if you're working in the Python land. All right. With that, I'm going
to turn it over to Kayla to talk
a little bit more about particular
environment to Colab. KAYLA HARDIE: Hello, everyone. So as Tyler was just
mentioning, the benefits of using Python and Jupyter. So now I'm going to
introduce Google Colab because it's an easy to get
started Jupyter Notebook. And that is what we're going
to use today in this workshop. We're using it because
it's really easy, like I said, to get started. There's easy integrations
with Google Drive and GitHub. Earth Engine comes
automatically installed, so that makes it really easy
for us to use it here today. And it has access
to free resources. So who's ready to get
started with Colab? [CHEERING] Woo! OK, so I want you to
all open your computers, if you haven't already, and
click on this Colab 101 link. TYLER ERICKSON: Actually,
let's go back to-- I should have pointed this
out on the very first slide that we had, there is
a link to this talk. KAYLA HARDIE: Oh, yeah. Sorry. Sorry-- sorry, guys! TYLER ERICKSON:
Or if you go just to the Geo for Good agenda
and search for this session, it's basically the link in the
resources is going to get you into this presentation. KAYLA HARDIE: So let me-- TYLER ERICKSON:
Yeah, if anybody's having problems with that,
just raise your hand please. KAYLA HARDIE: Could just
give it a couple of seconds. All right. TYLER ERICKSON: So
anybody need help at the moment getting in there? Please raise your
hand and the TAs will come and help
you get in there. Yeah, just keep your hand up
until they get all the way up to you. There's somebody up in the
front, Justin, as well. SPEAKER 1: I can take
you to the agenda slide and you've got to
scroll into the agenda. TYLER ERICKSON: If you wait,
it should scroll down for you there. If you pause a few
seconds, it should. SPEAKER 2: I've got
an interesting case. TYLER ERICKSON: Yeah? SPEAKER 2: I've got
no access to Drive. How do we access
the [INAUDIBLE]?? Drive link. Can we put it as a
gist or something? KAYLA HARDIE: It's a-- TYLER ERICKSON: That's a
good question, actually. SPEAKER 2: I've done it
where you can do a gist and then share that link. TYLER ERICKSON: So you're trying
to get to the presentation right now? Or you're trying to
get to the Colab? SPEAKER 2: I'm trying
to Colab Notebook, but if you don't
have access to Drive, the Notebook [INAUDIBLE]. TYLER ERICKSON: Oh, that is-- I don't think there's
a way that we can-- Yeah, actually Kel, if you
go and copy it into a gist then, as you said, you can
get them unblocked there. Thanks. All right, so
something that came up is some people do
not necessarily have access to Google Drive. Your organization may
have configured it in a certain way that
might not give you access. So Kel is going to spend
a few minutes giving you an alternative of how
to get the same code. I think it's good. KAYLA HARDIE: Yeah, that's good. So can you raise your hand
if you've gotten access to-- you're looking at this page? So a good chunk of people? All right. So the goal of this Colab that
I am showing you right now, it's nothing to do
with Earth Engine. It's just to get
familiar with Colab. So looking at this, the
first step you want to do is you can see my mouse,
go ahead and press Connect. That allows you to have
access to the Colab resources. TYLER ERICKSON: Might want
to increase size on that. KAYLA HARDIE: OK, sorry. One second. How is that for
everyone for size? So has everyone connected? Do you have a green
checkmark here? OK. So as Tyler mentioned, there's
a thing called cells in Colab. So you can have a text cell,
like this "Getting Started with Colab" tech cell. And if you double
click on it, you can see that there's a lot
of rich text you can add. You can add images. It's very flexible. And then there is
also code cells, which is what I put right here. I just defined a
very simple variable in Python, the number
of seconds in the day. And then if you write
out that variable, it will print it out for you. So in order to
run code in Colab, you can hover over and
see this play button. Or if you want a
shortcut, you can use Command Enter or Control Enter. So I'm going to click Run. And this is a warning that comes
up and asks you if you trust the code that we're giving you. I think we should say Yes. [LAUGHTER] TYLER ERICKSON: Kayla
does work for Google. KAYLA HARDIE: Yeah,
yeah, yeah, Yeah, yeah. Anyways, so we're
going to say Yes. And wow, we know the
number of seconds in a day. We've learned so much already. So then, I wanted
to show you guys that if you define a variable or
code above in the code cells-- so like this seconds
per day variable-- you can use it in
future code cells. So this code cell
below, I have the number of seconds in a week. So I'm just multiplying the
number of seconds in a day by seven. And you can run
that, and it works. So now I'm going to show you
some more co-op features. So when you're first
getting started, I don't know about you guys, but
when I first start with coding, I look for code
to copy and paste. That's always a
great place to start. So with Colab, those are
called code snippets. So if you go to the
bottom left corner, there's these arrows right
here, and you click on it, these are a whole
bunch of code snippets that you have access to
to easily copy and paste. So I am going to show
you one code snippet. We're going to type
in "visualization" and I'm going to click
on this, just randomly. It's a bar plot in Altair. I'll get into what
Altair is in a second. But I just want to show you,
you can click on any of these, you can search. And then when you
click on one, it has a brief description about
what it is right down here. And then you can insert it
really easily into your Colab. So maybe you want to
know where we insert it. So if you click
here or something and then you press
Insert, now we magically have code in our Colab. And if you inserted the
code in a different place, you can easily move the
code by using these arrows. How is it going? Is everyone-- cool. So I chose Altair
because Tyler mentioned that there's a lot
of fun visualization options in Python, and Altair
is a great plotting library. So let's see what
this bar plot is. You guys should press
Run so you can see. All right. So it's random. It has nothing to do with this
talk, but if you're interested, it shows the mean miles per
gallon for different cars from different countries. So now we're going to move on. So what if we get
an error in Colab? Right here, I wrote alt.color. Uh-oh, it's an error. So when you get an error,
there will be a red squiggly. And you can hover
your mouse over it and it might tell you
more information about it. So if this happens to you
today where you run something and you get an error, or in the
future, you can look at that. Another useful thing to know
is you can use tab completion for object methods. So if I type in Alt, which is
the Altair library, and then I type in chart, then
we get some methods that we can easily use. And if we don't know
what a method is and we want to get help, you
can use this help method and it will give you more
information about it. But if you're lazy and you don't
want to use the help method, you can just take your cursor
and hover over different things and normally there
is information. So for chart-- I don't know why it
doesn't want to do it. Oh, yeah. Then you get a whole
bunch of information about what is this chart object. And below here, I put
some additional resources. So there's an overview
of extra features if you want to learn
more about Colab. And then there's also
a guide to Markdown if you want to learn more
about that for the tech cells. And then there's
a link for Jupyter if you want to learn more
about the Jupyter project. How are we feeling right now? Awesome. Are we excited about Colab? [CHEERING] I love the enthusiasm. All right, so now I'm going
to pass it over to Tyler and we're going to
have even more fun. TYLER ERICKSON: Yeah. All right, I'm going
to check in with Kel, see how he is at getting-- did that work? OK. SPEAKER 2: I have the
link, but we don't have access, so [INAUDIBLE]. TYLER ERICKSON: OK. Yep, we'll put that in and so
we'll have them in the future. Thanks. All right. So that was a quick
introduction to Colab. There's a lot of other
features out there. We'll see some of them
as we're going through. And there's a lot of
also tutorials that are Colab specifics that will
give you ideas of what else Colab could do. But that's enough
to get us started for understanding
how we can work with Earth Engine in Colab. All right. So if you go back
to the presentation, we have a link to a
second Notebook, this EE, Earth Engine in Python 101. And that should open up a second
Notebook that looks like this. At the top, we're
just saying, hey, this is a code that we
are openly licensing. So feel free to copy
and use it however you want that matches
the license, which is the open Apache 2 license. But then it's going to start
down here with basically some setup of the
Notebook that we're going to run through in order
to get it prepared and ready to run Earth Engine. So this Notebook is set
out largely mirroring the JavaScript tutorial that
we have in the Earth Engine documentation. It's not quite the same. There's some variations because
of the differences in Python and the tools within there. And we definitely were not
as verbose and descriptive of all the different
sections of what's going on. But it follows along
the same pattern. But one thing that is
unique to running in Python is we do have to do that
little assembly required, a little bit of setup here. And so the first section here
is called authentication. And I set up a code
cell here that should work for most people. And we will see how
many it does work for. It depends kind of on how your
organization has configured and potentially constrained
the account that you are using. So we will debug that as-- if you have problems
running this, we will debug it as we go along. I'm going to go
through this live, but also realize if you switch
back to the presentation, there's a lot of step-by-step,
in a lot of detail, exactly what you will see on
each step of the authentication as you're going through here. But I encourage you
just to follow along with what I'm doing right here. So once again, we
get a little warning that this was not
authored by Google. It was actually myself that
was authoring this Notebook. But I'm using a test
account here to author it. And I'm going to
say, acknowledge that I'm going to want
to run that anyway. So we're going to
wait for a little bit to see the output of
the cell come back. And what it is going
to give us is a link that we can open up
by clicking on it. So that will be our next
step in authentication. So don't get rid of this tab. We're going to be
coming back to it later. But to start off with, I'm
going to click and make that a lot larger so we can see it. And it's going to bring up this
web page, which is our Notebook authenticator for Earth Engine. And there's a bit of information
that is very important in here. It's like, are you using
the correct account, the active account
that you want to use. So make sure that this is
your Earth Engine enabled account that you normally have. If you-- you might be
logged in your machine with multiple accounts, so make
sure that is the correct one. You might have to
switch it there. And then crucially,
underneath it, there should be listed
a Cloud project. And you can select a different
project by going in here and going under the dropdown
if you have multiple Cloud projects that you've
set up before. But it's key to note that it
needs to be an Earth Engine enabled Cloud
project that you are using when you do this
authentication in order for this to work. So I'm going to stop
right there because I bet there might be one or two
people that actually don't [AUDIO OUT] enable
the Cloud project. And if you do not,
please raise your hand so that we can get some help
to come around and help you try to create one. All right. So keep your hands up. The TAs will be
dispersing around here and we will see if it works. There's enough of-- there's
two in this row here. All right. I am actually going to jump
down and help just to move this along for a minute. Can you turn me off? Please raise your
hand if you're still trying to get an Earth
Engine enabled Cloud project. [INAUDIBLE] must accept
the Cloud terms of service. It's an easy click to that
page to acknowledge that you're creating a Cloud project. All right. Who needs more time to create
a Earth Engine enabled Cloud project? All right. I'm going to step
back up here then. I will select my Earth
Engine enabled Cloud project. And then hit Select to
dismiss that dialogue page. And now that you have the
account you want to use and the Cloud project
that you want to use, you could click the
Use read-only scopes if you want to restrict
what this Notebook can do. But we're going to
export something later on in the tutorial,
so I'm actually not going to click the read-only scopes. And then finally, I'm going
to generate a token down here. And it's actually
interesting to read what goes on underneath here. It explains what
you're granting. It's saying, this creates a
web application definition controlled by your
project provided above. After you click
Generate Token, Google asks for your permission to
grant the application access. So you're going to grant
permissions to something that you are creating yourself. So that's fairly safe to do. All right. When I hit Generate
Token, I will come to a choose your account page. Who needs more time there? All right, we're doing good. There's a lot of steps here,
but if you do them all quickly, it takes like 30 seconds to do. I'm going to select
that test account. It will then give me
a warning about Google hasn't verified this
app that I just created, which makes sense. But I'm going to continue to
use the app that I just created. And then finally it comes-- I shouldn't say
finally-- the next step is that it comes to a page that
asks you very specifically what permissions you're going to
grant to this application. And we want to allow it to view
and manage our Earth Engine data, which is the first
one, and then also manage data and permissions that are
stored in Google Cloud Storage. Because we export
from there, we often import data from Cloud Storage. So those are the two permissions
that we're going to grant. So I'll go to the bottom
and click Continue. And then gives you, once again,
another warning, make sure you trust this thing that you
just created, which is OK. The reason there's all these
different layers of that, you need to be careful when
you're granting permissions to an application, because it
could do stuff with your data. So that's why there are all
these checks and balances in describing
exactly what you're granting in a lot of detail. But what is key on this page
is a code that is generated and a little copy
button next to it. So go to find the
authorization code and copy it. We're going to paste
it on another page. Anybody need more time right
now with this, or we're good? If you raise your
hand if you need somebody to come and help you. We're good. All right. So I'm going to copy that. I'm actually going
to dismiss the page I was on so you can see
where I'm pasting it, which is back in that
Earth Engine 101 Notebook. So you paste it into that
box and then critically, press Return so
it actually knows that it needs to accept it. And this is what
we're hoping for-- successfully initialized. This is just one
way to authenticate. Once again, there's a lot
of flexibility around. I would refer you back to the
Earth Engine documentation. Look at Python
authentication if you want to know all details
about the other options. But this is kind
of the easiest way to authenticate from
within a Notebook. Lots of steps, but it will get
you authenticated within here. I see that most people are
looking like they're done. There's a lot of
discussion with the TA here, so they're probably
working through that. But anybody else need help? All right, we're
authenticated in the Notebook. Good thing it's one Notebook,
we only have to do that once. And the other
thing that I did is I wrote so if you run the
cell again and come back here, it basically just checks that
you're already authenticated and doesn't take you
through that flow again. All right, so we're good. All right, so that is the
first part of our setup. The next one is
that in a Notebook, and often in Python in general,
the standard set of libraries that Python has
is not necessarily going to be sufficient for
everything you want to do. And we, in particular,
are going to want to install something called
the Earth Engine Jupyter Library, which is going to
enable some different features in this Notebook. And so there is a
code block down here that tries to import
Earth Engine Jupyter. If it's not found,
it branches down here and starts doing
a Python install so that it's going to upload
it into your Colab Kernel. It's going to make
that library available. So that's what it's doing. Once it's installed,
it's going to tell you what your version is. This is a very new library that
I wrote over the past month, and so we're on a very
low number at this point. We're running with scissors,
but it's very useful. [LAUGHTER] All right, everybody good here? The next cell that
we have here is going to import all kinds
of other Python packages that we're going to
use along the way. Some of them are from that Earth
Engine Jupyter, or EE Jupyter that we just installed into
the Colab virtual machine. Another other ones are
Jupyter display libraries. I'm not going to go
through them in detail, but you can find all of
these by googling usually the name of it, and then
Python or Jupyter after it, and you'll find all
kinds of information on the web of what
these are about. All right. So now we have-- whoops, I need to
run that, actually. So now all those
libraries are going to be available in my Notebook. And now we're going
to start actually working with Earth Engine. We've done our setup. We're going to do-- make that a little larger. It's not too bad, but-- we're going to start off
by referencing an image object, an Earth Engine
image object, which is a digital elevation
model collected by the SRTM satellite. And we're going to assign
that to a variable called DEM. So I'm going to run
that right here. I should say, as I'm
going along here, you can see how far I'm
through the notebook over in this table of contents
on the left hand side. If you need room,
feel free to just click on the table
of contents again and it will disappear
off to the side. So we'll give you a little
bit more real estate. But when I can,
I'm going to keep that open just so
everybody can be aware of how far along we are. And if you want to jump
around in the Notebook, you can use that table of
contents to basically click and it will take you to the
particular part of the Notebook as well. All right, so we have
run to have a DEM object, an Earth Engine DEM object. And so we're going to print out
to see what is inside there. And what we have is a
really long printout. It's formatted somewhat nicely,
but also is somewhat verbose. But just telling you everything
about this Earth Engine image, what bands
it has, details of the projection
of the bands, what are the properties within here. This is a long description
for this image object and this is one of the shorter
ones we have in Earth Engine. When you start getting
into the Landsat data, they're really extensive. Like, a massive
amount of information is contained within that object. All right. So that's kind of useful. I mean, we got something
and we could read about it. But most of the time,
to work with the data, you're going to want to
display it on the map. So the next section
here is going to be displaying that
object on our first map. And in order to do
that, we are going to define some location,
the longitude and latitude on Earth, that we're going
to center our map on. And then we're going to build
some initialization parameters defining what is the
center of our map and what is the Zoom level here. And there's a little bit of
Python manipulation in here of reversing the list of
the long and lat data. And that is because the plotting
library that we're using uses a orientation of lat long,
yx, instead of long lat, xy. And so we have to reverse those
because Earth Engine does it in terms of xy. All right. So I'm going to run that. So we have that location
information in a variable. I can echo it back
if I want to see to verify that they switched
the coordinates around. And then finally, we are going
to instantiate a map object. And this-- before
I click on this, I'm going to go back to show
you where that was defined in the Python imports here. We had a line-- let me highlight it right here. From this Earth Engine Jupyter
package that we installed, there is a module
called ipyleaflet which has a map class inside of it. So that's the one that
we're going to use in order to get this behavior. So if I go back down to
where I'm going to run that-- it was already displayed
there, but I'll run it again. And now we have our map. Let me zoom out a
little bit so you can see the whole map itself. There we go. So it's an interactive map. I can click and drag here. You can zoom and pan, just like
you can do in the Code Editor. The background I'm using is I
really like this kind of design by Stamen Design. They're these map tiles
which is a watercolor design. And it's a good background
because it doesn't really look like satellite
data, so you can always see when you overlay
something on top of it. But there's a wide choice
of the tiles you can use in the background as well. So we've got our map here. Let me zoom back in a
little bit here again. And then the next cell
that we have is like, how do you take the DEM
image object that we have, pass in some visualization
parameters-- maximum value, minimum value-- give it a label and
add it to the map. So I'm going to click on that. And if you go now and
look at that map object, you can click and zoom around. The visualization parameters
are 0 to 1,000 meters. So a lot of the Western
US is above that, so that's why it's white there. But you should get
the idea that we have some type of visualization
applied to an image, and that is now on our
interactive map here. I'm going to go down to one
more cell that we have just to show that we can add
multiple layers to the same map. And I will click on
this map, Add Layer. And it's going to
display the same object, but choose some different
visualization parameters. So we have a min of 0, maximum
of 1,000, and then gray to red for the palette. And if I zoom back
up here, nobody is going to be writing home
about the great color choice that I had here. But it's just demonstrating
what you can do with this map and that within the map
itself, you have the ability to turn on and off
layers, just like you would in any kind of
GIS type of system. So take any questions to
where we got at this point. We also listed a little
bit of extra practice if you want to try something
with what you've learned up to this point. But we'll probably
keep going on. There's some
questions on the side. AUDIENCE: I just had a question
about Colab [INAUDIBLE] generally [INAUDIBLE]. So if there was a Google
Drive [INAUDIBLE] simple, but for editing,
if we could all see those changes and overall
the script [INAUDIBLE].. But when we clicked
on that link, if I made any changes
to these cells, am I automatically
making a copy of my own, or how does that work? TYLER ERICKSON: That's
a very good question. You see first a read-only
representation of it unless you are an editor. And you are not an
editor on that document. So if you try to
save, it will say, do you want to make a copy? So you don't have to worry
about it in this case. But if you were an
editor on it, then you do have to be in coordination
with whoever you are editing. And Kayla I found
this quite a bit when we were developing
the Notebooks. Sometimes we would
get into conflicts because we were both editing it. There is a revision history
that can help you reconcile. Where are we in there? Oh, sorry. I haven't actually saved
it yet, so it's not going to show me the
revision history. If you are co-editing
one, there is a way to look at the revision history
and it will do differences. So you can see who
added something there. But in general, I would
only have one person edit the Notebook at a time. It leads to a lot
less confusion. Also, you need to realize
that the programming Kernel that is running your code
is unique to yourself, even if you are sharing the
Colab document with somebody else. So just different
considerations that you have to have when you're
going with Colab when you're trying to do it
for collaborative work. AUDIENCE: Can you go back up
to where you chose the image? Where did you [INAUDIBLE]? TYLER ERICKSON: Oh, where
did we find the image? Yeah. KAYLA HARDIE: I think
it's [INAUDIBLE] TYLER ERICKSON: OK, so
where did we get this ID? That's a very good question. I didn't explain it
actually up there. Oh yeah, I can show where
this particular one went in, because that will bring us
out to the data catalog. But the easiest way
right now is to go to the web browser of the
Earth Engine data catalog, find an image or asset
that you want and then the ID is right here. The other way to
go about that is there is what's known
as the stack catalog. So you programmatically
can search for what data sets are available. That's a little
bit more advanced. But there are
alternatives to that. There was another question
over here, if I remember. AUDIENCE: I was just going
about the reverse [INAUDIBLE].. Is Earth Engine pretty
unique in doing the x and y? Google Maps is the
other one [INAUDIBLE].. TYLER ERICKSON: Is it unique? I would say Earth Engine follows
the [INAUDIBLE] standard. And Maps, I guess, doesn't. So it's always an argument of
people in the mapping community of which way do you do it. To me, logically, xy makes
a lot more sense to me. So I prefer it the way
Earth Engine does it. But yeah. Another question? AUDIENCE: [INAUDIBLE] TYLER ERICKSON: Yes. So if multiple people are
using the same Notebook, like we are in
this, everybody has to authenticate by themselves. You do authenticate just
once for a Notebook. But if you went away-- and Colab has this thing that
it recycles the virtual machine behind the scenes if you
leave it alone for too long. When you come back,
you would have to start over and
re-authenticate with it. If you move to something
outside of Colab, one of the other
environments you might be able to authenticate
once and save your credentials, like on your local drive,
and then it would persist. But in a Colab
environment, yeah. We try to keep you from having
to authenticate very often, but it does happen. All right, one
more question, or? Oh, go ahead. AUDIENCE: How much freedom do we
have to install extra packages? TYLER ERICKSON:
How much freedom do we have to install
extra Python packages? AUDIENCE: [INAUDIBLE] TYLER ERICKSON: Python packages. You have the freedom
to install them. But if they are graphical,
they may not work in Colab. There may be some
restrictions of what it can do in an output cell. So in general, you
can try to install it. It has to be a version
that is compatible with the other Python libraries
that are within Colab. So you might run
into some challenges there, depending on what
you're trying to install. If you host your own
Jupyter environment, you have a lot more flexibility
to install what you want. At this point, I
think we're ready to-- KAYLA HARDIE: Yeah. So we just displayed an image
that showed the elevation. Now let's find out even
more about this data, let's explore it further. Let's run a computation on it. So if we have
elevation data, I don't know, maybe we can think
about it-- what kind of things could we find out? One natural suggestion
would be to find the slope. If we have different
elevation, we might want to find the slope. So that's what we're
going to do just to show you what it's like to
run a computation on an image. So we're going to use the
ee.terrain.slope, which basically looks at the
neighboring elevation values for the different pixels
and calculates the slope. And then we're going
to display it on a map. So on this map, I've added
the elevation data, the one you already created with Tyler. And then we're going to
also add a slope layer. I put the max value
for the slope to be 30, just because it's
kind of rare to have a slope that's greater than
45 degrees in this area. So then I'm going to run it. And this is what the
slope looks like. Pretty cool. And as Tyler said, you can
toggle between the layers. So we can see the slope. But what if we wanted to find
the slope at a particular point on this map? Well, we're going to
use a map inspector. So there's two
different ways that we can create a map inspector
using the Earth Engine Jupyter library. The first is if you
already have a map. So we already created a
map up here, a map object-- map 2A. And we want to add
an inspector to it. We can create an inspector
using this Inspector method. And then we can just
display that inspector right beside the map using
this H box widget. Basically, the H box
widget just allows you to display things side
by side for the output. So right here we have the map
and we have the inspector. So I want you to go around
somewhere and pick a point. And you can see
that you can find the longitude and latitude, how
zoomed in we are, the scale. And we can also find
what we are looking for-- the elevation value in
meters and the slope. So I showed you if
we already had a map and we wanted to add
an inspector to it, we'd call that Inspector method. But if we didn't
already have a map and we just wanted to create
a map with an inspector, then we can call this function
called MapPlus right here. So MapPlus creates a map
and adds an inspector to it for you. So this doesn't have
any layers on it because I didn't
add any layers yet. But you can add
the layers to it. And now it's the same thing
as what we had above here. So there are just two
different approaches to adding an
inspector to your map. Do we have any questions? So now let's find out even more
information about our image. So we're going to
do some image math. We're going to calculate
the aspect, which is the orientation of
the slope, basically the direction of the slope,
measured clockwise in degrees. So 0 degrees is north, 90 is
east, 180 is south and to 270 is west. And then for fun,
we'll do some more math and we'll compute the
sine of the aspect. So the sine of the
aspect is the eastness of the slope with east being
plus 1 and west being minus 1. So we want to see what
those look like, right? So let's display
it side by side. So I'm just going to show you-- I showed you already
that with the H box, you could put the map and
the inspector side by side. Now we're going to put
two images side by side. And when we're talking
about eastness and westness, Tyler and I picked Mount Shasta. It's a mountain in
California because it's pretty cool to look at. The mountain face, one of them
faces east and one of them faces west, so it's
kind of fun to look at. So we made this point
around Mount Shasta. And we made a new map object and
we added the elevation to it. And then we made
another map object and added the sine
of the aspect. And then we can display
them side by side. So I don't know about
you guys, but the map on the left kind of just
reminds me of an iris. But it's not, it's Mount
Shasta, I assure you. But yeah, it's
pretty cool, right? I think it's cool to see. So here-- sorry, I
forgot to mention. We defined like what
the colors mean. Green is west, east is blue,
and white is north and south. So this is the east
side and this is the west side of the mountain. And we wanted to show
you that you can query the map objects we've created. So if you want to find
the center of the map, you can just call
whatever the map object was, in this
case, map 2B, the center. And then I also
wanted to show you that let's say you
move over here, but you also want to move
the same direction here. Like if you want those
maps to be synchronized, then we have a function here
that allows you to do that. So now if I move, it follows. All right. Any questions now? OK, we're going to
now do some stats. So this is where I would
like you guys to participate. What we're going to do is
we're going to create a custom geometry on a map
and then we're going to find the mean
elevation in that area. So the first step is we're going
to create that custom geometry. So we're going to
use draw control. So we're going to run this. And basically what
it does is it allows you to draw things on a map. So you can click
on this pentagon . And then draw a shape,
whatever you'd like. And then when you're done,
you can click Finish. So this is our custom
geometry that we're going to find the mean
elevation in this area, this blue shaded area. Has everyone created
their region? So it prints out the
region coordinates. And this does it in a nicer
way, not as much information. So we have this cell
basically to say, if you didn't create a
geometry you can run this. But it won't overwrite your
geometry that you made. And then now we're going
to calculate the stats. So like I said, we're looking
for the mean elevation on this geometry. So in order to
calculate the stats, we're going to
call Reduce Region so it looks at the region
we created, this geometry. And it applies a reducer to it. And you could use
another reducer here, but right now we're
interested in the mean. So that's why we're
using the mean. And then we have the scale,
which Tyler arbitrarily chose. I don't know how he picked 90. But you put a scale there. And then there's best
effort, which basically means if there's too
many pixels in your area and it doesn't work with
the scale that you chose, just Earth Engine, try your
best to still find a value. So my mean elevation
was 260 meters. Do we want to pause
for questions? Because we have three
minutes left, rather than talking about a new topic. If there are questions
on that, we'll take those before
we go to the break. AUDIENCE: Thank you. Does this scale mean resolution? KAYLA HARDIE: I don't
know, Tyler does that. How do you define? TYLER ERICKSON: Can
you turn me back on? The scale means the
resolution that we are sampling the image at. So if the underlying data
set in this case, SRTM-- I can't remember where they're
using the 30 meter or the 90 meter version of it--
but that is basically the pixel spacing there. You can sample at a
larger, because we do what's known as pyramiding
to basically report the information
at a higher scale. And so you can control
basically, of how finely you are sampling it. Generally, if you're
doing something like we are, like sampling
points on an image, you want to match the scale to
the resolution of the image. And we just took a
shortcut doing it this way. We could have programmatically
asked the image what its native resolution is. There's something that's called
nominal scale in the Earth Engine toolbox that
you can do that. Scale also comes into play
even more importantly, when you start doing things-- I guess in this case, it
was for a polygon there. So how finely are you sampling
within that polygon region that you're sampling? AUDIENCE: The resolution
of the resultant-- the resolution of
the resultant, right? TYLER ERICKSON: The
resolution that you are calculating the results. In this case, we
are reducing down 90 meter pixels, basically,
an image of 90 meter pixels. If you make it too
crude, you're going to get a very inaccurate
result very quickly. So it's a trade-off of
how much computation you want to do,
especially when you're looking at really large
regions on a very finely detailed image. AUDIENCE: Yeah. Thank you. KAYLA HARDIE: If we
increase the scale, then it should be
different, right? TYLER ERICKSON: It will be. If you change the scale
in here, it will probably be slightly different. It depends on how
variable the topography is that you're trying to reduce. KAYLA HARDIE: It did
change by two meters. TYLER ERICKSON: But that's
actually an interesting thing that Python actually
can be very good for is that you
can set up a loop and sample for a
variety of scales and answer that question of,
does it make a difference or not? You can do what's known as a
sensitivity analysis of varying one parameter to get
a bunch of results, and then just seeing
whether you can get by with a coarser scale. It might be appropriate
for your application. AUDIENCE: I just
wanted to verify I'm understanding what's going
on when we draw the polygon. That's locally? And then this command about
create an Earth Engine, server side geometry,
that's putting it up into Earth Engine. And you have to do that
in order for the reducer to work in the next step, right? TYLER ERICKSON: That is correct. You are drawing
client side there, and you do have to instantiate
a server side object in order to get the reducer to calculate
it on the server side, yes. Yep. KAYLA HARDIE: Thanks for asking. AUDIENCE: I have one question. I can see that-- is there an easy
way to have access to the different functions
within the Python package that you would just load? For example, I can
see that you input from EE Jupyter ipyleaflet,
the inspector command. So is there a way to
get an overview of what different commands exist
and what do they offer? Or do we go to the GitHub
and try to get an idea? TYLER ERICKSON: If the
package has been constructed as it should with the correct
documentation strings, then you should be able to type
Help and the name of the object or the method, and it should
give you the appropriate level of details. For the EE Jupyter,
I am definitely making no guarantees that
that is the case right now. It's something that
we will want to do. It probably will be better
when you do the EE library, the Earth Engine library,
if you do Help on that, it will give you
a lot of details. The other thing that you can do
is there's a command in Python called dir, directory
structure for the objects. And that will give you the
properties, the methods, lots of information about that. AUDIENCE: Because right now, we
are restricted to the function that you're showing this Jupyter
Notebook to what we learn. There might be much
more information we have to explore ourselves. TYLER ERICKSON: Yes,
there is so much more than we can cover in EE 101. There's over 1,500 different
Earth Engine methods at this point on probably
a dozen different objects-- actually more objects than that. AUDIENCE: There's also
comprehensive online docs for all 1,500 methods. TYLER ERICKSON: Yeah,
our documentation, when you go into the Earth
Engine documentation reference client libraries, it will give
you a list of the objects. Most of the examples
are in JavaScript, but the objects are
available in Python as well. KAYLA HARDIE: I ran it,
but it doesn't really-- TYLER ERICKSON:
Oh, so she actually ran it on one of the
Inspector objects. And it is giving
you too much detail. KAYLA HARDIE: It looks a lot. TYLER ERICKSON: It's talking
about everything a widget can do underneath the hood. So that's going to be
probably more detail than you want for a geospatial analysis. AUDIENCE: Yeah,
follow up on that. So the method name is similar
to what it is in JavaScript, is it? Like ee.images in JavaScript. Like an R, if [INAUDIBLE]
is with the dollar sign, but the same command name. So in Python also it's that way? TYLER ERICKSON: Generally we
have the same naming convention for the Earth Engine
classes and methods both in JavaScript
and in Python. There are some
exceptions to that because there are reserved
words in each of those languages that we have to avoid. And that is sort of an
open question too, of do we also provide the
appropriate capitalization for the language, in
addition to making it compatible with JavaScript? Because there is
a lot of methods we probably would rename if
we were just solely creating a Python library. So we kind of wrestle with
this, whether we should do that or not. AUDIENCE: Got it. Yeah. No, otherwise I was like
searching two places. Yeah, thank you. KAYLA HARDIE: I think we
should take a break now, right? TYLER ERICKSON: So
let's take a break. Do we 10 for-- KAYLA HARDIE: Yeah,
we come back at 2:30. TYLER ERICKSON: So let's
take a break for 10 minutes and then we will carry on
with the second hour of this KAYLA HARDIE: Thank you. [AUDIO LOGO]