Google Earth Engine(GEE)——数组及其切片简介

简介: Google Earth Engine(GEE)——数组及其切片简介

Earth Engine 表示 1-D 向量、2-D 矩阵、3-D 立方体和具有该ee.Array类型的更高维超立方体。数组是一种灵活的数据结构,但为了换取它们提供的强大功能,它们的伸缩性不如地球引擎中的其他数据结构。如果问题可以在不使用数组的情况下解决,那么结果的计算速度会更快、效率更高。但是,如果问题需要更高维度的模型、灵活的线性代数或任何其他数组特别适合的东西,则可以使用Array该类。

这里官方给出了一个简单的教学方案:

https://youtu.be/-qo8L5GmKO0


数组维度、形状和大小

数组的维数是指底层数据沿其变化的轴数。例如,0-D 数组是标量数,1-D 数组是向量,2-D 数组是矩阵,3-D 数组是立方体,>3-D 数组是超立方体。对于一个 N 维数组,从 0 到 N-1 有 N 个轴。阵列的形状由轴的长度决定。轴的长度是沿它的位置数。数组大小或数组中的总元素数等于轴长度的乘积。每个轴上每个位置的每个值都必须有一个有效数字,因为当前不支持稀疏或参差不齐的数组。数组的元素类型表示每个元素是什么类型的数字;数组的所有元素都将具有相同的类型。

Earth Engine 中的数组由数字列表和列表列表构成。嵌套的程度决定了维数。要从一个简单的、有动机的示例开始,请考虑以下Array从 Landsat 5 tasseled cap (TC) 系数(Crist 和 Cicone 1984)创建的案例:

函数:

length()

返回一个一维 EEArray,其中包含给定 EEArray 的每个维度的长度。无论你输入的是几个维度的数据,最终的结果都会显示为一个列表集合的一维数组

Returns a 1-D EEArray containing the length of each dimension of the given EEArray.


Arguments:

this:array (Array):

The array from which to extract the axis lengths.


Returns: Array

//创建一个缨帽系数数组
var coefficients = ee.Array([
  [0.3037, 0.2793, 0.4743, 0.5585, 0.5082, 0.1863],
  [-0.2848, -0.2435, -0.5436, 0.7243, 0.0840, -0.1800],
  [0.1509, 0.1973, 0.3279, 0.3406, -0.7112, -0.4572],
  [-0.8242, 0.0849, 0.4392, -0.0580, 0.2012, -0.2768],
  [-0.3280, 0.0549, 0.1075, 0.1855, -0.4357, 0.8085],
  [0.1084, -0.9022, 0.4120, 0.0573, -0.0251, 0.0238]
]);
//使用 确认这是一个 6x6 二维数组length(),它将返回每个轴的长度:
// 答应出来是一个维度,也就是6*6的格式,因为这里选取的是这个数组的长宽
print(coefficients.length()); //    [6,6]

下表说明了矩阵条目沿 0 轴和 1 轴的排列:0为竖轴,1为横轴。

1 轴 ->
0 1 2 3 4 5
0 0.3037 0.2793 0.4743 0.5585 0.5082 0.1863
1 -0.2848 -0.2435 -0.5436 0.7243 0.0840 -0.1800
0轴 2 0.1509 0.1973 0.3279 0.3406 -0.7112 -0.4572
3 -0.8242 0.0849 0.4392 -0.0580 0.2012 -0.2768
4 -0.3280 0.0549 0.1075 0.1855 -0.4357 0.8085
5 0.1084 -0.9022 0.4120 0.0573 -0.0251 0.0238


表格左侧的索引表示沿 0 轴的位置。0 轴上每个列表中的第 n 个元素位于 1 轴上的第 n 个位置。例如,数组坐标 [3,1] 处的条目是 0.0849。假设“绿色度”是感兴趣的 TC 分量。您可以使用slice()以下方法获得绿色子矩阵:

函数:

slice(axis, start, end, step)

通过以“step”为增量沿给定轴从“开始”(包括)到“结束”(不包括)切出每个位置来创建子数组。结果将具有与输入一样多的维度,并且在除切片轴之外的所有方向上都具有相同的长度,其中长度将是从“开始”到“结束”的“步长”范围内的位置数输入数组沿“轴”的长度。这意味着如果 start=end,或者如果开始或结束值完全超出范围,结果可以是沿给定轴的长度 0。


Creates a subarray by slicing out each position along the given axis from the 'start' (inclusive) to 'end' (exclusive) by increments of 'step'. The result will have as many dimensions as the input, and the same length in all directions except the slicing axis, where the length will be the number of positions from 'start' to 'end' by 'step' that are in range of the input array's length along 'axis'. This means the result can be length 0 along the given axis if start=end, or if the start or end values are entirely out of range.


Arguments:

轴(整数,默认值:0):
要切片的轴。
开始(整数,默认值:0):
第一个切片(包括)沿“轴”的坐标。负数用于相对于数组的末尾定位切片的开始,其中 -1 从轴上的最后一个位置开始,-2 从最后一个位置的下一个位置开始,依此类推。
结束(整数,默认值:空):
停止切片的坐标(独占)。默认情况下,这将是给定轴的长度。负数用于相对于数组的末尾定位切片的末尾,其中 -1 将排除最后一个位置,-2 将排除最后两个位置等。
步长(整数,默认值:1):
切片之间沿“轴”的间隔;将在从“开始”(包括)到“结束”(不包括)的“步”的每个整数倍处取一个切片。


this:array (Array):

Array to slice.

axis (Integer, default: 0):

The axis to slice on.

start (Integer, default: 0):

The coordinate of the first slice (inclusive) along 'axis'. Negative numbers are used to position the start of slicing relative to the end of the array, where -1 starts at the last position on the axis, -2 starts at the next to last position, etc.

end (Integer, default: null):

The coordinate (exclusive) at which to stop taking slices. By default this will be the length of the given axis. Negative numbers are used to position the end of slicing relative to the end of the array, where -1 will exclude the last position, -2 will exclude the last two positions, etc.

step (Integer, default: 1):

The separation between slices along 'axis'; a slice will be taken at each whole multiple of 'step' from 'start' (inclusive) to 'end' (exclusive). Must be positive.


Returns: Array

//获取 1x6 greenness切片,显示它。设置轴,设置切片的起始值,重点值和步长
var greenness = coefficients.slice({axis: 0, start: 1, end: 2, step: 1});
print(greenness);
//最后输出的结果:就是第2行数据
//[[-0.2848,-0.2435,-0.5436,0.7243,0.0840,-0.1800]]

注:观察startend参数slice() 对应于表中显示的 0 轴索引(start包含和end不包含)。我在函数当中标红了



相关文章
|
4月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
1942 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
4月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
193 0
|
4月前
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
GEE——Google dynamic world中在影像导出过程中无法完全导出较大面积影像的解决方案(投影的转换)EPSG:32630和EPSG:4326的区别
92 0
|
4月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
424 1
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
4月前
|
API Go 网络架构
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
241 4
|
4月前
|
机器学习/深度学习 存储 人工智能
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
202 3
|
4月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
71 0
|
4月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
100 0
|
4月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
59 0
|
4月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
174 0

热门文章

最新文章