GEE错误——PCA系数变换的时候出现的错误

目录

错误提示1

错误提示2

原始的教程链接:

错误代码

修正后的代码 

结果


错误提示1

这个是因为原始GEE教程中给的让我们填入需要进行计算的波段名称,而且是以list的形式传入。

错误提示2

这里我们虽然传入了正确的波段名称,但是发现要求的list要多一个中括号,所以我们再次修改代码。

原始的教程链接:

https://developers.google.com/earth-engine/guides/arrays_eigen_analysis#code-editor-javascript

错误代码

var roi = /* color: #d63000 *//* displayProperties: [{"type": "rectangle"}] */ee.Geometry.Polygon([[[-80.39442194432449, 25.89616042988596],[-80.39442194432449, 25.698332029213574],[-80.21864069432449, 25.698332029213574],[-80.21864069432449, 25.89616042988596]]], null, false);var getPrincipalComponents = function(centered, scale, region) {// Collapse the bands of the image into a 1D array per pixel.var arrays = centered.toArray();// Compute the covariance of the bands within the region.var covar = arrays.reduceRegion({reducer: ee.Reducer.centeredCovariance(),geometry: region,scale: scale,maxPixels: 1e9});// Get the 'array' covariance result and cast to an array.// This represents the band-to-band covariance within the region.var covarArray = ee.Array(covar.get('array'));// Perform an eigen analysis and slice apart the values and vectors.var eigens = covarArray.eigen();// This is a P-length vector of Eigenvalues.var eigenValues = eigens.slice(1, 0, 1);// This is a PxP matrix with eigenvectors in rows.var eigenVectors = eigens.slice(1, 1);// Convert the array image to 2D arrays for matrix computations.var arrayImage = arrays.toArray(1);// Left multiply the image array by the matrix of eigenvectors.var principalComponents = ee.Image(eigenVectors).matrixMultiply(arrayImage);// Turn the square roots of the Eigenvalues into a P-band image.var sdImage = ee.Image(eigenValues.sqrt()).arrayProject([0]).arrayFlatten([getNewBandNames('sd')]);// Turn the PCs into a P-band image, normalized by SD.return principalComponents// Throw out an an unneeded dimension, [[]] -> []..arrayProject([0])// Make the one band array image a multi-band image, [] -> image..arrayFlatten([getNewBandNames('pc')])// Normalize the PCs by their SDs..divide(sdImage);
};var image = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(roi).filterDate('2020-01-01','2020-03-01').mosaic().select(['B2', 'B3', 'B4', 'B5', 'B6', 'B7'])var centered = image.subtract(image.reduceRegion({'reducer': ee.Reducer.mean(), 'geometry': roi, 'scale': 30, 'maxPixels': 1e13}))var principal_components = getPrincipalComponents(image, 30, roi)print('principal_components',principal_components)

修正后的代码 

var roi = /* color: #d63000 *//* displayProperties: [{"type": "rectangle"}] */ee.Geometry.Polygon([[[-80.39442194432449, 25.89616042988596],[-80.39442194432449, 25.698332029213574],[-80.21864069432449, 25.698332029213574],[-80.21864069432449, 25.89616042988596]]], null, false);var getPrincipalComponents = function(centered, scale, region) {// Collapse the bands of the image into a 1D array per pixel.var arrays = centered.toArray();// Compute the covariance of the bands within the region.var covar = arrays.reduceRegion({reducer: ee.Reducer.centeredCovariance(),geometry: region,scale: scale,maxPixels: 1e9});// Get the 'array' covariance result and cast to an array.// This represents the band-to-band covariance within the region.var covarArray = ee.Array(covar.get('array'));// Perform an eigen analysis and slice apart the values and vectors.var eigens = covarArray.eigen();// This is a P-length vector of Eigenvalues.var eigenValues = eigens.slice(1, 0, 1);// This is a PxP matrix with eigenvectors in rows.var eigenVectors = eigens.slice(1, 1);// Convert the array image to 2D arrays for matrix computations.var arrayImage = arrays.toArray(1);// Left multiply the image array by the matrix of eigenvectors.var principalComponents = ee.Image(eigenVectors).matrixMultiply(arrayImage);// Turn the square roots of the Eigenvalues into a P-band image.var sdImage = ee.Image(eigenValues.sqrt()).arrayProject([0]).arrayFlatten([['B2_sd', 'B3_sd', 'B4_sd', 'B5_sd', 'B6_sd', 'B7_sd']]);// Turn the PCs into a P-band image, normalized by SD.return principalComponents// Throw out an an unneeded dimension, [[]] -> []..arrayProject([0])// Make the one band array image a multi-band image, [] -> image..arrayFlatten([['B2_pc', 'B3_pc', 'B4_pc', 'B5_pc', 'B6_pc', 'B7_pc']])// Normalize the PCs by their SDs..divide(sdImage);
};var image = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA').filterBounds(roi).filterDate('2020-01-01','2020-03-01').mosaic().select(['B2', 'B3', 'B4', 'B5', 'B6', 'B7'])var centered = image.subtract(image.reduceRegion({'reducer': ee.Reducer.mean(), 'geometry': roi, 'scale': 30, 'maxPixels': 1e13}))var principal_components = getPrincipalComponents(image, 30, roi)print('principal_components',principal_components)

