Google Earth Engine:对NDVI进行惠特克平滑算法进行长时序分析

2024-08-31 10:36

本文主要是介绍Google Earth Engine:对NDVI进行惠特克平滑算法进行长时序分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

简介

函数

ee.Array.identity(size)

Arguments:

Returns: Array

transpose(axis1, axis2)

Arguments:

Returns: Array

matrixMultiply(image2)

Arguments:

Returns: Image

matrixSolve(image2)

Arguments:

Returns: Image

arrayFlatten(coordinateLabels, separator)

Arguments:

Returns: Image

arrayReduce(reducer, axes, fieldAxis)

Arguments:

Returns: Image

代码

结果


简介

惠特克(GEE)平滑算法是一种用于时间序列预测的统计方法,特别适用于非线性、非平稳和非高斯的数据。该算法基于广义估计方程,通过最小化残差的平方和来拟合数据并找到最佳的平滑曲线。

GEE平滑算法的主要思想是在时间序列数据中引入一个平滑函数来描述数据的趋势和周期性变化。该平滑函数由一系列基函数的线性组合组成,其中每个基函数具有不同的频率和振幅。通过调整基函数的权重,可以得到最佳的平滑曲线,以最大程度地拟合数据。

在实际应用中,GEE平滑算法通常与其他统计方法结合使用,例如自回归移动平均模型(ARIMA)或指数平滑法。通过将GEE平滑算法与其他方法相结合,可以进一步提高时间序列的预测准确度和稳定性。

总的来说,GEE平滑算法是一种针对非线性、非平稳和非高斯数据的时间序列预测方法,通过引入一个平滑函数来描述数据的趋势和周期性变化,以最大程度地拟合数据。它在实际应用中通常与其他统计方法结合使用,以进一步提高预测的准确度和稳定性。

函数

ee.Array.identity(size)

Creates a 2D identity matrix of the given size.

创建一个给定大小的二维标识矩阵。

Arguments:

size (Integer):

The length of each axis.

Returns: Array

transpose(axis1axis2)

Transposes two dimensions of an array.

平移数组的两个维度。

Arguments:

this:array (Array):

Array to transpose.

axis1 (Integer, default: 0):

First axis to swap.

axis2 (Integer, default: 1):

Second axis to swap.

Returns: Array

matrixMultiply(image2)

Returns the matrix multiplication A * B for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.

返回图像 1 和图像 2 中每对匹配波段的矩阵乘法 A * B。如果图像 1 或图像 2 中只有一个波段,则该波段将与另一幅图像中的所有波段相对应。如果图像中的条带数量相同,但名称不同,则按自然顺序成对使用。输出波段以两个输入波段中较长的一个命名,如果两个输入波段长度相等,则按图像 1 的顺序命名。输出像素的类型是输入类型的组合。

Arguments:

this:image1 (Image):

The image from which the left operand bands are taken.

image2 (Image):

The image from which the right operand bands are taken.

Returns: Image

matrixSolve(image2)

Solves for x in the matrix equation A * x = B, finding a least-squares solution if A is overdetermined for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.

求解矩阵方程 A * x = B 中的 x,如果 A 对图像 1 和图像 2 中每对匹配的波段都是过确定的,则找到最小二乘法解。如果图像 1 或图像 2 中只有一个波段,则使用该波段与另一幅图像中的所有波段进行比对。如果图像中的波段数相同,但名称不相同,则按自然顺序成对使用。输出波段以两个输入波段中较长的一个命名,如果两个输入波段长度相等,则按图像 1 的顺序命名。输出像素的类型是输入类型的组合。

Arguments:

this:image1 (Image):

The image from which the left operand bands are taken.

image2 (Image):

The image from which the right operand bands are taken.

Returns: Image

arrayFlatten(coordinateLabels, separator)

Converts a single-band image of equal-shape multidimensional pixels to an image of scalar pixels, with one band for each element of the array.

将等形多维像素的单波段图像转换为标量像素图像,阵列中的每个元素对应一个波段。

Arguments:

this:image (Image):

Image of multidimensional pixels to flatten.

coordinateLabels (List):

Name of each position along each axis. For example, 2x2 arrays with axes meaning 'day' and 'color' could have labels like [['monday', 'tuesday'], ['red', 'green']], resulting in band names'monday_red', 'monday_green', 'tuesday_red', and 'tuesday_green'.

separator (String, default: "_"):

Separator between array labels in each band name.

Returns: Image

arrayReduce(reducer, axes, fieldAxis)

Reduces elements of each array pixel.

减少每个阵列像素的元素。

Arguments:

this:input (Image):

Input image.

