首页 > 其他分享 >GEE ——errors & debuggings (2023GEE峰会总结)

GEE ——errors & debuggings (2023GEE峰会总结)

时间:2023-11-14 14:33:20浏览次数:29  
标签:debuggings errors return ee image aside collection GEE print


简介:

在gee中有三种错误,一种就是系统错误,也就是我们看到的会在JavaScript code editor中出现的错误,也就是在程序还没有启动之前就会提示的错误,而客户端错误则主要是会提示一些在代码过程中的错误,比如说没出现过的变量名称,另外就是服务器出席那的错误,也就是说,你的代码和你索要运行的结果之间的错误,比如说,原本这个影像中是没有这个波段的,但是你却使用了,或者说你输入的波段名称不对而导致的错误。所有的这里显示的错误就如下面这张图所显示的。

GEE ——errors & debuggings (2023GEE峰会总结)_数据

bug解决方案:

这里针对debug的解决方法无非就是限制性输出,也就是减少控制台输出的量,另外我们会使用到下面的一些函数来实现这个功能。

函数:

ee.Filter(filter)

Constructs a new filter. This constructor accepts the following args:

  • Another filter.
  • A list of filters (which are implicitly ANDed together).
  • A ComputedObject returning a filter. Users shouldn't be making these; they're produced by the generator functions below.

Arguments:

filter (Filter|List<Object>|Object, optional):

Optional filter to add.

Returns: Filter

first()

Returns the first entry from a given collection.

Arguments:

this:collection (FeatureCollection):

The collection from which to select the first entry.

Returns: Element

limit(max, propertyascending)

Limit a collection to the specified number of elements, optionally sorting them by a specified property first.

Returns the limited collection.

Arguments:

this:collection (Collection):

The Collection instance.

max (Number):

The number to limit the collection to.

property (String, optional):

The property to sort by, if sorting.

ascending (Boolean, optional):

Whether to sort in ascending or descending order. The default is true (ascending).

Returns: Collection

aside(func, var_args)

Calls a function passing this object as the first argument, and returning itself. Convenient e.g. when debugging:调用一个函数,将此对象作为第一个参数,并返回自身。例如,在调试时非常方便:

var c = ee.ImageCollection('foo').aside(print)

.filterDate('2001-01-01', '2002-01-01').aside(print, 'In 2001')

.filterBounds(geom).aside(print, 'In region')

.aside(Map.addLayer, {min: 0, max: 142}, 'Filtered')

.select('a', 'b');

Returns the same object, for chaining.

Arguments:

this:computedobject (ComputedObject):

The ComputedObject instance.

func (Function):

The function to call.

var_args (VarArgs<Object>):

Any extra arguments to pass to the function.

Returns: ComputedObject

GEE ——errors & debuggings (2023GEE峰会总结)_gee_02

这里重点说一下aside函数,这个功能就是在你执行程序每一步的时候都可以一步步的让其输出到控制台中,最后到底检查时哪一行代码出现了问题:

var c = ee.ImageCollection('foo').aside(print)

.filterDate('2001-01-01', '2002-01-01').aside(print, 'In 2001')

.filterBounds(table).aside(print, 'In region').aside(print, 'xxxx')

.aside(Map.addLayer, {min: 0, max: 142}, 'Filtered')

.select('a', 'b');

print(c)

 

GEE ——errors & debuggings (2023GEE峰会总结)_gee_03

我们看一下简单的错误:

Early Errors -Corrected

image.set(days,image.get('system:time_start')/(60*60*24*1000))

Result Capture

image =image.set(.)

Casting

ee.Number(image.get('system:time_start'))

or

image.getNumber('system:time_start')

Javascript Operators   image.getNumber(.).divide(60*60*24**1000)

GEE ——errors & debuggings (2023GEE峰会总结)_数据_04

 

MAP function 错误

这里的map不能使用print或者getinfo或者export等函数的操作。

Return a Value

function(x){y=x.add(1);}

User-defined methods must return a value

Return an Element

function(x){return x.date()}

Collection.map:A mapped algorithm must return a Feature or Image.

Using getlnfo or print

function(x){return x.set('y',x.date().getInfo())}

Line 1:A mapped function's arguments cannot be used in client-side operation

Javascript branching

if(i==0){return 1 }else {return 2 }

Mapped Aggregations function(x){return x.reduceRegion({...maxPixels:1e9})}

GEE ——errors & debuggings (2023GEE峰会总结)_gee_05

GEE ——errors & debuggings (2023GEE峰会总结)_数据_06

 

GEE ——errors & debuggings (2023GEE峰会总结)_错误_07

Scaling Issues

Error:Image.reduceRegions:Computed value is too large.

Error:Image.classify:Feature null has a non-numeric value for property B1.Task timed out after 7200 seconds.

另外一些函数在使用过程中也指的注意:

How l Debug Your Code -my checklist

Low Hanging Fruit

getlnfo()

for loops

iterate()

toList()

Complex geometries

Don't clip

image.reduceToVectors()

image.reproject()

image.resample()

image.reduceResolution()

Joins

Collections

filterDate /filterBounds

calendarRange()without filterDate()

collection.geometry()

toBands()/toArray()

Aggregations

Tilescale in reduce*Combine reducers