结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/64123.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#代码实现把中文录音文件(.mp3 .wav)转为文本文字内容

我们有一个中文录音文件.mp3格式或者是.wav格式,如果我们想要提取录音文件中的文字内容,我们可以采用以下方法,不需要使用Azure Speech API 密钥注册通过离线的方式实现。 1.首先我们先在NuGet中下载两个包 NAudio 2.2.1、Whisper.net 1.7.3…

【py脚本+logstash+es实现自动化检测工具】

概述 有时候,我们会遇到需要查看服务器的网络连接或者内存或者其他指标是否有超时,但是每次需要登录到服务器查看会很不方便,所以我们可以设置一个自动脚本化工具自动帮助我们查看,下面我做了一个demo在windows上面。 一、py脚本 import s…

计算机操作系统与安全复习笔记

1 绪论 操作系统目标: 方便性; 有效性; 可扩充性; 开放性. 作用: 用户与计算机硬件系统之间的接口; 计算机资源的管理者; 实现了对计算机资源的抽象; 计算机工作流程的组织者. 多道程序设计: 内存中同时存放若干个作业, 使其共享系统资源且同时运行; 单处理机环境下宏观上并行…

qt5.12.11+msvc编译器编译qoci驱动

1.之前编译过minGW编译器编译qoci驱动,很顺利就完成了,文章地址:minGW编译qoci驱动详解,今天按照之前的步骤使用msvc编译器进行编译,直接就报错了: 查了些资料,发现两个编译器在编译时,pro文件中引用的库不一样,下面是msvc编译器引用的库,其中编译引用的库我这里安装…

Java爬虫实战:深度解析VIP商品详情获取技术

在数字化时代,数据的价值不言而喻。对于电商平台而言,掌握VIP商品的详细信息是提升服务质量、优化用户体验的关键。然而,这些信息往往被复杂的网页结构和反爬虫策略所保护。本文将带你深入了解如何使用Java编写爬虫,以安全、高效地…

校史馆云展厅适合远程教学吗?

随着信息技术的飞速发展,远程教学已经成为教育领域的一个重要趋势。 校史馆作为学校文化传承的重要场所,承载着丰富的历史信息和教育资源。 那么,将校史馆搬到云端,构建云展厅,是否适合远程教学呢? 下面…

一些elasticsearch重要概念与配置参数

ES 是在 lucene 的基础上进行研发的,隐藏了 lucene 的复杂性,提供简单易用的 RESTful Api接口。ES 的分片相当于 lucene 的索引。 Node 节点的几种部署实例 实例一: 只用于数据存储和数据查询,降低其资源消耗率 node.master: false node.da…

交换机与路由器的区别

交换机和路由器是网络中的两种关键设备,它们各自承担不同的功能,主要区别体现在以下几个方面: 一、工作层次与功能 交换机: 工作层次:交换机主要工作在OSI模型的第二层,即数据链路层。 功能:交…

Go Energy 跨平台框架 v2.5.1 发布

