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

 在开始写代码之前,我们要讲一下几个基础的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.

要转换的日期,分别可以是以下之一:数字(自纪元以来的毫秒数)、ISO 日期字符串、JavaScript 日期或 ComputedObject。

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

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

仅与字符串日期一起使用的可选时区

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

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

//先进行时间函数的确立,并添加波段,方便一会进行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');

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

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

 

 

 

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此星光明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值