I keep getting this error in GEE. What I want to do is:

  1. Normalize VV and VH values from S1
  2. Calculate MDNWI for S2
  3. Normalize MDNWI for S2
  4. Combine all normalized values in one stack and get median value for each month of the year

Currently, I get the following error. Somebody know what I've been doing wrong? See code below.

ImageCollection (Error) Error in map(ID=20190210T073039_20190210T075733_T36JVQ): Image.unitScale, argument 'high': Invalid type. Expected type: Float. Actual type: Object. Actual value: null

// ROI

var roi = geometry

// Display map layers 
Map.centerObject(geometry, 10);

// define mo
var months = ee.List.sequence(1, 12);
var years = ee.List.sequence(2019, 2019);

// Define training and monitoring period
var start_monitoring = '2019-01-01';
var end_monitoring = '2019-12-31';

var s1_collection = ee.ImageCollection('COPERNICUS/S1_GRD')
 .filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'))
 .filter(ee.Filter.eq('instrumentMode', 'IW'))
 .filterDate(ee.Date(start_monitoring), ee.Date(end_monitoring))

// Select and filter collection for S2, filter clouds
var s2_collection = ee.ImageCollection('COPERNICUS/S2')
 .filterDate(ee.Date(start_monitoring), ee.Date(end_monitoring))
 .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 40))

// Simple cloudMask
var func1 = function cloudMask(im) {
 var condition = im.select('B2').gte(2800)
 var mask1 = ee.Image(0).where(condition, 1).not()
 return im.updateMask(mask1);
// remove clouds for all images
var s2_collection = s2_collection.map(func1)

print(s2_collection, 'rmclouds')

var addvariables = function(image) {
 var SWIR = image.select('B11')
 var NIR = image.select('B8')
 var RED = image.select('B4')
 var BLUE = image.select('B2')
 var GREEN = image.select('B3')
 var mndwi = image.normalizedDifference(['B11', 'B3']).rename('mndwi')
   return image.addBands(mndwi);
var s2_collection = s2_collection.map(addvariables)
var s2_collection = s2_collection.select('mndwi')
print(s2_collection, 's2 mdnwi check')

//var s2_collection = s2_collection.select('').float()

// Clip to ROI
var s2_collection = s2_collection.map(function(image){
 return image.clip(roi);

var s1_collection = s1_collection.map(function(image){
 return image.clip(roi);

var s1_collection = s1_collection.select('VV', 'VH')
print(s1_collection, 's1 check')

// s1 and s2 normalization

var normalization = function(image) {
   var imMinMax = image.reduceRegion({
       reducer: ee.Reducer.minMax(),
       geometry: geometry,
       // scale: 1000,
       maxPixels: 10e9,
       bestEffort: true,
       tileScale: 16,
       crs: 'EPSG:4326',
       scale: 30,
   var imNorm = ee.ImageCollection.fromImages(
           name = ee.String(name);
           var band = image.select(name);
           return band.unitScale(ee.Number(imMinMax.get(name.cat('_min'))), ee.Number(imMinMax.get(name.cat('_max'))));
   return imNorm.toBands().rename(image.bandNames());
var imNormalize = function(imcollection){
 return imcollection.map(normalization);

var imNormalized_s1 = imNormalize(s1_collection);
print(imNormalized_s1, 's1 norm')

var imNormalized_s2 = imNormalize(s2_collection);
print(imNormalized_s2, 's2 norm')

var s1_collection = ee.ImageCollection.fromImages(
 years.map(function(y) {
   return months.map(function (m) {
     return s1_collection
       .filter(ee.Filter.calendarRange(y, y, 'year'))
       .filter(ee.Filter.calendarRange(m, m, 'month'))
       .set('month', m).set('year', y);

var s2_collection = ee.ImageCollection.fromImages(
 years.map(function(y) {
   return months.map(function (m) {
     return s1_collection
       .filter(ee.Filter.calendarRange(y, y, 'year'))
       .filter(ee.Filter.calendarRange(m, m, 'month'))
       .set('month', m).set('year', y);

var plotNDVI_s1_VV = ui.Chart.image.seriesByRegion(imNormalized_s2 ,Land,ee.Reducer.mean(),
               title: 'VV long-term time series (Land)',
               hAxis: {title: 'Month'},
               vAxis: {title: 'MNDWI', minValue:0.45, maxValue:0.7},

var plotNDVI_s1_VH = ui.Chart.image.seriesByRegion(imNormalized_s1, Land,ee.Reducer.mean(),
               title: 'VV long-term time series (Land)',
               hAxis: {title: 'Month'},
               vAxis: {title: 'MNDWI', minValue:0.4, maxValue:0.7}
print(plotNDVI_s1_VH);  ```
New contributor
user218574 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.


Your Answer

user218574 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.