Energy 框架 是Go语言基于CEF 和 LCL 开发的跨平台 GUI 框架, 具体丰富的系统原生 UI 控件集, 丰富的 CEF 功能 API,简化且不失功能的 CEF 功能 API 使用。 特性? 特性描述跨平台支持 Windows, macOS, Linux简单Go语言的简单特性,使用简单…

宏转录组+HiFi宏基因组:揭示厌氧消化中的碳流和能量转换

厌氧消化是一种重要的工程生物技术,对有机废物的资源回收和可再生能源的生产起着关键作用。然而,由于对未培养的厌氧菌及其适应环境变化的能力了解有限,这限制了该技术的优化和生物气生产的可持续性。今天小编带大家看一篇发表在《Microbiome…

PVE虚拟化平台之开启温度显示方法

PVE虚拟化平台之开启温度显示方法 一、PVE平台介绍1.1 PVE简介1.2 PVE特点1.3 PVE主要使用场景二、本次实践介绍2.1 环境介绍2.2 本次实践简介2.3 检查PVE状态三、pvetools介绍3.1 pvetool简介3.2 功能概览四、使用pvetools工具4.1 下载pvetools项目4.2 执行脚本五、一键安装脚…

C++中的命名规范:定义、用途与最佳实践

C中的命名规范:定义、用途与最佳实践 在软件开发中,命名规范(Naming Conventions)是指为变量、函数、类、命名空间等代码实体统一制定的命名规则和风格。对于C编程语言而言,遵循良好的命名规范不仅能够提升代码的可读…

SpringCloud 运用(2)—— 跨服务调度

上一篇:SpringCloud 入门(1)—— nacos 注册中心-CSDN博客 1.RestTemplate 跨服务请求 RestTemplate 是 Spring 框架中的一个同步客户端,用于与 HTTP 服务进行交互。它简化了与 HTTP 服务器通信的过程,并且提供了对多…

解决Springboot整合Shiro自定义SessionDAO+Redis管理会话,登录后不跳转首页

解决Springboot整合Shiro自定义SessionDAORedis管理会话,登录后不跳转首页 问题发现问题解决 问题发现 在Shiro框架中,SessionDAO的默认实现是MemorySessionDAO。它内部维护了一个ConcurrentMap来保存session数据,即将session数据缓存在内存…

java历史版本信息

Java是由Sun Microsystems(后被Oracle公司收购)于1995年推出的面向对象程序设计语言和Java平台的总称。到目前为止,Java已经发布了多个版本,以下是Java的主要版本及其发布时间。 一般来说,LTS版本(长期支持…

windows nmake 安装openssl

windows nmake 编译和安装 openssl 本文提供了在Windows环境下安装OpenSSL的详细步骤,包括下载Perl、NASM和VisualStudio,配置环境变量,使用PerlConfigure设置平台,通过nmake进行编译、测试和安装。整个过程涉及32位和64位版本的选…

Spring Boot应用开发实战:从入门到精通

一、Spring Boot 简介 1.1 什么是 Spring Boot? Spring Boot 是一个开源框架,旨在简化新 Spring 应用的初始搭建以及开发过程。它构建在 Spring 框架之上,利用了 Spring 的核心特性,如依赖注入(Dependency Injection&…

一、Hadoop概述

文章目录 一、Hadoop是什么二、Hadoop发展历史三、Hadoop三大发行版本1. Apache Hadoop2. Cloudera Hadoop3. Hortonworks Hadoop四、Hadoop优势1. 高可靠性2. 高扩展性3. 高效性4. 高容错性五、Hadoop 组成1. Hadoop1.x、2.x、3.x区别2. HDFS 架构概述3. YARN 架构概述4. MapR…

python版本的Selenium的下载及chrome环境搭建和简单使用

针对Python版本的Selenium下载及Chrome环境搭建和使用,以下将详细阐述具体步骤: 一、Python版本的Selenium下载 安装Python环境: 确保系统上已经安装了Python 3.8及以上版本。可以从[Python官方网站]下载并安装最新版本的Python,…

vue---- H5页面 pdf,docx,excel文件预览下载功能

vue---- H5页面 pdf,docx,excel文件预览&&下载功能 pdf,docx,excel文件预览&&下载适用于vue2和vue3,示例为vue3 1.npm下载这些文件的插件(选择自己需要预览的进行下载) 安装pd…