Google Earth Engine – Fixing Pixel Value Extraction Errors for Chlorophyll and SST from SMI Modis Aqua

google-earth-enginegoogle-earth-engine-javascript-apivalue-extraction

I'm trying to extract specific pixel values in a csv table of chlorophyll-a and sea surface temperature from Standard Mapped Image MODIS Aqua Data to match to the sampling site over the sampling period that on site measurements were also taken.
The script below returns an error sitesCollection.filterBounds is not a function. Any idea how I can fix this error?

I have run this code before with GCOM-C/SGLI L3 Chlorophyll-a concentration (V3) and I don't get the error. The only issue is I get a lot of NAs with that dataset and therefore I switched to Standard Mapped Image MODIS Aqua Data.

This is the code:


// Extract sea water chlorophyll-a and SST values for at a specific pixel that match to the 
// sampling site AND sampling period that on-site sampling was done

// Import dataset

var sitesCollection = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
  // Filter dates
  .filterDate('2022-01-10', '2022-02-10')
  // Mosaic all images in the collection (could use .mean() or .median())
  .mosaic()
  // Select only the two bands of interest
  .select(['chlor_a', 'sst']);

var chlorsst =
sitesCollection.select(['chlor_a', 'sst']);
var chlorsstVis = {
min: 0.0,
max: 99,
};

Map.addLayer(chlorsst, chlorsstVis,'Chlorsst');
 
print(chlorsst)

// Study sites sampled 

var siteCoords_features = [
ee.Feature(ee.Geometry.Point(73.8918, 1.8119), {name: 'TRA01'}),
ee.Feature(ee.Geometry.Point(72.7300, -4.5690), {name: 'TRA02'}),
ee.Feature(ee.Geometry.Point(72.2303, -5.2986), {name: 'TRA03'}),
ee.Feature(ee.Geometry.Point(72.2571, -5.2814), {name: 'SPOU2000'}),
ee.Feature(ee.Geometry.Point(72.2360371, -5.340068), {name: 'SAIN2000'}),
ee.Feature(ee.Geometry.Point(72.204352, -5.324261), {name: 'SAOU2000'}),
ee.Feature(ee.Geometry.Point(72.250802, -5.321385), {name: 'SPIN2000'}),
ee.Feature(ee.Geometry.Point(71.95208, -5.36914), {name: 'PGCIN2000'}),
ee.Feature(ee.Geometry.Point(71.770524, -5.399835), {name: 'PPOIN2000'}),
ee.Feature(ee.Geometry.Point(71.808373, -5.424579), {name: 'TRA04'}),
ee.Feature(ee.Geometry.Point(71.7319344, -5.400639), {name: 'PPOOU2000'}),
ee.Feature(ee.Geometry.Point(71.351852, -6.182962), {name: 'GE2000'}),
ee.Feature(ee.Geometry.Point(71.495025, -6.151137), {name: 'TRA05'}),
ee.Feature(ee.Geometry.Point(71.541092, -6.157744), {name: 'TRA07'}),
ee.Feature(ee.Geometry.Point(71.250083, -6.389199), {name: 'GD2000'}),
ee.Feature(ee.Geometry.Point(72.419197, -7.246325), {name: 'DE2000'}),];

// Create a FeatureCollection from the list of coords
var pt_collection = ee.FeatureCollection(siteCoords_features);

print('List', pt_collection);
Map.addLayer(pt_collection);
Map.centerObject(pt_collection, 10);

// Pixel extractions of all coordinates

var outputData = pt_collection.map(function(feat){
  // only map over images that intersect with the selected feature.
  var filterCollect = sitesCollection.filterBounds(ee.Feature(feat).geometry());
  
  return filterCollect.map(function(img){
    return ee.Feature(null,img.reduceRegion({
      geometry: feat.geometry(),
      scale: 30,
      reducer: ee.Reducer.mean()})).set({ // set additional properties
        name: feat.get('name'),
        //date: feat.get('Date'),
        lat: feat.geometry().coordinates().get(0),
        lon: feat.geometry().coordinates().get(1),
      });
    });
}).flatten();

print(outputData);

// Export
Export.table.toDrive({
  collection: outputData,
  folder: 'GEE_results',
  fileNamePrefix: 'MODIS_chloro_sst_2022',
  fileFormat: 'CSV',
  })
  

Best Answer

I changed var filterCollect = sitesCollection.filterBounds(ee.Feature(feat).geometry());

to var filterCollect = ee.ImageCollection(sitesCollection).filterBounds(ee.Feature(feat).geometry());

and it looks good now. When in doubt, tell GEE what object type you're using

Related Question