Springe direkt zu Inhalt

NDVI - إعداد البيانات الأساسية

الرمز هو نفسه بشكل أساسي لأي منطقة، والفرق الوحيد هو منطقة الاهتمام المحددة.

لذلك، سنحافظ على أسماء المتغيرات عامة ونحدد اختيار المنطقة في البداية.

هكذا، يمكننا ببساطة اختيار المنطقة التي نريد أن ننظر إليها وسيظل الكود يعمل.

تحضير البيانات الأساسية

لبدء تحليلنا، لابد من إنشاء مجموعة بيانات أساسية تحتوي على نطاق NDVI لكل صورة من مجموعة الصور الخاصة بنا.

يمكن بعد ذلك استخدام مجموعة الصور هذه للتصفية لأي وقت أو منطقة معينة نهتم بها.

نظرًا لأن الاختلاف الطبيعي لا يعمل إلا مع الصور، فسنحتاج إلى تطبيق NDVI على كل صورة مفردة من مجموعة الصور الخاصة بنا.

لحسن الحظ، هناك طريقة للقيام بذلك تلقائيًا عن طريق تعيين وظيفة على مجموعة الصور.

//Step 1: Access the AOI geometry
//Here, we can choose which region to look at.
//Please, remove the comments of the desired region and feel free to add any region you would like to analyse.
//By default, the code will run for the Administrative Unit of the region Homs, as processing times are shorter than for the whole country of Lebanon or Syria.

//Variant 1: Syria
//var extent_aoi = ee.FeatureCollection("FAO/GAUL/2015/level0")
//                  .filter(ee.Filter.eq('ADM0_NAME', 'Syrian Arab Republic')); //filter for entry that equals the UN country name 'Syrian Arab Rebuplic'
//print(extent_aoi, 'Extent AOI');
//Map.addLayer(extent_syria, {},'Extent AOI');
//Map.centerObject(extent_aoi, 8);

//Variant 2: Lebanon
//var extent_aoi = ee.FeatureCollection("FAO/GAUL/2015/level0")
//                  .filter(ee.Filter.eq('ADM0_NAME', 'Lebanon')); //filter for entry that equals the UN country name 'Lebanon'
//print(extent_aoi, 'Extent AOI');
//Map.addLayer(extent_aoi, {},'Extent AOI');
//Map.centerObject(extent_aoi, 8);

//Variant 3: Homs
var extent_aoi = ee.FeatureCollection("FAO/GAUL/2015/level1")
                  .filter(ee.Filter.eq('ADM1_NAME', 'Homs')); //filter for entry that equals the ADM1_NAME 'Homs'
print(extent_aoi, 'Extent AOI');
Map.addLayer(extent_aoi, {},'Extent AOI');
Map.centerObject(extent_aoi, 8);

 
 
//Step 2: Access Landsat 8 data from the day it launched until today. Filter for the desired region and less than 10% cloud cover.
var ls8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
        .filterBounds(extent_aoi)
        .filterDate('2013-02-11', '2021-06-18')
        .filter(ee.Filter.lt('CLOUD_COVER', 10));
print(ls8, 'Image Collection 2013-2021 <10% clouds'); //Use the console to look at the amount of Images accumulated

var visParams = {'min': 400,'max': [4000,3000,3000],   'bands':'B5,B4,B3'}; //bands 5, 4 and 3 are to be visualized; False Color Composite
Map.addLayer(ls8, visParams ,'Image Collection 2013-2021 <10% clouds', false);   // Visualize the ImageCollection in the Map panel and assign a name to it; Hide the layer by default, as it takes long to render

//Step 3: Write a function that allows us to map the NDVI to every Image of our of our ImageCollection. Use .rename to name the added NDVI-band 'NDVI'.
var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  return image.addBands(ndvi);
};

//Apply the function to the ImageCollection
var ls8_ndvi = ls8.map(addNDVI);
print(ls8_ndvi, 'Image Collection with NDVI')

تصفية البيانات الأساسية

تحقق من كل من وحدة التحكم ووحدات البيكسل العشوائية مع زر التعريف: يجب أن تحتوي كل صورة من مجموعتنا الآن على نطاق 13 مضافًا "NDVI”، مع قيم تتراوح من -1 إلى 1.

هذه هي مجموعة البيانات الأساسية لدينا.

يمكننا تطبيق المرشحات عليه، تمامًا كما نفعل لإنشاء مجموعة الصور الأولية الخاصة بنا.

دعنا على سبيل المثال نصفيها لبيانات NDVI لعام 2017.

var ndvi_2017 = ls8_ndvi
             .filterDate('2017-01-01', '2017-12-31')
             .select('NDVI')
print(ndvi_2017, 'NDVI 2017')
//Use the console to look at the amount of Images with NDVI-bands for your Area of Interest, 2017.

//Define specific visualization parameters for the NDVI and visualize it.
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi_2017, ndviParams, 'NDVI 2017', false);
Map.addLayer(ndvi_2017.median().clip(extent_aoi), ndviParams, 'NDVI 2017 Variant 2', false);

استخدم لوحة الشرائح الجغرافية في الزاوية اليمنى العليا من لوحة الخريطة للتبديل بين متغيري الطبقة.

ما هي الاختلافات؟

// في هذه المرحلة ، يمكنك أيضًا تعيين AOI رسم هندسي إضافيًا: ما عليك سوى اختيار الشكل الهندسي الذي يمكنك الوصول إليه وتصفية مجموعة الصوربالطريقة التي تعلمناها بالفعل!

يمكنك على سبيل المثال استخدام إما بيانات GAUL المستوى 1 / المستوى 2، أو الأشكال الهندسية الخاصة بك التي تم تحميلها إلى الملفات الخاصة بك أو رسم شكل هندسي باستخدام ادوات الرسم الهندسي في لوحة الخريطة.