Earth Engine में ऐरे, संख्याओं की सूचियों और सूचियों की सूचियों से बनाए जाते हैं. नेस्ट करने की डिग्री से, डाइमेंशन की संख्या तय होती है. आसान और काम के उदाहरण के साथ शुरू करने के लिए, Landsat 8 टैसल कैप (टीसी) के गुणांकों से बनाए गए Array
का यह उदाहरण देखें (Baig et al., 2014):
कोड एडिटर (JavaScript)
// Create an Array of Tasseled Cap coefficients. var coefficients = ee.Array([ [0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872], [-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608], [0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559], [-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773], [-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085], [0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252], ]);
import ee import geemap.core as geemap
Colab (Python)
# Create an Array of Tasseled Cap coefficients. coefficients = ee.Array([ [0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872], [-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608], [0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559], [-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773], [-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085], [0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252], ])
length()
का इस्तेमाल करके पुष्टि करें कि यह 6x6, 2-D ऐरे है. इससे हर ऐक्सिस की लंबाई दिखेगी:
कोड एडिटर (JavaScript)
// Print the dimensions. print(coefficients.length()); // [6,6]
import ee import geemap.core as geemap
Colab (Python)
# Print the dimensions. display(coefficients.length()) # [6,6]
नीचे दी गई टेबल में, 0-ऐक्सिस और 1-ऐक्सिस के साथ मैट्रिक एंट्री के क्रम को दिखाया गया है:
एक ऐक्सिस -> | |||||||
---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | ||
0 | 0.3029 | 0.2786 | 0.4733 | 0.5599 | 0.508 | 0.1872 | |
1 | -0.2941 | -0.243 | -0.5424 | 0.7276 | 0.0713 | -0.1608 | |
0-ऐक्सिस | 2 | 0.1511 | 0.1973 | 0.3283 | 0.3407 | -0.7117 | -0.4559 |
3 | -0.8239 | 0.0849 | 0.4396 | -0.058 | 0.2013 | -0.2773 | |
4 | -0.3294 | 0.0557 | 0.1056 | 0.1855 | -0.4349 | 0.8085 | |
5 | 0.1079 | -0.9023 | 0.4119 | 0.0575 | -0.0259 | 0.0252 |
टेबल की बाईं ओर मौजूद इंडेक्स, 0-ऐक्सिस के साथ पोज़िशन दिखाते हैं. 0-ऐक्सिस पर मौजूद हर सूची में, n-वां एलिमेंट, 1-ऐक्सिस पर n-वें क्रम में होता है. उदाहरण के लिए, ऐरे के निर्देशांक [3,1] पर मौजूद वैल्यू 0.0849 है. मान लें कि 'ग्रीननेस', आपकी दिलचस्पी का
टीसी कॉम्पोनेंट है. slice()
का इस्तेमाल करके, हरियाली की सब-मैट्रिक्स देखी जा सकती है:
कोड एडिटर (JavaScript)
// Get the 1x6 greenness slice, display it. var greenness = coefficients.slice({axis: 0, start: 1, end: 2, step: 1}); print(greenness);
import ee import geemap.core as geemap
Colab (Python)
# Get the 1x6 greenness slice, display it. greenness = coefficients.slice(axis=0, start=1, end=2, step=1) display(greenness)
हरियाली का 2-D मैट्रिक कुछ ऐसा दिखेगा:
[[-0.2941,-0.243,-0.5424,0.7276,0.0713,-0.1608]]
ध्यान दें कि slice()
के start
और end
पैरामीटर, टेबल में दिखाए गए 0-ऐक्सिस इंडेक्स से मेल खाते हैं. start
में सभी वैल्यू शामिल होती हैं और end
में सिर्फ़ वैल्यू शामिल होती हैं.
अरे वाली इमेज
हरियाली वाली इमेज पाने के लिए, लैंडसैट 8 इमेज के बैंड को हरियाली वाले मैट्रिक्स से गुणा करें. ऐसा करने के लिए, सबसे पहले मल्टी-बैंड Landsat इमेज को एक
“ऐरे इमेज” में बदलें. इसमें हर पिक्सल, बैंड वैल्यू का Array
होता है. उदाहरण के लिए:
कोड एडिटर (JavaScript)
// Load a Landsat 8 image, select the bands of interest. var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318') .select(['B2', 'B3', 'B4', 'B5', 'B6', 'B7']); // Make an Array Image, with a 1-D Array per pixel. var arrayImage1D = image.toArray(); // Make an Array Image with a 2-D Array per pixel, 6x1. var arrayImage2D = arrayImage1D.toArray(1);
import ee import geemap.core as geemap
Colab (Python)
# Load a Landsat 8 image, select the bands of interest. image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318').select( ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'] ) # Make an Array Image, with a 1-D Array per pixel. array_image_1d = image.toArray() # Make an Array Image with a 2-D Array per pixel, 6x1. array_image_2d = array_image_1d.toArray(1)
इस उदाहरण में, ध्यान दें कि toArray()
, image
को एक ऐरे इमेज में बदल देता है. इसमें हर पिक्सल एक-डाइमेंशन वाला वेक्टर होता है. इसकी एंट्री, image
के बैंड में मौजूद उसी पोज़िशन पर मौजूद छह वैल्यू से मेल खाती हैं. इस तरह से बनाई गई 1-D वैक्टर की ऐरे इमेज में, 2-D आकार का कोई कॉन्सेप्ट नहीं होता. मैट्रिक्स गुणन जैसे सिर्फ़ 2-D
ऑपरेशन करने के लिए, toArray(1)
की मदद से इसे हर पिक्सल इमेज के 2-D ऐरे में बदलें. 2-D ऐरे इमेज के हर पिक्सल में, बैंड वैल्यू का 6x1 मैट्रिक्स होता है. इसे समझने के लिए, खिलौने के इस उदाहरण पर ध्यान दें:
कोड एडिटर (JavaScript)
var array1D = ee.Array([1, 2, 3]); // [1,2,3] var array2D = ee.Array.cat([array1D], 1); // [[1],[2],[3]]
import ee import geemap.core as geemap
Colab (Python)
array_1d = ee.Array([1, 2, 3]) # [1,2,3] array_2d = ee.Array.cat([array_1d], 1) # [[1],[2],[3]]
ध्यान दें कि array1D
वेक्टर, 0-ऐक्सिस के साथ अलग-अलग होता है. array2D
मैट्रिक भी ऐसा करती है, लेकिन इसमें एक अतिरिक्त डाइमेंशन होता है. ऐरे इमेज पर toArray(1)
को कॉल करना, हर पिक्सल पर cat(bandVector, 1)
को कॉल करने जैसा है. 2-D ऐरे इमेज का इस्तेमाल करके, उस इमेज से बाईं ओर गुणा करें जिसमें हर पिक्सल में, हरियाली के गुणांक का 2-D मैट्रिक होता है:
कोड एडिटर (JavaScript)
// Do a matrix multiplication: 1x6 times 6x1. // Cast the greenness Array to an Image prior to multiplication. var greennessArrayImage = ee.Image(greenness).matrixMultiply(arrayImage2D);
import ee import geemap.core as geemap
Colab (Python)
# Do a matrix multiplication: 1x6 times 6x1. # Cast the greenness Array to an Image prior to multiplication. greenness_array_image = ee.Image(greenness).matrixMultiply(array_image_2d)
इसका नतीजा एक नई ऐरे इमेज होती है, जिसमें हर पिक्सल 1x1 मैट्रिक होता है. यह मैट्रिक, 1x6 ग्रीननेस मैट्रिक (बाईं ओर) और 6x1 बैंड मैट्रिक (दाईं ओर) को गुणा करने से बनती है. डिसप्ले के लिए, arrayGet()
की मदद से सामान्य, एक-बैंड इमेज में बदलें:
कोड एडिटर (JavaScript)
// Get the result from the 1x1 array in each pixel of the 2-D array image. var greennessImage = greennessArrayImage.arrayGet([0, 0]); // Display the input imagery with the greenness result. Map.setCenter(-122.3, 37.562, 10); Map.addLayer(image, {bands: ['B5', 'B4', 'B3'], min: 0, max: 0.5}, 'image'); Map.addLayer(greennessImage, {min: -0.1, max: 0.13}, 'greenness');
import ee import geemap.core as geemap
Colab (Python)
# Get the result from the 1x1 array in each pixel of the 2-D array image. greenness_image = greenness_array_image.arrayGet([0, 0]) # Display the input imagery with the greenness result. m = geemap.Map() m.set_center(-122.3, 37.562, 10) m.add_layer(image, {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5}, 'image') m.add_layer(greenness_image, {'min': -0.1, 'max': 0.13}, 'greenness') m
यहां एक पूरा उदाहरण दिया गया है, जिसमें एक साथ कई टैसल वाली टोपी के कॉम्पोनेंट का हिसाब लगाने और नतीजा दिखाने के लिए, पूरे कोएफ़िशिएंट कलेक्शन का इस्तेमाल किया गया है:
कोड एडिटर (JavaScript)
// Define an Array of Tasseled Cap coefficients. var coefficients = ee.Array([ [0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872], [-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608], [0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559], [-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773], [-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085], [0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252], ]); // Load a Landsat 8 image, select the bands of interest. var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318') .select(['B2', 'B3', 'B4', 'B5', 'B6', 'B7']); // Make an Array Image, with a 1-D Array per pixel. var arrayImage1D = image.toArray(); // Make an Array Image with a 2-D Array per pixel, 6x1. var arrayImage2D = arrayImage1D.toArray(1); // Do a matrix multiplication: 6x6 times 6x1. var componentsImage = ee.Image(coefficients) .matrixMultiply(arrayImage2D) // Get rid of the extra dimensions. .arrayProject([0]) .arrayFlatten( [['brightness', 'greenness', 'wetness', 'fourth', 'fifth', 'sixth']]); // Display the first three bands of the result and the input imagery. var vizParams = { bands: ['brightness', 'greenness', 'wetness'], min: -0.1, max: [0.5, 0.1, 0.1] }; Map.setCenter(-122.3, 37.562, 10); Map.addLayer(image, {bands: ['B5', 'B4', 'B3'], min: 0, max: 0.5}, 'image'); Map.addLayer(componentsImage, vizParams, 'components');
import ee import geemap.core as geemap
Colab (Python)
# Define an Array of Tasseled Cap coefficients. coefficients = ee.Array([ [0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872], [-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608], [0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559], [-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773], [-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085], [0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252], ]) # Load a Landsat 8 image, select the bands of interest. image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318').select( ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'] ) # Make an Array Image, with a 1-D Array per pixel. array_image_1d = image.toArray() # Make an Array Image with a 2-D Array per pixel, 6x1. array_image_2d = array_image_1d.toArray(1) # Do a matrix multiplication: 6x6 times 6x1. components_image = ( ee.Image(coefficients) .matrixMultiply(array_image_2d) # Get rid of the extra dimensions. .arrayProject([0]) .arrayFlatten( [['brightness', 'greenness', 'wetness', 'fourth', 'fifth', 'sixth']] ) ) # Display the first three bands of the result and the input imagery. viz_params = { 'bands': ['brightness', 'greenness', 'wetness'], 'min': -0.1, 'max': [0.5, 0.1, 0.1], } m = geemap.Map() m.set_center(-122.3, 37.562, 10) m.add_layer(image, {'bands': ['B5', 'B4', 'B3'], 'min': 0, 'max': 0.5}, 'image') m.add_layer(components_image, viz_params, 'components') m
ध्यान दें कि ऐरे इमेज से बैंड पाने के लिए, पहले project()
की मदद से अतिरिक्त डाइमेंशन हटाएं. इसके बाद, arrayFlatten()
की मदद से उसे फिर से सामान्य इमेज में बदलें. आउटपुट कुछ ऐसा दिखेगा:
