I would like to get 5 to 95 percent Day_1km_LST from MOD11A1, but it show this error:

ComputedObject (Error) Error in map(ID=2015_01_05): Image.constant: Parameter 'value' is required

The Google Earth Engine Code: https://code.earthengine.google.com/98134eed5eb512d7db6561619a7053c6accept_repo=users%2Fsofiaermida%2Flandsat_smw_lst

// region
var boundary1=ee.FeatureCollection("users/liukunsheng6/GBA");
var roi = boundary1.geometry();
Map.addLayer(roi,{'color':'grey'}, 'studyArea');

var year = 2015;

var LSTVisPara = {
  min: 290.0,
  max: 310.0,
  palette: [
    '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
    '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
    '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
    'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
    'ff0000', 'de0101', 'c21301', 'a71001', '911003'

// remove cloud for MoDIS_lst
var bitwiseExtract = function(input, fromBit, toBit) {
  var maskSize = ee.Number(1).add(toBit).subtract(fromBit);
  var mask = ee.Number(1).leftShift(maskSize).subtract(1);
  return input.rightShift(fromBit).bitwiseAnd(mask);
function maskMod_lst(image){
  var lstDay = image.select('LST_Day_1km');
  var qcDay = image.select('QC_Day');
// Let's extract all pixels from the input image where
// Bits 0-1 <= 1 (LST produced of both good and other quality)
// Bits 2-3 = 0 (Good data quality)
// Bits 4-5 Ignore, any value is ok
// Bits 6-7 = 0 (Average LST error ≤ 1K)  
  var qaMask = bitwiseExtract(qcDay, 0, 1).lte(1);
  var dataQualityMask = bitwiseExtract(qcDay, 2, 3).eq(0);
  var lstErrorMask = bitwiseExtract(qcDay, 6, 7).eq(0);
  var mask = qaMask.and(dataQualityMask).and(lstErrorMask);
  return lstDay.updateMask(mask).toFloat().multiply(0.02).subtract(273.15)

//get the 1kmd ailyLST product MOD11A1
var MOD_LST = ee.ImageCollection('MODIS/061/MOD11A1')

// MO11A1_year composite
var MOD_LST_source = MOD_LST.select('LST_Day_1km').median().clip(roi);
Map.addLayer(MOD_LST_source, LSTVisPara,'LST_Day_1km',false); 

// define the percent function
function removeOutliers(image) {
  var accPctRange = image.reduceRegion({
    reducer: ee.Reducer.percentile([5, 95]),
    geometry: roi, 
    scale: 30, 
    bestEffort: true

  var minVal = ee.Number(accPctRange.get('LST_Day_1km_p5'));
  var maxVal = ee.Number(accPctRange.get('LST_Day_1km_p95'));
  var processedImage = image.updateMask(image.gte(minVal).and(image.lte(maxVal)));
  return processedImage;

// cal the median
var lst = MOD_LST.map(removeOutliers)

// cal the min and max
var minValImage = lst.reduceRegion(ee.Reducer.min(), roi, 1000).get('LST_Day_1km');
var maxValImage = lst.reduceRegion(ee.Reducer.max(), roi, 1000).get('LST_Day_1km');

print('Min Value:', minValImage);
print('Max Value:', maxValImage);

1 Answer 1


The problem here is that LST_Day_1km_p5 and LST_Day_1km_p95 is null. There is probably some image with no unmasked pixels in the collection.

A quick fix to this could be to turn minVal and maxVal into constant images and use ee.Algorithms.If() to ensure they're masked out if they're null. Note that this will also mask them out if they're 0 too.

  var minVal = accPctRange.getNumber('LST_Day_1km_p5')
  minVal = ee.Image(ee.Algorithms.If(minVal, ee.Image(minVal), ee.Image()))
  var maxVal = accPctRange.getNumber('LST_Day_1km_p95')
  maxVal = ee.Image(ee.Algorithms.If(maxVal, ee.Image(maxVal), ee.Image()))

An arguably better solution is to split up removeOutliers() into two separate functions. First calculate the percentiles, filter out images where you get null, then remove outliers.

var lst = MOD_LST
  .filter(ee.Filter.notNull(['LST_Day_1km_p5', 'LST_Day_1km_p95']))

function addPercentiles(image) {
  var accPctRange = image.reduceRegion({
    reducer: ee.Reducer.percentile([5, 95]),
    geometry: roi, 
    scale: 30, 
    bestEffort: true
  return image.set(accPctRange)

function removeOutliers(image) {
  var minVal = image.getNumber('LST_Day_1km_p5')
  var maxVal = image.getNumber('LST_Day_1km_p95')
  var processedImage = image.updateMask(image.gte(minVal).and(image.lte(maxVal)));
  return processedImage;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.