image.reduceNeighborhood()

Neighborhood size使用较小的pixels作为参数

Use optimizations

How I Debug Your Code -my checklist

Distances

use fastDistanceTransform()

/ee.Image.pixelArea().sqrt()

Geometries

Specify an error marginSimplify if possible

bounds()vs.drawing a box

Discard them completely

Pre-caching before sampling

Classifier size(trees,training)

Never use Math.random()

 错误代码示范:

https://code.earthengine.google.com/34bdb87a407011a6c9b821fad47d7987

 

GEE ——errors & debuggings (2023GEE峰会总结)_gee_08

var l8 = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2").limit(400);

function reduceBands(x, acc) {
    return ee.Image(acc).addBands(x);
}

var iterateVersion = ee.Image(l8.iterate(reduceBands, ee.Image()));
print('Iterate: image has', iterateVersion.bandNames().length(), 'bands');

var toBandsVersion = l8.toBands();
print('toBands: image has', toBandsVersion.bandNames().length(), 'bands');

标签:debuggings,errors,return,ee,image,aside,collection,GEE,print
From: https://blog.51cto.com/u_15654855/8368808

相关文章

  • GEE错误——XXX is not a function,如何解决这个问题?
    错误:这里的时错误原始的代码链接:https://code.earthengine.google.com/4bf0975a41e14d0c40e01925c6f3cf2a这里主要的问题时这个单一影像不存在:ImageCollection(Error)ImageCollection.load:ImageCollectionasset'LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411'notfound(does......
  • GEE数据集——2019、2020、2021、2022和2023年全球固定宽带和移动(蜂窝)网络性能Shapefi
    全球固定宽带和移动(蜂窝)网络性能¶全球固定宽带和移动(蜂窝)网络性能,分配给缩放级别16网络墨卡托图块(赤道处约610.8米x610.8米)。数据以Shapefile格式和ApacheParquet格式提供,其几何形状以众所周知的文本(WKT)表示,投影在EPSG:4326中。下载速度、上传速度和延迟是通过......
  • 编程最佳外挂:批量数据分析与可视化,CodeGeeX工具箱一键完成
    ChatGLM3代模型的CodeInterpreter能力,本周已经在VSCode里的CodeGeeX插件产品中,以开发者工具箱的产品形态上线。下图以VSCode插件为例:在CodeGeeX的侧边栏,和智能问答AskCodeGeeX并列出现的工具箱标签,用户登录后就可以直接打开使用。CodeInterpreter曾被称为ChatGPT最强外挂。现......
  • cc1: all warnings being treated as errors报错处理
    cmake时一切正常,make时产生了报错,并且解释为`cc1:allwarningsbeingtreatedaserrors`一些网上的方法是在Makefile文件里删除`-Werror`,但我的Makefile文件不存在这个选项。我的解决方法:在CMakeLists里寻找配置'-Werror'的语句,将这些涉及的语句删除。并且删除之前cmake......
  • Node opensslErrorStack 错误解决方法记录
    从Git仓库中下载了一个老项目,使用npminstall安装后没有问题,当我使用npmrundev的时候遇到了OpenSSL相关错误,例如opensslErrorStack:['error:03000086:digitalenveloperoutines::initializationerror']网上找了一下相关信息,然后顺利解决了,记录分享给大家问题原因:这种错......
  • WPF开发的小巧、美观桌面快捷工具GeekDesk开源项目--极客桌面
    今天给大家推荐一个基于WPF开发的,专门为程序员定制的桌面快捷工具。项目简介这是基于.Net+WPF开发的,一个小巧、UI美观的快捷工具。此项目发布以来就受到大家的喜欢,代码结构清晰非常适合用来学习。项目还在持续迭代中,有部分小问题,用来学习、体验完全没问题。作者一直在迭代升级......
  • Continue SQL query even on errors
    trymysql--force<sample_data.sqlMysqlhelpsectionsays -f,--force        Continueevenifwegetansqlerror.----------------------YoucouldalsouseINSERTIGNOREINSERTIGNOREINTOmytable (primaryKey,field1,field2)VALUES ('1',1,2......
  • 2023PKU GeekGame Web wp
    2023PKUGeekGameWebwp第三新XSS巡猎查看源码我们可以知道可以在body的部分插入代码触发xss漏洞,根据题目给出的提示可以知道需要创建一个元素指向/admin/路径,然后通过document读取目标的cookies。<iframesrc="/admin/"id="barframe"></iframe><script>setTimeout(()=>......
  • CodeGeeX vscode代码提示,智能问答
    CodeGeeX官网https://codegeex.cn/zh-CN/CodeGeeXvscode代码提示,智能问答---------------------------------------------生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!https://pengchenggang.gitee.io/navigator/SMART原则:目标必须是具体的(Spec......
  • 【GEE】Google Earth Engine(GEE)注册详细教程&无需教育邮箱
    ​    这个专栏真的是纠结了很久,不知道到底要不要分享自己在学习GEE的时候的一些经验和代码。因为本人在日常中使用Python和ENVI多点,虽然GEE也会用但不至于频繁使用,同时针对GEE其实官网给出了很多接口的使用方法,国内外也有很多人分享过一些实操代码,因此大部分代码可能都......