前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GEE ——errors & debuggings (2023GEE峰会总结)

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

作者头像
此星光明
发布2024-02-02 09:34:18
1270
发布2024-02-02 09:34:18
举报

简介:

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

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, property, ascending)

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

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

代码语言:javascript
复制
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)

我们看一下简单的错误:

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)

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})}

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

代码语言:javascript
复制
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');
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-02-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介:
  • bug解决方案:
    • ee.Filter(filter)
      • Arguments:
      • Returns: Filter
    • first()
      • Arguments:
      • Returns: Element
    • limit(max, property, ascending)
      • Arguments:
      • Returns: Collection
    • aside(func, var_args)
      • Arguments:
      • Returns: ComputedObject
    • Scaling Issues
    • 错误代码示范:
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档