0

I want to extract a random sample of pixel values from each image of an image collection and then create a time series from the output. I have created a function to collect an sample of 1000 point from each image as follows.

function sampleImage(image) {

    var param = {numPoints: 1000, 
                  classBand: 'LST',
                  region:polygonCoordList, 
                  scale:30,
                  tileScale: 4
    };
    var SamPix = image.stratifiedSample(param);
    return SamPix;
}
var training = yearlyCol.map(sampleImage);
 print(training)

When running the code I get this error:

mageCollection (Error) Error in map(ID=0): Image.stratifiedSample: The class band must be integer typed.

From the documentation class band should be a string.

https://developers.google.com/earth-engine/apidocs/ee-image-stratifiedsample

I've also tried to go about it by sample random points (code bellow), but it times out after 5min or so

var randomPoints = ee.FeatureCollection.randomPoints(
    {region: meanTemp.geometry(), points: 1000});
    

function sampleImage(image) {
  
    var param = { collection: randomPoints, 
                  scale:30,
                  tileScale: 4
    };
    var SamPix = image.sampleRegions(param);
    return SamPix;
}
var training = yearlyCol.map(sampleImage);
 print(training);

Do you have any recommendations for fixing this error, or maybe an alternative route to get my desire output?

Link to code

1 Answer 1

0

The error mentions that the class band must be integer; thus, you need to convert that band to integers (in your OP it was double typed). You just need to add a pair of lines to your createAnnualImage function, round and cast to integer (int).

var createAnnualImage = function(year) {
  var startDate = ee.Date.fromYMD(year, 1, 1);
  var endDate = startDate.advance(1, 'year');
  // Calculate total precipitation
  var mean = LandsatCol.reduce(ee.Reducer.mean()).rename('LST')
                       // round and transform to integer
                       .round()
                       .int();
  return mean.set({
    'system:time_start': startDate.millis(),
    'system:time_end': endDate.millis(),
    'year': year,
  });
};

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.