如何根据时间序列的数据绘制Google Earth Engine中某个点的散点图

时间:2020-04-14 20:58:24

标签: time-series scatter-plot google-earth-engine

我正在尝试在Google Earth Engine中为我的数据创建散点图。我能够为选定的区域和日期绘制散点图,但不能为选定的点和时间序列绘制散点图。在此处提供的代码中,我尝试遵循https://developers.google.com/earth-engine/charts_array_values中的示例。我收到错误消息“ s1_Lai.reduceRegion不是函数”。我认为这是因为reduceRegion需要图像而不是集合;但是,时间序列信息位于集合中,而不是单个图像。这可能不是正确的方法。

// NE_1 Ameriflux site
var point = ee.Geometry.Point(-96.47664, 41.16506);

var proj = ee.Projection('EPSG:32614');
var startDate = '2017-01-01'
var endDate = '2020-02-20'

var reproject = function(image) {
  var reprojected = image.reproject(proj, null, 500);
  return reprojected};

//MODIS LAI
var MODIS = ee.ImageCollection('MODIS/006/MCD15A3H');
var MODIS_TempFilt = MODIS.filterDate(startDate, endDate);
var MODIS_TempFilt_Resamp =  MODIS_TempFilt.map(reproject);
var MODIS_TempSpatFilt_Resamp = MODIS_TempFilt_Resamp.filterBounds(point);
var M_LAI = MODIS_TempSpatFilt_Resamp.select('Lai');

//Sentinel-1 SAR
var LogRatio = function(img) {
  var logVV = img.select('VV');
  var logVH = img.select('VH');
  var logratio = logVH.subtract(logVV).rename('logVH/VV');
  var logratio_float = logratio.toFloat();
  return img.addBands(logratio_float)};

var S1 = ee.ImageCollection('COPERNICUS/S1_GRD');
var S1_TempFilt = S1.filterDate(startDate, endDate);
var S1_TempFilt_Resamp = S1_TempFilt.map(reproject);
var S1_TempSpatFilt_Resamp = S1_TempFilt_Resamp.filterBounds(point);
var S1_TempSpaceFiltResamp_W_LogCR = S1_TempSpatFilt_Resamp.map(LogRatio);
var S1_Log_VH_VV = S1_TempSpaceFiltResamp_W_LogCR.select('logVH/VV');

// image join code contributed by Daniel (?) from Stack Exchange
var s1_Lai = ee.ImageCollection(ee.Join.saveAll('Lai')
  .apply({
      primary: S1_Log_VH_VV,
      secondary: M_LAI,
      condition: ee.Filter.and(
        ee.Filter.intersects({
          leftField: '.geo',
          rightField: '.geo'
        }),
        ee.Filter.maxDifference({
          // Include LAI within 2 days of s1
          difference: 2 * 24 * 3600 * 1000, 
          leftField: 'system:time_start',
          rightField: 'system:time_start'
        })
      )
  }))
  .map(function (s1) {
    var Lai = ee.ImageCollection(
        ee.List(s1.get('Lai'))
      )
      .mosaic()
    return s1
      .addBands(Lai)
      .float()
  })
print('s1_Lai',s1_Lai)

// Define an area, generate a sample of points within the area for a given date
var area = S1_Log_VH_VV.first().geometry()
var start = '2017-09-02'
var finish = '2017-09-06'
var example = s1_Lai.filterDate(start, finish).first()
var sample = example.sample({ region: area, scale: 500, numPixels: 1000, geometries: true})

// Create spatial scatter chart for selected date with R-squared
var chart1 = ui.Chart.feature.byFeature(sample,'Lai', 'logVH/VV')
  .setChartType('ScatterChart')
  .setOptions({ pointSize: 2, pointColor: 'red', width: 300, height: 300, 
      titleX: 'LAI NE Area', titleY: 'Backscatter Cross Ratio NE Area', trendlines: {
        0: {
          type: 'linear',
          color: 'lightblue',
          lineWidth: 3,
          opacity: 0.7,
          showR2: true,
          visibleInLegend: true
        } } });
print(chart1);

// Create temporal scatter chart for selected point with R-squared
// Ref https://developers.google.com/earth-engine/charts_array_values

// Get a dictionary with band names as keys, pixel lists as values.
var result = s1_Lai.reduceRegion(ee.Reducer.toList(), point, 500);

// Convert the band data to plot on the y-axis to arrays.
var yValues = ee.Array(result.get('Lai'));

// The band data to plot on the x-axis is a List.
var xValues = result.get('logVH/VV');
var chart = ui.Chart.array.values(yValues, 0, xValues)
    .setSeriesNames('Lai')
    .setOptions({
      title: 'logVH/VV vs. Lai',
      hAxis: {'title': 'logVH/VV'},
      vAxis: {'title': 'Lai'},
      pointSize: 3,
      trendlines: {
        0: {
          type: 'linear',
          color: 'lightblue',
          lineWidth: 3,
          opacity: 0.7,
          showR2: true,
          visibleInLegend: true
        } }});
// Print the chart.
print(chart);

0 个答案:

没有答案