Vâng! Điều này rất hữu ích và cực kỳ nhanh chóng!
This introductory training is part of the official training materials prepared by the United States Department of Agriculture.
Code Editor cho phép người dùng thực hiện được tất cả các chức năng của Earth Engine, tuy nhiên, cần có hiểu biết cơ bản về lập trình và JavaScript. Trong bài tập này, chúng ta sẽ tiếp tục học về ngôn ngữ lập trình Java và các khái niệm mới về dữ liệu không gian trong Earth Engine. Bạn sẽ tiếp tục những gì được học ở bài tập 2 về đối tượng ảnh; tuy nhiên trong bài học này bạn sẽ tập trung nhiều hơn vào các tập hợp hoặc chồng lớp của các đối tượng ảnh có tính chất tương tự. Trong bài học này, bạn sẽ tập trung vào các khái niệm cơ bản và phương pháp liên quan đến các tập hợp ảnh trong Earth Engine. Đây là hướng dẫn giúp người sử dụng có thể viết được các sript đơn giản trong JavaScript.
Các Hàm sử dụng Với Tập Hợp Ảnh
1. Bây giờ chúng ta biết các hàm của mình đã hoạt động, cùng áp dụng chúng cho tập ảnh mà bạn đã tạo trong nửa đầu bài tập này
2. Copy hàm lọc mây (cloud mask) như dưới đây.
var cloudfunction = function(image){ //use add the cloud likelihood band to the image var CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image); //isolate the cloud likelihood band var quality = CloudScore.select('cloud'); //get pixels above the threshold var cloud01 = quality.gt(cloud_thresh); //create a mask from high likelihood pixels var cloudmask = image.mask().and(cloud01.not()); //mask those pixels from the image return image.mask(cloudmask); }
3. Sau đó mở script đã được đặt tên là ‘Ex 3 Image Collection Part 5’.
4. Paste hàm lọc mây và biến cloud_thresh vào script (sau những dòng lệnh tạo tập hợp ảnh lọc mây, nhưng phía trước median reducer). Xem code hoàn chỉnh phía dưới đây
// Get a collection. var L8_collection = ee.ImageCollection('LANDSAT/LC8_L1T_TOA'); // Filter to scenes that intersect your boundary var L8_StudyArea = L8_collection.filterBounds(StudyArea); // Filter to scenes for a given time period var L8_SA_2015 = L8_StudyArea.filterDate('2015-01-01', '2015-12-31'); print(L8_SA_2015, 'L8_SA_2015'); var cloud_thresh = 40; var cloudfunction = function(image){ //use add the cloud likelihood band to the image var CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image); //isolate the cloud likelihood band var quality = CloudScore.select('cloud'); //get pixels above the threshold var cloud01 = quality.gt(cloud_thresh); //create a mask from high likelihood pixels var cloudmask = image.mask().and(cloud01.not()); //mask those pixels from the image return image.mask(cloudmask); }; //reduce to median value per pixel var median_L8_2015 = L8_SA_2015.median(); print(median_L8_2015, 'median_L8_2015'); //add layers Map.addLayer(median_L8_2015, { min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'median_L8_2015 with clouds'); Map.centerObject(StudyArea, 7);
5. Bây giờ thêm một lệnh giúp đưa kết quả thực hiện với toàn bộ tập ảnh lên cửa sổ xuất kết quả bản đồ. Sau đó đưa tập ảnh với mây được lọc lên cửa sổ hiển thị. Xem ví dụ về lệnh map dưới đây
var L8_SA_2015NoClouds = L8_SA_2015.map(cloudfunction); Map.addLayer(ee.Image(L8_SA_2015NoClouds.first()), {min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'first image no clouds'); Map.centerObject(StudyArea, 7);
6. Thay đổi lệnh median reducer để chạy trên tập ảnh L8_SA_2015NoClouds image mà bạn vừa tạo. Xem ví dụ các code dưới đây.
//reduce to median value per pixel var median_L8_2015 = L8_SA_2015NoClouds.median(); print(median_L8_2015, 'median_L8_2015'); //add layers Map.addLayer(median_L8_2015, {min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'median composite of cloud free images');