前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >GEE(Google Earth Engine)计算全球100年的夜间灯光数据!

GEE(Google Earth Engine)计算全球100年的夜间灯光数据!

作者头像
此星光明
发布2024-02-01 19:55:56
发布2024-02-01 19:55:56
26000
代码可运行
举报
运行总次数:0
代码可运行

 在开始写代码之前,我们要讲一下几个基础的GEE中内置的一些用法:

ee.Date(date, tz)

Constructs a new Date object.构造一个新的时间对象

Arguments:

date (ComputedObject|Date|Number|String):计算的数据类型包括了哪些

The date to convert, one of: a number (number of milliseconds since the epoch), an ISO Date string, a JavaScript Date or a ComputedObject.

代码语言:javascript
代码运行次数:0
复制
要转换的日期,分别可以是以下之一:数字(自纪元以来的毫秒数)、ISO 日期字符串、JavaScript 日期或 ComputedObject。

tz (String, optional):时区的选择,一般情况下可以忽略。

An optional timezone only to be used with a string date.

代码语言:javascript
代码运行次数:0
复制
仅与字符串日期一起使用的可选时区
Returns: Date

difference(start, unit)

Returns the difference between two Dates in the specified units; the result is floating-point and based on the average length of the unit.

以指定单位返回两个日期之间的差值;结果是浮点数并基于单位的平均长度。一般情况下输入你的开始时间和你要精确到的单位。

Arguments:

this:date (Date)

start (Date)

unit (String):

One of 'year', 'month' 'week', 'day', 'hour', 'minute', or 'second'.

Returns: Float

ee.Reducer.linearFit()

Returns a Reducer that computes the slope and offset for a (weighted) linear regression of 2 inputs. The inputs are expected to be x data followed by y data..

这个就相当于计算斜率,根据你输入的x值来改变Y的变化,

No arguments.
Returns: Reducer

好了接下来进行代码分析:

代码语言:javascript
代码运行次数:0
复制
//先进行时间函数的确立,并添加波段,方便一会进行map遍历分析
function createTimeBand(img) {
  var year = img.date().difference(ee.Date('1990-01-01'), 'year');
  return ee.Image(year).float().addBands(img);
}

// Fit a linear trend to the nighttime lights collection.
var collection = ee.ImageCollection('NOAA/DMSP-OLS/CALIBRATED_LIGHTS_V4')
    .select('avg_vis')
    .map(createTimeBand);
//通过ee.Reducer.linearFit()来计算其变化趋势
var fit = collection.reduce(ee.Reducer.linearFit());

//选择第一张影像进行分析和展示
// Display a single image
Map.addLayer(ee.Image(collection.select('avg_vis').first()),
         {min: 0, max: 63},
         'stable lights first asset');

// Display trend in red/blue, brightness in green.
//展示变化趋势,分别用'scale', 'offset', 'scale'三个波段来进行颜色区分
Map.setCenter(30, 45, 4);
Map.addLayer(fit,
         {min: 0, max: [0.18, 20, -0.18], bands: ['scale', 'offset', 'scale']},
         'stable lights trend');

这是分析的第一张影像结果图

再来看看咱们大中国的变化:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-02-01,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Arguments:
  • Returns: Date
  • Arguments:
  • Returns: Float
  • No arguments.
  • Returns: Reducer
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档