0

I have a large telemetry dataframe that I am trying to extract MSAVI2 values for. The way my code is currently set up, I believe I am able to correctly calculate an MSAVI2 layer and export a file containing all MSAVI2 values for each telemetry point. The problem is that my data spans twenty two years and I would like to be able to get an average annual MSAVI2 value from each point according to what year it was recorded in. Is there any way for me to do this if I include a year column in my data csv file?

Here's my current setup to calculate MSAVI2 values using a mosaic of the last five days of satellite imagery. The only caveat is that I'm having issues getting the example data to be displayed as a map layer. My real data was imported as a csv file so I'm not sure how to get the example coordinates to display. If anyone has any suggestions how to do this I would greatly appreciate it! I'm still very new to GEE so apologies for the incomplete nature of my example and any other obvious flaws in my code.

    //add imported data
    var s2 = ee.ImageCollection("COPERNICUS/S2")
    var pts= [
    [ {label: 'Year', role: 'data', type: 'number'}, 
    {label: 'X', role: 'data', type: 'number'},
    {label: 'Y', role: 'data', type: 'number'}
    ],
    [2000, -115.4324048, 36.16060103],
    [2001,-115.4301831, 36.16051783],
    [2002,-115.4301837, 36.1604908],
    [2003,-115.4281123, 36.15900324],
    [2004,-115.4289184, 36.15871634],
    [2005,-115.4303636, 36.15871727],
    [2006,-115.4284889, 36.15907129],
    [2007,-115.4288955, 36.16153763],
    [2008,-115.4284775, 36.15908917],
    [2009,-115.430006, 36.16159727],
    ]; 

    //compute composite for all images aquired in the last 5 days
    var now = ee.Date(Date.now())
    var composite = s2
    .filterDate(now.advance(-5, 'day'), now)
    .mosaic()
    .divide(10000)

    Map.addLayer(composite, {bands: ['B8', 'B8', 'B4'], min: 0, max: 0.4}, 'composite')

    // compute MSAVI2 using expression
    var msavi2 = composite.expression(
    '(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2',  
    {
    'NIR': composite.select('B8'), 
    'RED': composite.select('B4')
    }
    );
    //add the MSAVI2 layer
    Map.addLayer(msavi2, {min: -0.1, max: 0.5}, 'msavi2')

    //add the telemetry data points
    Map.addLayer(pts, null, 'points')

    // Applying first reducer
    var results = msavi2.reduceRegions({
    collection: pts, 
    reducer: ee.Reducer.first(), 
    scale: 250, // Native resolution
    });

    ///Export to Google Drive as csv file
    Export.table.toDrive({
    collection: results,
    description:'RasterValues',
    fileFormat: 'csv'});

0 Answers0