计算DMSP灯光数据的趋势
主要功能
获取1990年以来的灯光数据,
代码
// Compute the trend of nighttime lights from DMSP.
// Add a band containing image date as years since 1990.
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);
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.
Map.setCenter(30, 45, 4);
Map.addLayer(fit,
{min: 0, max: [0.18, 20, -0.18], bands: ['scale', 'offset', 'scale']},
'stable lights trend');
步骤分析
- 定义函数,生成时序波段
- 生成数据集对象,选择灯光数据
- 计算灯光数据变化趋势
- 添加变化趋势最大结果
- 设置地图中心,缩放等级
- 添加图层
主要方法
- ee.Image.date()
Returns the acquisition time of an image as a Date object. This helper function is equivalent to ee.Date(image.get('system:time_start')).
Arguments:
this:image (Image):
The image whose acquisition time to return.
Returns: Date
以对象形式返回指定的影像数据。
输入参数:输入影像对象
- ee.Date.difference()
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.ImageCollection.map()
Maps an algorithm over a collection.
Returns the mapped collection.
Arguments:
this:collection (Collection):
The Collection instance.
algorithm (Function):
The operation to map over the images or features of the collection. A JavaScript function that receives an image or features and returns one. The function is called only once and the result is captured as a description, so it cannot perform imperative operations or rely on external state.
dropNulls (Boolean, optional):
If true, the mapped algorithm is allowed to return nulls, and the elements for which it returns nulls will be dropped.
Returns: Collection
在数据集内的所有数据上执行指定函数。
输入参数:输入数据集对象,算法(指定的函数),是否允许返回NULL(布尔型)
- ee.ImageCollection.reduce()
Applies a reducer across all of the images in a collection.
If the reducer has a single input, it will be applied separately to each band of the collection; otherwise it must have the same number of inputs as the collection has bands.
The reducer output names determine the names of the output bands: reducers with multiple inputs will use the output names directly, while reducers with a single input will prefix the output name with the input band name (e.g. '10_mean', '20_mean', etc.).
Arguments:
this:collection (ImageCollection):
The image collection to reduce.
reducer (Reducer):
The reducer to apply to the given collection.
parallelScale (Float, default: 1):
A scaling factor used to limit memory use; using a larger parallelScale (e.g. 2 or 4) may enable computations that run out of memory with the default.
Returns: Image
对数据集中的所有数据应用一个reducer。如果reducer只需要一个数据,则对每一个数据都执行该操作;否则,必须与数据集中数据个数相同的输入参数个数。
输入参数:数据集对象,reducer,并行尺度(限制内存使用量)
- ee.Reducer.linearFit()
Returns a Reducer that computes the slope and offset for a (weighted) linear regression of 2 inputs.
No arguments.
Returns: Reducer
返回一个reduce对象,用于计算坡度和加权的偏移量