reducer (Reducer):

The reducer to apply.

axes (List):

The list of array axes to reduce in each pixel. The output will have a length of 1 in all these axes.

fieldAxis (Integer, default: null):

The axis for the reducer's input and output fields. Only required if the reducer has multiple inputs or outputs.

Returns: Image

代码

//加载研究区
var geometry = /* color: #d63000 *//* displayProperties: [{"type": "rectangle"}] */ee.Geometry.Polygon([[[113.44773227683973, 38.6708907304602],[113.44773227683973, 38.64783484482313],[113.47588474266004, 38.64783484482313],[113.47588474266004, 38.6708907304602]]], null, false);// 将 qa 位图像转换为标志的辅助函数
function extractBits(image, start, end, newName) {// 计算我们需要提取的比特。var pattern = 0;for (var i = start; i <= end; i++) {pattern += Math.pow(2, i);}// 返回提取的质量保证位的单波段图像,并为该波段命名。return image.select([0], [newName]).bitwiseAnd(pattern).rightShift(start);
}// 在输入矩阵上获取指定阶次的差分矩阵的函数。将矩阵和阶次作为参数
function getDifferenceMatrix(inputMatrix, order){var rowCount = ee.Number(inputMatrix.length().get([0]));var left = inputMatrix.slice(0,0,rowCount.subtract(1));var right = inputMatrix.slice(0,1,rowCount);if (order > 1 ){return getDifferenceMatrix(left.subtract(right), order-1)}return left.subtract(right);
};// 将数组图像解包为图像和波段
// 以数组图像、图像 ID 列表和乐队名称列表为参数
function unpack(arrayImage, imageIds, bands){function iter(item, icoll){function innerIter(innerItem, innerList){return ee.List(innerList).add(ee.String(item).cat("_").cat(ee.String(innerItem)))}var temp = bands.iterate(innerIter, ee.List([]));return ee.ImageCollection(icoll).merge(ee.ImageCollection(ee.Image(arrayImage).select(temp,bands).set("id",item)))}var imgcoll  = ee.ImageCollection(imageIds.iterate(iter, ee.ImageCollection([])));return imgcoll}// 用于计算回归结果的反对数比率并转换回百分比单位的函数
function inverseLogRatio(image) {var bands = image.bandNames();var t = image.get("system:time_start");var ilrImage = ee.Image(100).divide(ee.Image(1).add(image.exp())).rename(bands);return ilrImage.set("system:time_start",t);
}function whittakerSmoothing(imageCollection, isCompositional, lambda){// 快速配置以设置默认值if (isCompositional === undefined || isCompositional !==true) isCompositional = false;if (lambda === undefined ) lambda = 10;// 程序启动  var ic = imageCollection.map(function(image){var t = image.get("system:time_start");return image.toFloat().set("system:time_start",t);});var dimension = ic.size();var identity_mat = ee.Array.identity(dimension);var difference_mat = getDifferenceMatrix(identity_mat,3);var difference_mat_transpose = difference_mat.transpose();var lamda_difference_mat = difference_mat_transpose.multiply(lambda);var res_mat = lamda_difference_mat.matrixMultiply(difference_mat);var hat_matrix = res_mat.add(identity_mat);// 备份原始数据var original = ic;// 获取原始图像属性var properties = ee.List(ic.iterate(function(image, list){return ee.List(list).add(image.toDictionary());},[]));var time = ee.List(ic.iterate(function(image, list){return ee.List(list).add(image.get("system:time_start"));},[]));// 如果数据是合成的// 计算图像在 0 到 100 之间的对比率。首先// 夹在 delta 和 100-delta 之间,其中 delta 是一个很小的正值。if (isCompositional){ic = ic.map(function(image){var t = image.get("system:time_start");var delta = 0.001;var bands = image.bandNames();image = image.clamp(delta,100-delta);image = (ee.Image.constant(100).subtract(image)).divide(image).log().rename(bands);return image.set("system:time_start",t);});}var arrayImage = original.toArray();var coeffimage = ee.Image(hat_matrix);var smoothImage = coeffimage.matrixSolve(arrayImage);var idlist = ee.List(ic.iterate(function(image, list){return ee.List(list).add(image.id());},[]));var bandlist = ee.Image(ic.first()).bandNames();var flatImage = smoothImage.arrayFlatten([idlist,bandlist]);var smoothCollection = ee.ImageCollection(unpack(flatImage, idlist, bandlist));if (isCompositional){smoothCollection = smoothCollection.map(inverseLogRatio);}// 通过添加后缀fitted获得新的乐队名称var newBandNames = bandlist.map(function(band){return ee.String(band).cat("_fitted")});// 重新命名平滑图像中的波段smoothCollection = smoothCollection.map(function(image){return ee.Image(image).rename(newBandNames)});// 一个非常笨的方法,可以flatten谷歌地球引擎生成的 ID,这样就可以将两张图片合并为图表了var dumbimg = arrayImage.arrayFlatten([idlist,bandlist]);var dumbcoll = ee.ImageCollection(unpack(dumbimg,idlist, bandlist));var outCollection = dumbcoll.combine(smoothCollection);var outCollectionProp = outCollection.iterate(function(image,list){var t = image.get("system:time_start")return ee.List(list).add(image.set(properties.get(ee.List(list).size())));},[]);var outCollectionProp = outCollection.iterate(function(image,list){return ee.List(list).add(image.set("system:time_start",time.get(ee.List(list).size())));},[]);var residue_sq = smoothImage.subtract(arrayImage).pow(ee.Image(2)).divide(dimension);var rmse_array = residue_sq.arrayReduce(ee.Reducer.sum(),[0]).pow(ee.Image(1/2));var rmseImage = rmse_array.arrayFlatten([["rmse"],bandlist]);return [ee.ImageCollection.fromImages(outCollectionProp), rmseImage];
}var ndvi =ee.ImageCollection("NOAA/VIIRS/001/VNP13A1").select('NDVI').filterDate("2019-01-01","2019-12-31");
// 去除屏蔽像素
ndvi = ndvi.map(function(img){return img.unmask(ndvi.mean())});var ndvi =  whittakerSmoothing(ndvi)[0];// 添加图表
print(ui.Chart.image.series(ndvi.select(['NDVI', 'NDVI_fitted']), geometry, ee.Reducer.mean(), 500).setSeriesNames(['NDVI', 'NDVI_fitted']).setOptions({title: 'smoothed',lineWidth: 1,pointSize: 3,
}));

