gee线性回归制图

直接附上代码,在学习过程中又不需要了,但怕忘记便记录下来。

该为一个函数,所需要分析的影像数据 添加至

如下所示

//var LAI_mean=ee.ImageCollection(LAI_list).median();
//var NDVI_mean=ee.ImageCollection(NDVI_list).median();

var NDVI_LAI=LAI_mean.select('Lai').addBands(NDVI_mean.select('NDVI')).rename(['Lai','NDVI']);
get_value(NDVI_LAI)//调用函数

function get_value(combo){
  // Create 5000 random points in the region.在研究区中获得随机点
var randomPoints = ee.FeatureCollection.randomPoints(region,5000);
var imgSamp = combo.sampleRegions({
  collection: randomPoints,
  scale: 500,
  tileScale:16
})
// Add a constant property to each feature to be used as an independent variable.
.map(function(feature) {
  return feature.set('constant', 1);设定一个常数
});
Map.addLayer(randomPoints, {}, 'random points');
//

//return imgSamp
//Map.addLayer(randomPoints,{},'point')
var linearRegression = ee.Dictionary(imgSamp.reduceColumns({
  reducer: ee.Reducer.linearRegression({
    numX: 2,
    numY: 1
  }),
  selectors: ['constant', 'NDVI', 'Lai'] ndvi为x lai为y
}));
// Convert the coefficients array to a list.
var coefList = ee.Array(linearRegression.get('coefficients')).toList();
//print(coefList,'coe')
var res = ee.Array(linearRegression.get('residuals')).toList();
//print(res,'res')

// Extract the y-intercept and slope.
var yInt = ee.List(coefList.get(0)).get(0); // y-intercept
var slope = ee.List(coefList.get(1)).get(0); // slope
print(slope,'slope')
print(yInt,'yInt')
// Gather the  values from the point sample into a list of lists.
var props = ee.List(['NDVI', 'Lai']);
var regressionVarsList = ee.List(imgSamp.reduceColumns({
  reducer: ee.Reducer.toList().repeat(props.size()),
  selectors: props
}).get('list'));

// Convert regression x and y variable lists to an array - used later as input
// to ui.Chart.array.values for generating a scatter plot.
var x = ee.Array(ee.List(regressionVarsList.get(0)));
var y1 = ee.Array(ee.List(regressionVarsList.get(1)));
// Apply the line function defined by the slope and y-intercept of the
// regression to the x variable list to create an array that will represent
// the regression line in the scatter plot.


var y2 = ee.Array(ee.List(regressionVarsList.get(0)).map(function f(x) {
  var y = ee.Number(x).multiply(slope).add(y1);
  return y;
}));

// Concatenate the y variables ( predicted y) into an array
// for input to ui.Chart.array.values for plotting a scatter plot.
var yArr = ee.Array.cat([y1,y2], 1);

// Make a scatter plot of the two bands for the point sample and include
// the least squares line of best fit through the data.
print(ui.Chart.array.values({
  array: yArr,
  axis: 0,
  xLabels: x})
  .setChartType('ScatterChart')
  .setOptions({
    legend: {position: 'none'},
    hAxis: {'title': 'NDVI'},
    vAxis: {'title': 'Lai'},
    series: {
      0: {
        pointSize: 0.5,
        dataOpacity: 0.5,
      },
      1: {
        pointSize: 0,
        lineWidth: 2,
      },
      
    }
  })
);

}

计算过程中会有超时、及波段超过80mib,等问题尚待解决,目前对小区域、少随机数量点值可用

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值