রিলেশনাল, কন্ডিশনাল ও বুলিয়ান অপারেশন

ee.Image অবজেক্টে সিদ্ধান্ত-গ্রহণকারী এক্সপ্রেশন তৈরি করার জন্য রিলেশনাল, কন্ডিশনাল ও বুলিয়ান পদ্ধতির সেট থাকে। এইসব পদ্ধতির ফলাফল মাস্কিং, ক্লাসিফায়েড ম্যাপ তৈরি করা ও ভ্যালু পুনরায় অ্যাসাইন করার মাধ্যমে নির্দিষ্ট পিক্সেল বা অঞ্চলে বিশ্লেষণ সীমিত করার জন্য উপযোগী।

রিলেশনাল ও বুলিয়ান অপারেটর

রিলেশনাল পদ্ধতির মধ্যে অন্তর্ভুক্ত হল:

eq(), gt(), gte(), lt() এবং lte()

বুলিয়ান পদ্ধতির মধ্যে এগুলি অন্তর্ভুক্ত:

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

and(),or() এবং not()

Colab (Python)

And(),Or() এবং Not()

ছবির মধ্যে প্রতি-পিক্সেল তুলনা করতে, রিলেশনাল অপারেটর ব্যবহার করুন। কোনও ছবিতে শহুরে এলাকা এক্সট্র্যাক্ট করতে, এই উদাহরণে স্পেকট্রাল ইন্ডেক্স থ্রেশহোল্ড করতে রিলেশনাল অপারেটর ব্যবহার করা হয়, and অপারেটরের সাথে থ্রেশহোল্ড একত্রিত করে:

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

// Load a Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');

// Create NDVI and NDWI spectral indices.
var ndvi = image.normalizedDifference(['B5', 'B4']);
var ndwi = image.normalizedDifference(['B3', 'B5']);

// Create a binary layer using logical operations.
var bare = ndvi.lt(0.2).and(ndwi.lt(0));

// Mask and display the binary layer.
Map.setCenter(-122.3578, 37.7726, 12);
Map.setOptions('satellite');
Map.addLayer(bare.selfMask(), {}, 'bare');

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# Load a Landsat 8 image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')

# Create NDVI and NDWI spectral indices.
ndvi = image.normalizedDifference(['B5', 'B4'])
ndwi = image.normalizedDifference(['B3', 'B5'])

# Create a binary layer using logical operations.
bare = ndvi.lt(0.2).And(ndwi.lt(0))

# Define a map centered on San Francisco Bay.
map_bare = geemap.Map(center=[37.7726, -122.3578], zoom=12)

# Add the masked image layer to the map and display it.
map_bare.add_layer(bare.selfMask(), None, 'bare')
display(map_bare)

এই উদাহরণে যেমন দেখানো হয়েছে, রিলেশনাল ও বুলিয়ান অপারেটরের আউটপুট হয় সত্য (১) অথবা মিথ্যা (০) হয়। 0 মাস্ক করতে, আপনি selfMask() ব্যবহার করে ফলাফল হিসেবে পাওয়া বাইনারি ছবিকে মাস্ক করতে পারবেন।

relational_sf
Landsat 8 থেকে কম NDVI এবং কম NDWI (সাদা), সান ফ্রান্সিসকো, ক্যালিফোর্নিয়া, মার্কিন যুক্তরাষ্ট্র।

রিলেশনাল ও বুলিয়ান অপারেটর থেকে পাওয়া বাইনারি ছবি ম্যাথমেটিক্যাল অপারেটরের সাথে ব্যবহার করা যেতে পারে। এই উদাহরণটি রিলেশনাল অপারেটর এবং add() ব্যবহার করে রাতের আলোয় শহুরে অঞ্চলের ছবি তৈরি করে:

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

// Load a 2012 nightlights image.
var nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012');
var lights = nl2012.select('stable_lights');

// Define arbitrary thresholds on the 6-bit stable lights band.
var zones = lights.gt(30).add(lights.gt(55)).add(lights.gt(62));

// Display the thresholded image as three distinct zones near Paris.
var palette = ['000000', '0000FF', '00FF00', 'FF0000'];
Map.setCenter(2.373, 48.8683, 8);
Map.addLayer(zones, {min: 0, max: 3, palette: palette}, 'development zones');

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# Load a 2012 nightlights image.
nl_2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012')
lights = nl_2012.select('stable_lights')

# Define arbitrary thresholds on the 6-bit stable lights band.
zones = lights.gt(30).add(lights.gt(55)).add(lights.gt(62))

# Define a map centered on Paris, France.
map_zones = geemap.Map(center=[48.8683, 2.373], zoom=8)