结果

这篇关于Google Earth Engine:对NDVI进行惠特克平滑算法进行长时序分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1123663

相关文章

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

SpringSecurity6.0 如何通过JWTtoken进行认证授权

《SpringSecurity6.0如何通过JWTtoken进行认证授权》:本文主要介绍SpringSecurity6.0通过JWTtoken进行认证授权的过程,本文给大家介绍的非常详细,感兴趣... 目录项目依赖认证UserDetailService生成JWT token权限控制小结之前写过一个文章,从S

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

kotlin中const 和val的区别及使用场景分析

《kotlin中const和val的区别及使用场景分析》在Kotlin中,const和val都是用来声明常量的,但它们的使用场景和功能有所不同,下面给大家介绍kotlin中const和val的区别,... 目录kotlin中const 和val的区别1. val:2. const:二 代码示例1 Java

Go标准库常见错误分析和解决办法

《Go标准库常见错误分析和解决办法》Go语言的标准库为开发者提供了丰富且高效的工具,涵盖了从网络编程到文件操作等各个方面,然而,标准库虽好,使用不当却可能适得其反,正所谓工欲善其事,必先利其器,本文将... 目录1. 使用了错误的time.Duration2. time.After导致的内存泄漏3. jsO

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.

C#使用SQLite进行大数据量高效处理的代码示例

《C#使用SQLite进行大数据量高效处理的代码示例》在软件开发中,高效处理大数据量是一个常见且具有挑战性的任务,SQLite因其零配置、嵌入式、跨平台的特性,成为许多开发者的首选数据库,本文将深入探... 目录前言准备工作数据实体核心技术批量插入:从乌龟到猎豹的蜕变分页查询:加载百万数据异步处理:拒绝界面

Python使用自带的base64库进行base64编码和解码

《Python使用自带的base64库进行base64编码和解码》在Python中,处理数据的编码和解码是数据传输和存储中非常普遍的需求,其中,Base64是一种常用的编码方案,本文我将详细介绍如何使... 目录引言使用python的base64库进行编码和解码编码函数解码函数Base64编码的应用场景注意

Java进行文件格式校验的方案详解

《Java进行文件格式校验的方案详解》这篇文章主要为大家详细介绍了Java中进行文件格式校验的相关方案,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、背景异常现象原因排查用户的无心之过二、解决方案Magandroidic Number判断主流检测库对比Tika的使用区分zip

Java使用Curator进行ZooKeeper操作的详细教程

《Java使用Curator进行ZooKeeper操作的详细教程》ApacheCurator是一个基于ZooKeeper的Java客户端库,它极大地简化了使用ZooKeeper的开发工作,在分布式系统... 目录1、简述2、核心功能2.1 CuratorFramework2.2 Recipes3、示例实践3