TransWikia.com

Band calculation error occurred after inner join of ImageCollections in Google earth engine

Geographic Information Systems Asked by xiaoxue peng on January 10, 2021

As a newbie who was learning GEE, I had some problems in code implementation. I am using a SUE algorithm to calculate the intensity of urban heat islands. First of all, I have successfully realized the distinction between cities and non-urban cities in the study area with the help of MODIS classification data and extracted their LST as two ImageCollections of the same time range. I used ee.Join.inner to join the two ImageCollections and then converted them into an ImageCollection containing only two bands of urban average LST and non-urban average LST, and performed band subtraction on them to Calculate UHI. But the calculated results were all null values. This problem has bothered me for a long time. Would it be possible for someone to give me some suggestions in this regard?

//study area
var fcol = ee.FeatureCollection("users/pengxiaoxuehznu/anguoshi");

//mask function
var mask=function(image,my_type){
  var mask=image.neq(my_type);
  var masked_image=image.updateMask(mask);
  return masked_image;
}
var nomask=function(image,my_type){
  var nomask=image.eq(my_type);
  var nomasked_image=image.updateMask(nomask);
  return nomasked_image;
}

//mask city
var dataset1 = ee.ImageCollection('MODIS/006/MCD12Q1')
.filterDate('2017-01-01','2017-12-01')
.select('LC_Type1')
.map(function(image){
  image = mask(image,17);
  return image;
})
.map(function(image){
  image = mask(image,13).clip(fcol);
  return image;
});
               
//mask non-city
var dataset2 = ee.ImageCollection('MODIS/006/MCD12Q1')
.filterDate('2017-01-01','2017-12-01')
.select('LC_Type1')
.map(function(image){
  image = mask(image,17);
  return image;
})
.map(function(image){
  image = nomask(image,13).clip(fcol);
  return image;
});

// choose MODIS city temperature
var MOD11_city = ee.ImageCollection('MODIS/006/MOD11A1')
.filterDate('2017-01-01', '2017-12-31')
.map(function(image){
  image = image.updateMask(dataset2.first().mask());
  return image;
})//city
.map(function(image) {
  var lst = image.select('LST_Day_1km').multiply(0.02).subtract(273.15).rename('LST');
  return image.addBands(lst);
});
print(MOD11_city,"MOD11_city")

//mean city temperature
var MOD11_city_mean=MOD11_city
.map(function(image) {
  var image_city_meanlst = image.select('LST').reduce(ee.Reducer.mean()).rename('LST_mean1');
  return image.addBands(image_city_meanlst);
});  
print(MOD11_city_mean,"image_city_meanlst")

var mod11_citymean=ee.ImageCollection(MOD11_city_mean).select('LST_mean1');
print(mod11_citymean,"image_city_onlymeanlst")

// choose MODIS non-city temperature
var MOD11_nocity = ee.ImageCollection('MODIS/006/MOD11A1')
.filterDate('2017-01-01', '2017-12-31')
.map(function(image){
  image = image.updateMask(dataset1.first().mask());
  return image;
})//non-city
.map(function(image) {
  var lst = image.select('LST_Day_1km').multiply(0.02).subtract(273.15).rename('LST');
  return image.addBands(lst);
});

//mean non-city temperature
var MOD11_nocity_mean=MOD11_nocity
.map(function(image) {
  var image_nocity_meanlst = image.select('LST').reduce(ee.Reducer.mean()).rename('LST_mean2');
  return image.addBands(image_nocity_meanlst);
});  
print(MOD11_nocity_mean,"image_nocity_meanlst")

var mod11_nocitymean=ee.ImageCollection(MOD11_nocity_mean).select('LST_mean2');
print(mod11_nocitymean,"image_nocity_onlymeanlst")

//Inner Join
var innerJoin = ee.Join.inner();
var filterTimeEq = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

var innerJoinedMODIS = innerJoin.apply(mod11_citymean, mod11_nocitymean, filterTimeEq);
print('Inner join output:', innerJoinedMODIS);

// connect ImageCollections
var joinedMODIS = innerJoinedMODIS.map(function(feature) {
  return ee.Image.cat(feature.get('primary'), feature.get('secondary'));
});
print('Inner join, merged bands:', joinedMODIS);

//calculate UHI
//**My question: band subtraction was not calculated successfully.**
var connect=ee.ImageCollection(joinedMODIS)
 .map(function(image){
   var uhi = image.select('LST_mean1').subtract(image.select('LST_mean2')).float().rename('UHI');         
   return image.addBands(uhi);
 })
print(connect)

//ui.chart
var chart1 = ui.Chart.image.series({
 imageCollection: connect,
 region:fcol,
 reducer: ee.Reducer.mean(),
 scale: 500,
}).setOptions({title: 'UHI IMAGE SERIES'});
print(chart1);

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP