計算DMSP燈光數(shù)據(jù)的趨勢
主要功能
獲取1990年以來的燈光數(shù)據(jù),
代碼
// 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');
步驟分析
- 定義函數(shù),生成時序波段
- 生成數(shù)據(jù)集對象,選擇燈光數(shù)據(jù)
- 計算燈光數(shù)據(jù)變化趨勢
- 添加變化趨勢最大結果
- 設置地圖中心,縮放等級
- 添加圖層
主要方法
- 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
以對象形式返回指定的影像數(shù)據(jù)。
輸入?yún)?shù):輸入影像對象
- 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
返回兩個輸入時間間的差值,使用指定的單位,返回結果是浮點型的。
輸入?yún)?shù):輸入時間對象,開始(時間對象),單位(字符串)
- 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
在數(shù)據(jù)集內(nèi)的所有數(shù)據(jù)上執(zhí)行指定函數(shù)。
輸入?yún)?shù):輸入數(shù)據(jù)集對象,算法(指定的函數(shù)),是否允許返回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
對數(shù)據(jù)集中的所有數(shù)據(jù)應用一個reducer。如果reducer只需要一個數(shù)據(jù),則對每一個數(shù)據(jù)都執(zhí)行該操作;否則,必須與數(shù)據(jù)集中數(shù)據(jù)個數(shù)相同的輸入?yún)?shù)個數(shù)。
輸入?yún)?shù):數(shù)據(jù)集對象,reducer,并行尺度(限制內(nèi)存使用量)
- 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對象,用于計算坡度和加權的偏移量