# Display the thresholded image as three distinct zones near Paris.
palette = ['000000', '0000FF', '00FF00', 'FF0000']
map_zones.add_layer(
    zones, {'min': 0, 'max': 3, 'palette': palette}, 'development zones'
)
display(map_zones)

কন্ডিশনাল অপারেটর

মনে রাখবেন যে আগের উদাহরণের কোডটি expression() দ্বারা প্রয়োগ করা টারনারি অপারেটর ব্যবহার করার সমতুল্য:

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

// Create zones using an expression, display.
var zonesExp = nl2012.expression(
    "(b('stable_lights') > 62) ? 3" +
      ": (b('stable_lights') > 55) ? 2" +
        ": (b('stable_lights') > 30) ? 1" +
          ": 0"
);
Map.addLayer(zonesExp,
             {min: 0, max: 3, palette: palette},
             'development zones (ternary)');

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# Create zones using an expression, display.
zones_exp = nl_2012.expression(
    "(b('stable_lights') > 62) ? 3 "
    ": (b('stable_lights') > 55) ? 2 "
    ": (b('stable_lights') > 30) ? 1 "
    ': 0'
)

# Define a map centered on Paris, France.
map_zones_exp = geemap.Map(center=[48.8683, 2.373], zoom=8)

# Add the image layer to the map and display it.
map_zones_exp.add_layer(
    zones_exp, {'min': 0, 'max': 3, 'palette': palette}, 'zones exp'
)
display(map_zones_exp)

লক্ষ্য করুন যে আগের এক্সপ্রেশনের উদাহরণে, আগ্রহের ব্যান্ডটি ভেরিয়েবল নামের অভিধানের পরিবর্তে b() ফাংশন ব্যবহার করে রেফারেন্স করা হয়েছে। এই পৃষ্ঠা থেকে ছবির এক্সপ্রেশন সম্পর্কে আরও জানুন। গাণিতিক অপারেটর বা এক্সপ্রেশন, যে কোনও একটি ব্যবহার করলে একই ফলাফল পাওয়া যাবে।

conditional_paris
ফ্রান্সের প্যারিসের ২০১২ সালের নাইটলাইট ইমেজের ইচ্ছামতো জোন।

ছবিতে শর্তসাপেক্ষ অপারেশন প্রয়োগ করার আরেকটি উপায় হল where() অপারেটর ব্যবহার করা। মাস্ক করা পিক্সেল অন্য কোনও ডেটা দিয়ে পরিবর্তন করার প্রয়োজনীয়তা বিবেচনা করুন। নিচের উদাহরণে, where() ব্যবহার করে মেঘমুক্ত ছবি থেকে পিক্সেল নিয়ে মেঘাচ্ছন্ন পিক্সেল প্রতিস্থাপন করা হয়েছে:

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

// Load a cloudy Sentinel-2 image.
var image = ee.Image(
  'COPERNICUS/S2_SR_HARMONIZED/20210114T185729_20210114T185730_T10SEG');
Map.addLayer(image,
             {bands: ['B4', 'B3', 'B2'], min: 0, max: 2000},
             'original image');

// Load another image to replace the cloudy pixels.
var replacement = ee.Image(
  'COPERNICUS/S2_SR_HARMONIZED/20210109T185751_20210109T185931_T10SEG');

// Set cloudy pixels (greater than 5% probability) to the other image.
var replaced = image.where(image.select('MSK_CLDPRB').gt(5), replacement);

// Display the result.
Map.setCenter(-122.3769, 37.7349, 11);
Map.addLayer(replaced,
             {bands: ['B4', 'B3', 'B2'], min: 0, max: 2000},
             'clouds replaced');

Python সেট-আপ

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

import ee
import geemap.core as geemap

Colab (Python)

# Load a cloudy Sentinel-2 image.
image = ee.Image(
    'COPERNICUS/S2_SR_HARMONIZED/20210114T185729_20210114T185730_T10SEG'
)

# Load another image to replace the cloudy pixels.
replacement = ee.Image(
    'COPERNICUS/S2_SR_HARMONIZED/20210109T185751_20210109T185931_T10SEG'
)

# Set cloudy pixels (greater than 5% probability) to the other image.
replaced = image.where(image.select('MSK_CLDPRB').gt(5), replacement)

# Define a map centered on San Francisco Bay.
map_replaced = geemap.Map(center=[37.7349, -122.3769], zoom=11)

# Display the images on a map.
vis_params = {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 2000}
map_replaced.add_layer(image, vis_params, 'original image')
map_replaced.add_layer(replaced, vis_params, 'clouds replaced')
display(map_replaced)