I am trying to use the MODIS Terra Thermal Anomalies & Fire Daily Global dataset to get fire data in a date range at random points. I have the following code:
var dataset = ee.ImageCollection('MODIS/006/MOD14A1')
.filter(ee.Filter.date('2018-01-17', '2019-01-04'));
var fireMaskVis = {
min: 0.0,
max: 6000.0,
bands: ['MaxFRP', 'FireMask', 'FireMask'],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(dataset, fireMaskVis, 'Fire Mask');
// coordinates to zoom to and get statistics from
var AOI = ee.Geometry.Polygon(
[[[-123.77121985512588,41.949152607992204],[-120.01389563637588,41.965492420510905],
[-120.01389563637588,38.95714272663463],[-123.59543860512588,38.99130708533593]]]);
AOI = ee.FeatureCollection.randomPoints(AOI);
var point = ee.Geometry.Point([2.3622940161999395, 42.569280018996714]);
Map.addLayer(AOI, {}, 'the area of interest');
Map.centerObject(AOI, 11);
var fire = dataset.select("FireMask");
// reduce the surface temperature image collection to a single image with stacked bands
function collToBands(imageCollection, bandName) {
// stack all the bands to one single image
// change the name of the bandname to the date it is acquired
var changedNames = imageCollection.map( function(img){
var dateString = ee.Date(img.get('system:time_start')).format('yyyy-MM-dd');
return img.select(bandName).rename(dateString);
});
// Apply the function toBands() on the image collection to set all bands into one image
var multiband = changedNames.toBands();
// Reset the bandnames
var names = multiband.bandNames();
// rename the bandnames
var newNames = names.map(function(name){
var ind = names.indexOf(name);
return ee.String(names.get(ind)).slice(5);
});
return multiband.rename(newNames);
}
// apply the function and print to console
var multiband = collToBands(fire, "FireMask");
//print('collection to bands', multiband);
// get the temperature at a given point on the map for the given time spand and print to the console
var firePoint = multiband.reduceRegion({reducer: ee.Reducer.mean(), geometry: point, scale: 1000, bestEffort: true});
//print(firePoint);
///// DO THE SAME OPERATION FOR MULTIPLE SPACED POINTS IN AN AREA OF INTEREST
// make a feature collection of many pixelsize-spaced points
function spacedPoints(AOI, proj) {
// make a coordinate image
// get coordinates image
var latlon = ee.Image.pixelLonLat().reproject(proj);
// put each lon lat in a list -> this time for getting an multipoint list (more useful inside the GEE)
var coords = latlon.select(['longitude', 'latitude'])
.reduceRegion({reducer: ee.Reducer.toList(),
geometry: AOI,
scale: proj.nominalScale().toInt()
});
// zip the coordinates for representation. Example: zip([1, 3],[2, 4]) --> [[1, 2], [3,4]]
var point_list = ee.List(coords.get('longitude')).zip(ee.List(coords.get('latitude')));
// preset a random list
var list = ee.List([0]);
// Make a feature collection of the multipoints and assign distinct IDs to every feature
var feats = ee.FeatureCollection(point_list.map(function(point){
var ind = point_list.indexOf(point);
var feat = ee.Feature(ee.Geometry.Point(point_list.get(ind)), {'ID': ind});
return list.add(feat);
}).flatten().removeAll([0]));
return feats;
}
// use function to get the spaced points
var points = spacedPoints(AOI, multiband.projection());
//print(points);
// add to the map
Map.addLayer(points.draw('red'), {}, 'the spaced points');
// calculate the temperature over the time span at every point in the AOI
var fires = multiband.reduceRegions({collection: points, reducer: ee.Reducer.mean(), scale: 1000});
//print(fires);
//print('feature collection of temperatures', temperatures);
//print(fires.filter(ee.Filter.eq("system:index", '0')));
var aDate = ee.Date('2018-01-17');
var days = ee.List.sequence(0, 352); //352
var dates = days.map(function(d) {
return aDate.advance(ee.Number(d), 'day').format('YYYY-MM-dd');
});
//print(dates);
var pointCounts = [];
for(var e = 0; e < 100; e++) {
pointCounts.push(e.toString());
}
var pointValues = pointCounts.map(function(point) {
var numOfDates = ee.List.sequence(0, 10);
var values = numOfDates.map(function(i) {
return fires.filter(ee.Filter.eq("system:index", point)).aggregate_array(dates.get(i));
});
return values;
});
print(pointValues);
When I run the code, I get the following error: the spaced points: Layer error: Image.projection: The bands of the specified image contains different projections. Use Image.select to pick a single band. Can anyone tell me what's wrong?