ঘোষণা :
15 এপ্রিল, 2025 এর আগে আর্থ ইঞ্জিন ব্যবহার করার জন্য নিবন্ধিত সমস্ত অবাণিজ্যিক প্রকল্পগুলিকে অবশ্যই আর্থ ইঞ্জিন অ্যাক্সেস বজায় রাখার জন্য
অ-বাণিজ্যিক যোগ্যতা যাচাই করতে হবে।
অ্যারে সাজানো এবং হ্রাস করা
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
অ্যারে বাছাই কাস্টম মানের মোজাইক পাওয়ার জন্য দরকারী যা একটি ভিন্ন ব্যান্ডের মান অনুযায়ী ইমেজ ব্যান্ডের একটি উপসেট হ্রাস করে। নিম্নলিখিত উদাহরণটি এনডিভিআই দ্বারা বাছাই করে, তারপর সর্বোচ্চ এনডিভিআই মান সহ সংগ্রহে পর্যবেক্ষণের একটি উপসেটের গড় পায়:
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Define a function that scales and masks Landsat 8 surface reflectance images
// and adds an NDVI band.
function prepSrL8(image) {
// Develop masks for unwanted pixels (fill, cloud, cloud shadow).
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
// Apply the scaling factors to the appropriate bands.
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
// Calculate NDVI.
var ndvi = opticalBands.normalizedDifference(['SR_B5', 'SR_B4'])
.rename('NDVI');
// Replace original bands with scaled bands, add NDVI band, and apply masks.
return image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true)
.addBands(ndvi)
.updateMask(qaMask)
.updateMask(saturationMask);
}
// Define an arbitrary region of interest as a point.
var roi = ee.Geometry.Point(-122.26032, 37.87187);
// Load a Landsat 8 surface reflectance collection.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
// Filter to get only imagery at a point of interest.
.filterBounds(roi)
// Filter to get only six months of data.
.filterDate('2021-01-01', '2021-07-01')
// Prepare images by mapping the prepSrL8 function over the collection.
.map(prepSrL8)
// Select the bands of interest to avoid taking up unneeded memory.
.select('SR_B.|NDVI');
// Convert the collection to an array.
var array = collection.toArray();
// Label of the axes.
var imageAxis = 0;
var bandAxis = 1;
// Get the NDVI slice and the bands of interest.
var bandNames = collection.first().bandNames();
var bands = array.arraySlice(bandAxis, 0, bandNames.length());
var ndvi = array.arraySlice(bandAxis, -1);
// Sort by descending NDVI.
var sorted = bands.arraySort(ndvi.multiply(-1));
// Get the highest 20% NDVI observations per pixel.
var numImages = sorted.arrayLength(imageAxis).multiply(0.2).int();
var highestNdvi = sorted.arraySlice(imageAxis, 0, numImages);
// Get the mean of the highest 20% NDVI observations by reducing
// along the image axis.
var mean = highestNdvi.arrayReduce({
reducer: ee.Reducer.mean(),
axes: [imageAxis]
});
// Turn the reduced array image into a multi-band image for display.
var meanImage = mean.arrayProject([bandAxis]).arrayFlatten([bandNames]);
Map.centerObject(roi, 12);
Map.addLayer(meanImage, {bands: ['SR_B6', 'SR_B5', 'SR_B4'], min: 0, max: 0.4});
পাইথন সেটআপ
পাইথন এপিআই এবং ইন্টারেক্টিভ ডেভেলপমেন্টের জন্য geemap
ব্যবহার করার জন্য পাইথন এনভায়রনমেন্ট পৃষ্ঠাটি দেখুন।
import ee
import geemap.core as geemap
Colab (পাইথন)
# Define a function that scales and masks Landsat 8 surface reflectance images
# and adds an NDVI band.
def prep_sr_l8(image):
# Develop masks for unwanted pixels (fill, cloud, cloud shadow).
qa_mask = image.select('QA_PIXEL').bitwiseAnd(int('11111', 2)).eq(0)
saturation_mask = image.select('QA_RADSAT').eq(0)
# Apply the scaling factors to the appropriate bands.
optical_bands = image.select('SR_B.').multiply(0.0000275).add(-0.2)
thermal_bands = image.select('ST_B.*').multiply(0.00341802).add(149.0)
# Calculate NDVI.
ndvi = optical_bands.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI')
# Replace the original bands with the scaled ones and apply the masks.
return (
image.addBands(optical_bands, None, True)
.addBands(thermal_bands, None, True)
.addBands(ndvi)
.updateMask(qa_mask)
.updateMask(saturation_mask)
)
# Define an arbitrary region of interest as a point.
roi = ee.Geometry.Point(-122.26032, 37.87187)
# Load a Landsat 8 surface reflectance collection.
collection = (
ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
# Filter to get only imagery at a point of interest.
.filterBounds(roi)
# Filter to get only six months of data.
.filterDate('2021-01-01', '2021-07-01')
# Prepare images by mapping the prep_sr_l8 function over the collection.
.map(prep_sr_l8)
# Select the bands of interest to avoid taking up unneeded memory.
.select('SR_B.|NDVI')
)
# Convert the collection to an array.
array = collection.toArray()
# Label of the axes.
image_axis = 0
band_axis = 1
# Get the NDVI slice and the bands of interest.
band_names = collection.first().bandNames()
bands = array.arraySlice(band_axis, 0, band_names.length())
ndvi = array.arraySlice(band_axis, -1)
# Sort by descending NDVI.
sorted = bands.arraySort(ndvi.multiply(-1))
# Get the highest 20% NDVI observations per pixel.
num_images = sorted.arrayLength(image_axis).multiply(0.2).int()
highest_ndvi = sorted.arraySlice(image_axis, 0, num_images)
# Get the mean of the highest 20% NDVI observations by reducing
# along the image axis.
mean = highest_ndvi.arrayReduce(reducer=ee.Reducer.mean(), axes=[image_axis])
# Turn the reduced array image into a multi-band image for display.
mean_image = mean.arrayProject([band_axis]).arrayFlatten([band_names])
m = geemap.Map()
m.center_object(roi, 12)
m.add_layer(
mean_image, {'bands': ['SR_B6', 'SR_B5', 'SR_B4'], 'min': 0, 'max': 0.4}
)
m
লিনিয়ার মডেলিং উদাহরণের মতো, ব্যান্ড অক্ষ বরাবর arraySlice()
ব্যবহার করে সাজানোর সূচক (NDVI) থেকে আগ্রহের ব্যান্ডগুলিকে আলাদা করুন। তারপর arraySort()
ব্যবহার করে সর্ট ইনডেক্স দ্বারা আগ্রহের ব্যান্ডগুলি সাজান। পিক্সেলগুলিকে NDVI ক্রমানুসারে সাজানোর পরে, সর্বোচ্চ NDVI পিক্সেলের 20% পেতে imageAxis
বরাবর arraySlice()
ব্যবহার করুন। সবশেষে, সর্বোচ্চ NDVI পিক্সেলের গড় পেতে একটি গড় রিডুসার সহ imageAxis
বরাবর arrayReduce()
প্রয়োগ করুন। চূড়ান্ত ধাপটি প্রদর্শনের জন্য অ্যারে চিত্রটিকে একটি মাল্টি-ব্যান্ড ছবিতে রূপান্তর করে।
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-24 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-24 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eThis example demonstrates using array sorting to calculate the mean of the top 20% of Landsat 8 images with the highest NDVI values within a specific region and timeframe.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves preparing the Landsat 8 collection by scaling, masking, and adding an NDVI band.\u003c/p\u003e\n"],["\u003cp\u003eImage pixels are sorted based on NDVI values using \u003ccode\u003earraySort()\u003c/code\u003e, allowing selection of the highest values using \u003ccode\u003earraySlice()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003earrayReduce()\u003c/code\u003e function is applied to calculate the mean of the selected pixels, resulting in a composite image representing the desired values.\u003c/p\u003e\n"],["\u003cp\u003eThe final output is a multi-band image displaying the mean values for the selected bands (SR_B6, SR_B5, SR_B4) of the highest NDVI pixels.\u003c/p\u003e\n"]]],["The process involves sorting Landsat 8 images by NDVI to create a custom mosaic. First, a function prepares images by scaling, masking, and calculating NDVI. Then, a collection of images is filtered by location and date range, transformed into an array, and sorted by descending NDVI values. The top 20% of NDVI observations are isolated. Finally, the mean of these top observations is calculated and transformed into a multi-band image for display.\n"],null,["# Array Sorting and Reducing\n\nArray sorting is useful for obtaining custom quality mosaics which involve reducing a\nsubset of image bands according to the values in a different band. The following example\nsorts by NDVI, then gets the mean of a subset of observations in the collection with the\nhighest NDVI values:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Define a function that scales and masks Landsat 8 surface reflectance images\n// and adds an NDVI band.\nfunction prepSrL8(image) {\n // Develop masks for unwanted pixels (fill, cloud, cloud shadow).\n var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);\n var saturationMask = image.select('QA_RADSAT').eq(0);\n\n // Apply the scaling factors to the appropriate bands.\n var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);\n var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);\n\n // Calculate NDVI.\n var ndvi = opticalBands.normalizedDifference(['SR_B5', 'SR_B4'])\n .rename('NDVI');\n\n // Replace original bands with scaled bands, add NDVI band, and apply masks.\n return image.addBands(opticalBands, null, true)\n .addBands(thermalBands, null, true)\n .addBands(ndvi)\n .updateMask(qaMask)\n .updateMask(saturationMask);\n}\n\n// Define an arbitrary region of interest as a point.\nvar roi = ee.Geometry.Point(-122.26032, 37.87187);\n\n// Load a Landsat 8 surface reflectance collection.\nvar collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')\n // Filter to get only imagery at a point of interest.\n .filterBounds(roi)\n // Filter to get only six months of data.\n .filterDate('2021-01-01', '2021-07-01')\n // Prepare images by mapping the prepSrL8 function over the collection.\n .map(prepSrL8)\n // Select the bands of interest to avoid taking up unneeded memory.\n .select('SR_B.|NDVI');\n\n// Convert the collection to an array.\nvar array = collection.toArray();\n\n// Label of the axes.\nvar imageAxis = 0;\nvar bandAxis = 1;\n\n// Get the NDVI slice and the bands of interest.\nvar bandNames = collection.first().bandNames();\nvar bands = array.arraySlice(bandAxis, 0, bandNames.length());\nvar ndvi = array.arraySlice(bandAxis, -1);\n\n// Sort by descending NDVI.\nvar sorted = bands.arraySort(ndvi.multiply(-1));\n\n// Get the highest 20% NDVI observations per pixel.\nvar numImages = sorted.arrayLength(imageAxis).multiply(0.2).int();\nvar highestNdvi = sorted.arraySlice(imageAxis, 0, numImages);\n\n// Get the mean of the highest 20% NDVI observations by reducing\n// along the image axis.\nvar mean = highestNdvi.arrayReduce({\n reducer: ee.Reducer.mean(),\n axes: [imageAxis]\n});\n\n// Turn the reduced array image into a multi-band image for display.\nvar meanImage = mean.arrayProject([bandAxis]).arrayFlatten([bandNames]);\nMap.centerObject(roi, 12);\nMap.addLayer(meanImage, {bands: ['SR_B6', 'SR_B5', 'SR_B4'], min: 0, max: 0.4});\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Define a function that scales and masks Landsat 8 surface reflectance images\n# and adds an NDVI band.\ndef prep_sr_l8(image):\n # Develop masks for unwanted pixels (fill, cloud, cloud shadow).\n qa_mask = image.select('QA_PIXEL').bitwiseAnd(int('11111', 2)).eq(0)\n saturation_mask = image.select('QA_RADSAT').eq(0)\n\n # Apply the scaling factors to the appropriate bands.\n optical_bands = image.select('SR_B.').multiply(0.0000275).add(-0.2)\n thermal_bands = image.select('ST_B.*').multiply(0.00341802).add(149.0)\n\n # Calculate NDVI.\n ndvi = optical_bands.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI')\n\n # Replace the original bands with the scaled ones and apply the masks.\n return (\n image.addBands(optical_bands, None, True)\n .addBands(thermal_bands, None, True)\n .addBands(ndvi)\n .updateMask(qa_mask)\n .updateMask(saturation_mask)\n )\n\n\n# Define an arbitrary region of interest as a point.\nroi = ee.Geometry.Point(-122.26032, 37.87187)\n\n# Load a Landsat 8 surface reflectance collection.\ncollection = (\n ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')\n # Filter to get only imagery at a point of interest.\n .filterBounds(roi)\n # Filter to get only six months of data.\n .filterDate('2021-01-01', '2021-07-01')\n # Prepare images by mapping the prep_sr_l8 function over the collection.\n .map(prep_sr_l8)\n # Select the bands of interest to avoid taking up unneeded memory.\n .select('SR_B.|NDVI')\n)\n\n# Convert the collection to an array.\narray = collection.toArray()\n\n# Label of the axes.\nimage_axis = 0\nband_axis = 1\n\n# Get the NDVI slice and the bands of interest.\nband_names = collection.first().bandNames()\nbands = array.arraySlice(band_axis, 0, band_names.length())\nndvi = array.arraySlice(band_axis, -1)\n\n# Sort by descending NDVI.\nsorted = bands.arraySort(ndvi.multiply(-1))\n\n# Get the highest 20% NDVI observations per pixel.\nnum_images = sorted.arrayLength(image_axis).multiply(0.2).int()\nhighest_ndvi = sorted.arraySlice(image_axis, 0, num_images)\n\n# Get the mean of the highest 20% NDVI observations by reducing\n# along the image axis.\nmean = highest_ndvi.arrayReduce(reducer=ee.Reducer.mean(), axes=[image_axis])\n\n# Turn the reduced array image into a multi-band image for display.\nmean_image = mean.arrayProject([band_axis]).arrayFlatten([band_names])\nm = geemap.Map()\nm.center_object(roi, 12)\nm.add_layer(\n mean_image, {'bands': ['SR_B6', 'SR_B5', 'SR_B4'], 'min': 0, 'max': 0.4}\n)\nm\n```\n\nAs in the linear modeling example, separate the bands of interest from the sort index (NDVI)\nusing `arraySlice()` along the band axis. Then sort the bands of interest by\nsort index using `arraySort()`. After the pixels have been sorted by\ndescending NDVI, use `arraySlice()` along the `imageAxis` to\nget 20% of the highest NDVI pixels. Lastly, apply `arrayReduce()` along the\n`imageAxis` with a mean reducer to get the mean of the highest NDVI\npixels. The final step converts the array image back to a multi-band image for display."]]