ee.Image.expression

একটি চিত্রের একটি গাণিতিক অভিব্যক্তি মূল্যায়ন করে, সম্ভবত অতিরিক্ত চিত্রগুলি জড়িত।

প্রাথমিক ইনপুট চিত্রের ব্যান্ডগুলি বিল্ট-ইন ফাংশন b(), b(0) বা b('band_name') হিসাবে উপলব্ধ।

অভিব্যক্তিতে ভেরিয়েবলগুলিকে অতিরিক্ত চিত্র পরামিতি হিসাবে ব্যাখ্যা করা হয় যা অবশ্যই opt_map এ সরবরাহ করতে হবে। এই ধরনের প্রতিটি ছবির ব্যান্ডগুলিকে image.band_name বা image[0] এর মত অ্যাক্সেস করা যেতে পারে।

b() এবং image[] উভয়ই একাধিক আর্গুমেন্টকে অনুমতি দেয়, একাধিক ব্যান্ড নির্দিষ্ট করতে, যেমন b(1, 'name', 3)। কোন আর্গুমেন্ট ছাড়া b() কল করা, বা নিজেই একটি ভেরিয়েবল ব্যবহার করে, ইমেজের সমস্ত ব্যান্ড রিটার্ন করে।

যদি একটি অভিব্যক্তির ফলাফল একটি একক ব্যান্ড হয়, তবে এটি '=' অপারেটর ব্যবহার করে একটি নাম বরাদ্দ করা যেতে পারে (যেমন: x = a + b)।

প্রদত্ত অভিব্যক্তি দ্বারা গণনা করা চিত্র প্রদান করে।

ব্যবহার রিটার্নস
Image. expression (expression, map ) ছবি
যুক্তি টাইপ বিস্তারিত
এই: image ছবি ইমেজ উদাহরণ.
expression স্ট্রিং মূল্যায়ন করার অভিব্যক্তি।
map অভিধান<ছবি>, ঐচ্ছিক নামের দ্বারা উপলব্ধ ইনপুট চিত্রগুলির একটি মানচিত্র৷

উদাহরণ

কোড এডিটর (জাভাস্ক্রিপ্ট)

// The following expressions calculate the normalized difference vegetation
// index (NDVI): (NIR - Red) / (NIR + Red).
// NIR is Landsat 8 L2 band 'SR_B5', the 4th band index.
// Red is Landsat 8 L2 band 'SR_B4', the 3rd band index.

// A Landsat 8 L2 surface reflectance image.
var img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508');

// Visualization parameters for NDVI.
var ndviVis = {min: 0, max: 0.5};

// Expression using image band indices.
var bandIndexExp = '(b(4) - b(3)) / (b(4) + b(3))';
var bandIndexImg = img.expression(bandIndexExp).rename('NDVI');
Map.setCenter(-122.14, 37.38, 11);
Map.addLayer(bandIndexImg, ndviVis, 'NDVI 1');

// Expression using image band names.
var bandNameExp = '(b("SR_B5") - b("SR_B4")) / (b("SR_B5") + b("SR_B4"))';
var bandNameImg = img.expression(bandNameExp).rename('NDVI');
Map.addLayer(bandNameImg, ndviVis, 'NDVI 2');

// Expression using named variables.
var namedVarsExp = '(NIR - Red) / (NIR + Red)';
var namedVarsImg = ee.Image().expression({
  expression: namedVarsExp,
  map: {
    NIR: img.select('SR_B5'),
    Red: img.select('SR_B4')
  }
}).rename('NDVI');
Map.addLayer(namedVarsImg, ndviVis, 'NDVI 3');

// Expression using named variables with image band access by dot notation.
var namedVarsDotExp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)';
var namedVarsDotImg = ee.Image().expression({
  expression: namedVarsDotExp,
  map: {ls8: img}
}).rename('NDVI');
Map.addLayer(namedVarsDotImg, ndviVis, 'NDVI 4');

// Expressions can use arithmetic operators (+ - * / % **), relational
// operators (== != < > <= >=), logical operators (&& || ! ^), the ternary
// operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math
// functions. Math functions are called by name directly, they are not accessed
// from the Math object (e.g., sqrt() instead of Math.sqrt()).
var jsMathExp = 'c = sqrt(pow(a, 2) + pow(b, 2))';
var jsMathImg = ee.Image().expression({
  expression: jsMathExp,
  map: {
    a: ee.Image(5),
    b: img.select('SR_B2')
  }
});
Map.addLayer(jsMathImg, {min: 5000, max: 20000}, 'Hypotenuse', false);

পাইথন সেটআপ

পাইথন এপিআই এবং ইন্টারেক্টিভ ডেভেলপমেন্টের জন্য geemap ব্যবহার করার জন্য পাইথন এনভায়রনমেন্ট পৃষ্ঠাটি দেখুন।

import ee
import geemap.core as geemap

Colab (পাইথন)

# The following expressions calculate the normalized difference vegetation
# index (NDVI): (NIR - Red) / (NIR + Red).
# NIR is Landsat 8 L2 band 'SR_B5', the 4th band index.
# Red is Landsat 8 L2 band 'SR_B4', the 3rd band index.

# A Landsat 8 L2 surface reflectance image.
img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508')

# Visualization parameters for NDVI.
ndvi_vis = {'min': 0, 'max': 0.5}

# Expression using image band indices.
band_index_exp = '(b(4) - b(3)) / (b(4) + b(3))'
band_index_img = img.expression(band_index_exp).rename('NDVI')
m = geemap.Map()
m.set_center(-122.14, 37.38, 11)
m.add_layer(band_index_img, ndvi_vis, 'NDVI 1')

# Expression using image band names.
band_name_exp = '(b("SR_B5") - b("SR_B4")) / (b("SR_B5") + b("SR_B4"))'
band_name_img = img.expression(band_name_exp).rename('NDVI')
m.add_layer(band_name_img, ndvi_vis, 'NDVI 2')

# Expression using named variables.
named_vars_exp = '(NIR - Red) / (NIR + Red)'
named_vars_img = (
    ee.Image()
    .expression(
        expression=named_vars_exp,
        opt_map={'NIR': img.select('SR_B5'), 'Red': img.select('SR_B4')},
    )
    .rename('NDVI')
)
m.add_layer(named_vars_img, ndvi_vis, 'NDVI 3')

# Expression using named variables with image band access by dot notation.
named_vars_dot_exp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)'
named_vars_dot_img = (
    ee.Image()
    .expression(expression=named_vars_dot_exp, opt_map={'ls8': img})
    .rename('NDVI')
)
m.add_layer(named_vars_dot_img, ndvi_vis, 'NDVI 4')

# Expressions can use arithmetic operators (+ - * / % **), relational
# operators (== != < > <= >=), logical operators (&& || ! ^), the ternary
# operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math
# functions. Math functions are called by name directly, they are not accessed
# from the Math object (e.g., sqrt() instead of Math.sqrt()).
js_math_exp = 'c = sqrt(pow(a, 2) + pow(b, 2))'
js_math_img = ee.Image().expression(
    expression=js_math_exp, opt_map={'a': ee.Image(5), 'b': img.select('SR_B2')}
)
m.add_layer(js_math_img, {'min': 5000, 'max': 20000}, 'Hypotenuse', False)
m