1 00:00:01,230 --> 00:00:02,340 Hello, everybody. 2 00:00:02,340 --> 00:00:05,490 Welcome back to another code tutorial. 3 00:00:05,490 --> 00:00:08,880 This week, we're gonna learn how to filter for clouds, 4 00:00:08,880 --> 00:00:10,770 so how to make cloud-free imagery, 5 00:00:10,770 --> 00:00:14,300 and also how to make false color composites. 6 00:00:16,200 --> 00:00:19,350 So last week, we learned how to make true color composites 7 00:00:19,350 --> 00:00:21,810 and how to make an ROI. 8 00:00:21,810 --> 00:00:23,493 So again, here's my ROI. 9 00:00:25,410 --> 00:00:28,290 Let's use the same ROI that we used last week, 10 00:00:28,290 --> 00:00:31,620 and you can use the same script that you started last week 11 00:00:31,620 --> 00:00:33,210 or you can make a new script. 12 00:00:33,210 --> 00:00:36,600 I'm just gonna continue on in the script from last week. 13 00:00:36,600 --> 00:00:40,590 So in order to make this a new script for Module 3, 14 00:00:40,590 --> 00:00:45,030 I'm gonna say save as and save it as Module 3. 15 00:00:45,030 --> 00:00:47,490 So that M2 script still exists. 16 00:00:47,490 --> 00:00:50,433 I'm just creating a new one called M3 that I'll work in. 17 00:00:52,830 --> 00:00:55,260 I also wanna do a little bit of housekeeping 18 00:00:55,260 --> 00:00:57,900 in terms of organizing my script. 19 00:00:57,900 --> 00:01:02,790 So first off, it's important to label your, 20 00:01:02,790 --> 00:01:05,400 the top of your script with some information. 21 00:01:05,400 --> 00:01:10,400 So for example, I might say created by my name, 22 00:01:10,590 --> 00:01:14,670 created and the date, 23 00:01:14,670 --> 00:01:17,160 oh, 2024, 24 00:01:17,160 --> 00:01:22,160 and then I'm also gonna do some block organization. 25 00:01:23,280 --> 00:01:28,170 So I'm creating these blocks of comments, 26 00:01:28,170 --> 00:01:32,253 and I'm gonna label last week's code as TRUE COLOR. 27 00:01:33,540 --> 00:01:35,220 So this is just like a way 28 00:01:35,220 --> 00:01:40,220 to visually break apart and organize your code, 29 00:01:40,410 --> 00:01:43,590 and then for the new code this week, 30 00:01:43,590 --> 00:01:48,590 I'm gonna label that as CLOUDS and FALSE COLOR. 31 00:01:48,690 --> 00:01:51,210 So now when I'm just, like, quickly looking at my code, 32 00:01:51,210 --> 00:01:53,583 I can see the different sections really easily. 33 00:01:57,900 --> 00:02:01,860 I also am going to, well, I guess we can run the code 34 00:02:01,860 --> 00:02:04,210 from last week to remind ourselves what we did. 35 00:02:07,050 --> 00:02:07,883 Run. 36 00:02:10,590 --> 00:02:12,993 It's taking a minute to load, 37 00:02:14,760 --> 00:02:18,610 but last week, remember we used the Landsat 8 satellite 38 00:02:19,980 --> 00:02:22,710 and used the red, green and blue bands 39 00:02:22,710 --> 00:02:24,630 in the red, green and blue channels 40 00:02:24,630 --> 00:02:28,110 and created this true color image. 41 00:02:28,110 --> 00:02:30,600 I'm gonna start with some new code today. 42 00:02:30,600 --> 00:02:33,270 So I'm actually gonna comment out this code 43 00:02:33,270 --> 00:02:34,650 that we did last time, 44 00:02:34,650 --> 00:02:38,100 and I'm gonna import a new satellite to work with. 45 00:02:38,100 --> 00:02:42,030 So last week, we used Landsat 8 and the top of atmosphere. 46 00:02:42,030 --> 00:02:44,430 We learned in the lecture this week the difference between 47 00:02:44,430 --> 00:02:47,160 top of atmosphere and surface reflectance. 48 00:02:47,160 --> 00:02:50,850 So let's grab a surface reflectance dataset this week. 49 00:02:50,850 --> 00:02:55,230 I also wanna use a different Landsat sensor 50 00:02:55,230 --> 00:02:57,450 to just show the differences between 51 00:02:57,450 --> 00:02:59,160 Landsat 8 and another one. 52 00:02:59,160 --> 00:03:00,350 So let's use Landsat 5. 53 00:03:01,890 --> 00:03:03,240 Again, we don't want raw scenes 54 00:03:03,240 --> 00:03:06,000 'cause those are typically lowest quality, 55 00:03:06,000 --> 00:03:08,190 and then the top of atmosphere, 56 00:03:08,190 --> 00:03:10,950 as we talked about in lecture, can have some haze effects. 57 00:03:10,950 --> 00:03:14,250 So what we're gonna use is this Tier 1, 58 00:03:14,250 --> 00:03:17,010 and we can click on it and see this represents 59 00:03:17,010 --> 00:03:20,670 the atmospherically corrected surface reflectance values. 60 00:03:20,670 --> 00:03:22,380 So great. That's what we want. 61 00:03:22,380 --> 00:03:24,930 Some other important things to look at when you're looking 62 00:03:24,930 --> 00:03:28,080 at datasets is the date range of your dataset. 63 00:03:28,080 --> 00:03:32,580 So Landsat 5 goes from 1984 to 2012. 64 00:03:32,580 --> 00:03:33,840 That's good to know. 65 00:03:33,840 --> 00:03:37,950 We can also look at some other qualities of this dataset, 66 00:03:37,950 --> 00:03:39,693 including the band names. 67 00:03:41,100 --> 00:03:43,410 So the band names are named a little bit different 68 00:03:43,410 --> 00:03:46,110 in this dataset than they were in the last. 69 00:03:46,110 --> 00:03:49,740 So because these represent surface reflectance values, 70 00:03:49,740 --> 00:03:54,363 the band names are SR_ and then the band number. 71 00:03:55,500 --> 00:03:57,930 I also wanna point out that if you remember last week, 72 00:03:57,930 --> 00:04:02,550 Landsat 8's red, green and blue were B4, B3 and B2, 73 00:04:02,550 --> 00:04:05,910 but for Landsat 5, because they don't have the coastal blue 74 00:04:05,910 --> 00:04:09,750 that in Landsat 8 is labeled B1, 75 00:04:09,750 --> 00:04:13,800 the B3 band is red, B2 is green, 76 00:04:13,800 --> 00:04:15,180 and B1 is blue. 77 00:04:15,180 --> 00:04:16,980 So that's important to note. 78 00:04:16,980 --> 00:04:21,060 Also, you might notice that the min and max values 79 00:04:21,060 --> 00:04:25,800 are different in this satellite than they were in Landsat 8. 80 00:04:25,800 --> 00:04:27,200 So that's important to note. 81 00:04:28,260 --> 00:04:30,330 I also wanna go to IMAGE PROPERTIES really quick 82 00:04:30,330 --> 00:04:32,880 and show you this property name called CLOUD_COVER 83 00:04:32,880 --> 00:04:34,980 'cause we'll be using it today. 84 00:04:34,980 --> 00:04:37,320 So the name is CLOUD_COVER, 85 00:04:37,320 --> 00:04:40,590 and then the description is that it represents 86 00:04:40,590 --> 00:04:44,190 the percent cloud cover in each Landsat tile 87 00:04:44,190 --> 00:04:46,323 between 0 and 100. 88 00:04:47,730 --> 00:04:51,120 Great. So I'm gonna import this image collection. 89 00:04:51,120 --> 00:04:52,170 I'm gonna name it L5, 90 00:04:55,590 --> 00:04:58,200 and now we can work with it down here. 91 00:04:58,200 --> 00:04:59,070 So first things first, 92 00:04:59,070 --> 00:05:04,070 I'm gonna create a variable called L5_notcloudy, 93 00:05:04,200 --> 00:05:06,990 and so within this variable, 94 00:05:06,990 --> 00:05:11,990 we're gonna summarize that entire Landsat 5 image collection 95 00:05:12,780 --> 00:05:16,980 into just one single image that we will visualize. 96 00:05:16,980 --> 00:05:18,780 So we're gonna start off 97 00:05:18,780 --> 00:05:21,090 with that Landsat 5 image collection. 98 00:05:21,090 --> 00:05:24,690 First, I'm gonna filter it again to the bounds of my ROI. 99 00:05:24,690 --> 00:05:27,303 So my ROI is called FortCollins. 100 00:05:28,890 --> 00:05:31,473 I'm gonna filter it by date as well. 101 00:05:32,670 --> 00:05:35,130 This is not necessary this week, 102 00:05:35,130 --> 00:05:38,490 but I'm just doing it because it gives the computer 103 00:05:38,490 --> 00:05:42,210 less data to sift through, and so it'll just process faster. 104 00:05:42,210 --> 00:05:44,790 So I'm using this filterDate function, 105 00:05:44,790 --> 00:05:46,860 and within this filterDate function, 106 00:05:46,860 --> 00:05:48,510 you can put just years. 107 00:05:48,510 --> 00:05:51,480 You could put in entire date ranges, 108 00:05:51,480 --> 00:05:53,850 so including days, months and years. 109 00:05:53,850 --> 00:05:55,770 For now, I'm just gonna put the year. 110 00:05:55,770 --> 00:06:00,770 I'm gonna get data from 2000 to 2002. 111 00:06:01,020 --> 00:06:02,460 Again, this is just kind of random 112 00:06:02,460 --> 00:06:05,700 because I don't want to work with so much data, 113 00:06:05,700 --> 00:06:09,690 and then finally, now we're going to filter by clouds, 114 00:06:09,690 --> 00:06:14,690 and the syntax for filtering clouds is a little clunky. 115 00:06:14,910 --> 00:06:17,850 First we're gonna tell it that we're filtering something, 116 00:06:17,850 --> 00:06:22,850 and then we're gonna use this Filter.lte function. 117 00:06:23,400 --> 00:06:27,720 This represents less than or equal to. 118 00:06:27,720 --> 00:06:29,490 If we wanna learn more about this, again, 119 00:06:29,490 --> 00:06:33,030 we can go to the docs and search 120 00:06:33,030 --> 00:06:34,953 for ee.Filter.lte, 121 00:06:36,390 --> 00:06:40,027 and click on it, and it says, 122 00:06:40,027 --> 00:06:43,830 "Filter on metadata less than or equal to a given value." 123 00:06:43,830 --> 00:06:46,140 So there's two arguments that are required, 124 00:06:46,140 --> 00:06:48,990 the name of the property that you're filtering 125 00:06:48,990 --> 00:06:50,340 and then the value. 126 00:06:50,340 --> 00:06:53,730 So in our case, 127 00:06:53,730 --> 00:06:57,540 the name of the property is CLOUD_COVER, 128 00:06:57,540 --> 00:07:02,540 and then we can add a number to represent the cloud cover 129 00:07:02,640 --> 00:07:04,950 that we want less than or equal to 130 00:07:04,950 --> 00:07:07,470 to be included in our final image collection. 131 00:07:07,470 --> 00:07:08,763 So I'm gonna put 20. 132 00:07:10,290 --> 00:07:14,073 I also wanna point out that there's ee.Filter.gte. 133 00:07:15,990 --> 00:07:19,290 So same concept, it'll just do all the numbers 134 00:07:19,290 --> 00:07:21,540 above the number that you list. 135 00:07:21,540 --> 00:07:23,220 There's also greater than. 136 00:07:23,220 --> 00:07:24,690 So there's a lot of different options here 137 00:07:24,690 --> 00:07:27,423 that you could explore, and then again, 138 00:07:28,770 --> 00:07:32,250 if I left this variable as is right now, 139 00:07:32,250 --> 00:07:34,410 it would still be an image collection. 140 00:07:34,410 --> 00:07:37,800 So it might contain a couple of images 141 00:07:37,800 --> 00:07:41,910 that are within my filter bounds, within my filter dates, 142 00:07:41,910 --> 00:07:44,190 and that have cloud cover that's less than 20. 143 00:07:44,190 --> 00:07:47,310 So I need to summarize that image collection 144 00:07:47,310 --> 00:07:49,710 into just one image somehow. 145 00:07:49,710 --> 00:07:52,320 So I'm gonna put median. 146 00:07:52,320 --> 00:07:55,053 So I'll take a median of all of those images. 147 00:07:56,910 --> 00:07:59,220 Great, so now we can add 148 00:07:59,220 --> 00:08:04,113 that notcloudy Landsat 5 image. 149 00:08:05,190 --> 00:08:07,020 We can add it to our map. 150 00:08:07,020 --> 00:08:10,170 So I'm gonna first put the name 151 00:08:10,170 --> 00:08:13,410 of my image variable. 152 00:08:13,410 --> 00:08:16,263 Then I'm gonna add some visualization parameters. 153 00:08:17,100 --> 00:08:21,840 So the important one to put here is the band names. 154 00:08:21,840 --> 00:08:26,070 So SR_B3 is red. 155 00:08:26,070 --> 00:08:29,853 SR_B2 is green. 156 00:08:31,900 --> 00:08:36,450 SR_B1 is blue, and then this is a list, 157 00:08:36,450 --> 00:08:38,163 so I have to put it in brackets. 158 00:08:39,510 --> 00:08:42,060 Let's also put the min and max values. 159 00:08:42,060 --> 00:08:44,820 So if you remember, min they said was 1. 160 00:08:44,820 --> 00:08:48,060 Max was around 60000. 161 00:08:48,060 --> 00:08:50,100 We can edit that in a second, 162 00:08:50,100 --> 00:08:53,733 and then let's add a name to our map, so I'm gonna say L5, 163 00:08:54,960 --> 00:08:58,563 and then this is a true color image. 164 00:08:59,940 --> 00:09:01,533 So let's run that. 165 00:09:03,750 --> 00:09:05,370 Oh, okay. 166 00:09:05,370 --> 00:09:10,170 So what happened here is I forgot to clip my image 167 00:09:10,170 --> 00:09:12,630 to exactly to my ROI. 168 00:09:12,630 --> 00:09:17,630 So what it's giving me here is the entire Landsat tile, 169 00:09:18,210 --> 00:09:20,310 and actually it's given me two Landsat tiles 170 00:09:20,310 --> 00:09:22,293 'cause it seems like my ROI, 171 00:09:23,430 --> 00:09:27,330 there's two tiles that both sit on top of my ROI. 172 00:09:27,330 --> 00:09:31,407 So after this variable, I need to put .clip(FortCollins), 173 00:09:32,790 --> 00:09:37,173 and then it'll clip it just to my little ROI. 174 00:09:38,310 --> 00:09:40,650 Okay, so one of the first things I'm seeing here 175 00:09:40,650 --> 00:09:42,693 is that this image is pretty dark. 176 00:09:43,560 --> 00:09:46,320 So I'm gonna go to the Inspector tool 177 00:09:46,320 --> 00:09:47,943 and click around a little bit. 178 00:09:48,870 --> 00:09:51,033 I can see the values here. 179 00:09:52,290 --> 00:09:57,290 So you can click on some low reflectance value pixels 180 00:09:58,050 --> 00:10:00,960 and see what those are. 181 00:10:00,960 --> 00:10:05,370 You can click on some high reflectance value pixels, 182 00:10:05,370 --> 00:10:08,580 and this is just giving me an idea of what the, like, 183 00:10:08,580 --> 00:10:11,193 max, min and max might be. 184 00:10:12,120 --> 00:10:15,570 I could also manually look in here 185 00:10:15,570 --> 00:10:20,460 and say stretch the image by 100%, 186 00:10:20,460 --> 00:10:25,460 and it'll give me the range of my image. 187 00:10:25,680 --> 00:10:28,563 Okay, so that's good to know. 188 00:10:29,850 --> 00:10:32,190 I'm gonna change my min to, let's say, 189 00:10:32,190 --> 00:10:37,190 5000 and my max to 20000, and I'm gonna run it again, 190 00:10:38,130 --> 00:10:40,050 and yep, this is a bit clearer. 191 00:10:40,050 --> 00:10:42,600 I can see more in the landscape now, which is good. 192 00:10:44,640 --> 00:10:48,480 Okay, so again, we filtered for cloud cover 193 00:10:48,480 --> 00:10:51,420 to get less than 20% clouds. 194 00:10:51,420 --> 00:10:54,130 What if we did less than 195 00:10:55,050 --> 00:10:58,503 1% clouds? 196 00:10:59,340 --> 00:11:00,690 So it kinda looks the same. 197 00:11:01,590 --> 00:11:04,380 Colorado's not the cloudiest place ever, 198 00:11:04,380 --> 00:11:06,967 but just for fun, we could say, 199 00:11:06,967 --> 00:11:11,967 "What if I want an image that has greater than 30% clouds?" 200 00:11:13,050 --> 00:11:15,390 I'm gonna run that, and let's see. 201 00:11:15,390 --> 00:11:18,420 Yeah, so just to show you that the code works, 202 00:11:18,420 --> 00:11:22,050 if I put greater than 30% cloud cover, 203 00:11:22,050 --> 00:11:25,140 it'll give me a pretty cloudy photo. 204 00:11:25,140 --> 00:11:29,583 So let's go back less than or equal to 20% cloud cover, 205 00:11:32,580 --> 00:11:37,470 and now I want to visualize 206 00:11:37,470 --> 00:11:40,980 this image but with a false color composite, 207 00:11:40,980 --> 00:11:42,960 not a true color composite. 208 00:11:42,960 --> 00:11:47,340 So I'm just gonna copy-paste this code, 209 00:11:47,340 --> 00:11:49,080 and then I'm gonna edit it down here. 210 00:11:49,080 --> 00:11:51,780 So this is my false color. 211 00:11:51,780 --> 00:11:54,273 This was my true color. 212 00:11:55,380 --> 00:11:57,960 So in order to make this false color, 213 00:11:57,960 --> 00:12:00,150 I need to change the band names. 214 00:12:00,150 --> 00:12:04,509 So I'm gonna make this an infrared false color, 215 00:12:04,509 --> 00:12:07,260 infrared, 216 00:12:07,260 --> 00:12:10,350 and to do that, 217 00:12:10,350 --> 00:12:14,103 I need to assign the red channel to the infrared, 218 00:12:16,050 --> 00:12:19,020 the green channel to the red band, 219 00:12:19,020 --> 00:12:21,303 and the blue channel to the green band. 220 00:12:22,320 --> 00:12:25,710 I'm gonna make sure I label my map 221 00:12:25,710 --> 00:12:30,093 so I know what it's visualizing, and now I can run, 222 00:12:35,430 --> 00:12:36,960 and the image looks quite different. 223 00:12:36,960 --> 00:12:41,830 So the areas that were green before are red 224 00:12:45,400 --> 00:12:49,830 in this image, and I'll let you think about why that is. 225 00:12:49,830 --> 00:12:52,230 So in the assignment for this week for Yellowdig, 226 00:12:52,230 --> 00:12:55,680 I asked you to create a infrared false color 227 00:12:55,680 --> 00:13:00,360 and a short wave false color image within your ROI. 228 00:13:00,360 --> 00:13:04,470 So what you'll do next is take this code 229 00:13:04,470 --> 00:13:06,120 and then change the bands again 230 00:13:06,120 --> 00:13:10,173 to represent a short wave false color image. 231 00:13:12,090 --> 00:13:14,163 So don't forget to save your code, 232 00:13:18,570 --> 00:13:21,180 and then again, when you're sharing your code, 233 00:13:21,180 --> 00:13:25,563 click Get Link and then copy-paste what's here. 234 00:13:28,680 --> 00:13:30,903 All right, thanks, and see you next week.