0

I was trying to map rice in the Indramayu Regency in Indonesia using the random forest algorithm. It has responded with no training data found.

When I used the same code previously for a different time period I was able to map rice with no problem so I am unsure as to what is the problem. I used some imports to build the country boundaries and to map the rice so I have linked the code. The code has some imports so it's worth taking a look at the code link.

Here is the code (minus the imports):

var dist = countries.filter(ee.Filter.eq('ADM0_CODE', 116));

//2015-16 wet crop season 

var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2015-11-01', '2015-11-15')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                    .filterBounds(dist);
var sentinel2 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2015-12-16', '2015-12-31')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist);
var sentinel3 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-01-01', '2016-01-15')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist);
var sentinel4 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2015-01-16', '2015-01-31')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist);
var sentinel5 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-02-01', '2016-02-15')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist);
var sentinel6 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-02-16', '2016-02-28')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist);   
var sentinel7 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-03-01', '2016-03-15')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                     .filterBounds(dist); 
var sentinel8 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-03-16', '2016-03-31')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                    .filterBounds(dist);  
var sentinel9 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-04-01', '2016-04-15')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                    .filterBounds(dist);
var sentinel10 = ee.ImageCollection('COPERNICUS/S1_GRD')
                    .filterDate('2016-04-16', '2016-04-30')
                    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
                    .filter(ee.Filter.eq('instrumentMode', 'IW'))
                    .filter(ee.Filter.or((ee.Filter.eq('orbitProperties_pass', 'ASCENDING'), ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))))
                    .filterBounds(dist);
                    
var image1 = sentinel1.select('VH').mean().rename('VH1');
var image2 = sentinel2.select('VH').mean().rename('VH2');
var image3 = sentinel3.select('VH').mean().rename('VH3');
var image4 = sentinel4.select('VH').mean().rename('VH4');
var image5 = sentinel5.select('VH').mean().rename('VH5');
var image6 = sentinel6.select('VH').mean().rename('VH6');
var image7 = sentinel7.select('VH').mean().rename('VH7');
var image8 = sentinel8.select('VH').mean().rename('VH8');
var image9 = sentinel9.select('VH').mean().rename('VH9');
var image10 = sentinel10.select('VH').mean().rename('VH10');

var stacked1 = image1.addBands([image2,image3,image4,image5,image6,image7,image8,image9,image10]).clip(dist);

var stacked_scaled1 = stacked1.multiply(10).add(350).uint8();
var bands1 = ['VH2', 'VH3','VH9'];
var display = {bands: bands1, min: 0, max: 255};
Map.addLayer(stacked_scaled1, display, 'stacked1');

var gt1 =  water.merge(other).merge(rice1).merge(rice2).merge(rice3).merge(rice4).merge(rice5).merge(rice6).merge(urban);

var bandList = stacked_scaled1.bandNames().remove('VH4')
print(bandList)
var training = stacked_scaled1.select(bandList).sampleRegions({
  collection: gt1,
  properties: ['class'],
  scale: 10
});

// Make a Random Forest classifier and train it.
var classifier = ee.Classifier.smileRandomForest(10)
    .train({
      features: training,
      classProperty: 'class',});

var classified = stacked_scaled1.classify(classifier);

var masked = classified.updateMask(classified.lt(7));

Map.addLayer(classified,
             {min: 1, max:9 , palette: ['yellow','yellow','yellow','yellow','yellow','yellow','black','blue','red']},
             'classification');

https://code.earthengine.google.com/6ceafbd50a481df08c2fad5a2a9a2062.

1
  • 1
    Welcome to GIS SE. Please edit your question to include the pertinent code within the body of your question. This way, if the link ever goes defunct, the question will still be useful for yourself and others.
    – Aaron
    Commented Jun 22, 2022 at 3:19

1 Answer 1

1

If you print your training data training, you'll notice it is completely empty, hence there not being any valid training data. It looks like the error stems from your reduceRegions(). Upon going through your data carefully, I finally found the error. It appears that within your image stacked_scaled1 the band VH4 is masked for most of the analyzed area. If you add it to the map, you'll see why:

enter image description here

This masked band was causing the reduceRegions to mask all outputs. The following adjustment to your code works:

var bandList = stacked_scaled1.bandNames().remove('VH4')
var training = stacked_scaled1.select(bandList).sampleRegions({
  collection: gt1,
  properties: ['class'],
  scale: 10
});

In the future, I would strongly suggest you make sure your input data covers your sampling regions.

Your Answer

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

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