Google Earth Engine(GEE)——如何获取指定时间范围的影像值并进行图表展示(指定天数范围内的时序图)

很多时候我们可以直接进行影像图表的加载,但是如何获取不同天数,或者给了指定的时间节点,如何获取这个指定时间范围内的月或者日的结果,从而正确的加载影像波段值的图表。我们需要了解几个函数:

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.

返回两个Date在指定单位中的差值;结果是浮点的,基于单位的平均长度。

Arguments:

this:date (Date)

start (Date)

unit (String):

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

Returns: Float

advance(delta, unit, timeZone)//这个是进行日期的设定,按照年月日等格式

Create a new Date by adding the specified units to the given Date.

通过向给定的日期添加指定的单位来创建一个新的日期。 

Arguments:

this:date (Date)

delta (Float)

unit (String):

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

timeZone (String, default: null):

The time zone (e.g. 'America/Los_Angeles'); defaults to UTC.

Returns: Date

ui.Chart.image.series(imageCollection, region, reducerscalexProperty)

Generates a Chart from an ImageCollection. Plots derived values of each band in a region across images. Usually a time series.

  • X-axis: Image, labeled by xProperty value.

  • Y-axis: Band value.

  • Series: Band names.

Returns a chart.

Arguments:

imageCollection (ImageCollection):

An ImageCollection with data to be included in the chart.

region (Feature|FeatureCollection|Geometry):

The region to reduce.

reducer (Reducer, optional):

Reducer that generates the values for the y-axis. Must return a single value. Defaults to ee.Reducer.mean().

scale (Number, optional):

Scale to use with the reducer in meters.

xProperty (String, optional):

Property to be used as the label for each image on the x-axis. Defaults to 'system:time_start'.

Returns: ui.Chart

 

代码:

var startDate = ee.Date('2022-01-01'); // set start time for analysis
var endDate = ee.Date('2022-12-31'); // set end time for analysis
var nDays = ee.Number(endDate.difference(startDate,'day')).round();

// coordinate Arpat Ponte alle Mosse
//var point = ee.Geometry.Point([11.230520538799576, 43.78480193916678]);

// Signa 11.097849 43.793234
//https://www.arpat.toscana.it/temi-ambientali/aria/qualita-aria/rete_monitoraggio/scheda_stazione/FI-SIGNA
var point = ee.Geometry.Point([11.097849, 43.793234]);
Map.setCenter(11.097849, 43.793234,14);


var chirps = ee.ImageCollection('COPERNICUS/S5P/NRTI/L3_O3')
            .select('O3_column_number_density')
            .filterBounds(point)
            .filterDate(startDate, endDate)
            .map(function(image){return image.clip(point)}) ;

      
//这个关键地方,,是需要我们建立一个时序,然后获取每一天的值,这里最主要的时间函数的运用,以及影像系统时间的设定
var byday = ee.ImageCollection(
  // map over each day
  ee.List.sequence(0,nDays).map(function (n) {
    var ini = startDate.advance(n,'day');
    // advance just one day
    var end = ini.advance(1,'day');
    return chirps.filterDate(ini,end)
                .select(0).mean()
                .set('system:time_start', ini);
}));



// plot full time series
print(
  ui.Chart.image.series({
    imageCollection: byday,
    region: point,
    scale: 1
  }).setOptions({title: 'O3 Signa 2020 mol/m2'})
);

Export.table.toDrive({
        collection: chirps,
        description: 'O3', 
    fileNamePrefix: 'O3', 
    fileFormat: 'CSV'
    });

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用Google Earth Engine获取逐日NDVI的代码示例: ```javascript // 设置ROI var roi = ee.Geometry.Rectangle([xmin, ymin, xmax, ymax]); // 设置起始和结束日期 var startDate = ee.Date('2019-01-01'); var endDate = ee.Date('2019-12-31'); // 加载MODIS数据 var modis = ee.ImageCollection('MODIS/006/MOD13A1') .filterBounds(roi) .filterDate(startDate, endDate) .select('NDVI'); // 定义函数计算每个图像的年份和日数 var addDate = function(image) { var doy = image.date().getRelative('day', 'year'); return image.addBands(doy).addBands(image.date().get('year')); }; // 对图像集应用函数 var modisWithDate = modis.map(addDate); // 定义函数计算每个年份和日数的平均NDVI var reduceDaily = function(imageCollection, year, doy) { var filtered = imageCollection.filter(ee.Filter.calendarRange(year, year, 'year')) .filter(ee.Filter.calendarRange(doy, doy, 'day_of_year')); return filtered.mean().set('year', year).set('doy', doy); }; // 创建一个二维数组,其中第一维表示年份,第二维表示一年中的日数 var years = ee.List.sequence(startDate.get('year'), endDate.get('year')); var days = ee.List.sequence(1, 365); // 对所有年份和日数应用reduceDaily函数 var dailyNDVI = ee.ImageCollection.fromImages(years.map(function(y){ return days.map(function(d){ return reduceDaily(modisWithDate, y, d); }); }).flatten()); // 打印输出结果 print(dailyNDVI); ``` 在上述代码中,首先定义了一个感兴趣区域(ROI),然后加载了2000年至今的MODIS NDVI数据,并对其进行了筛选。接着定义了两个函数,一个函数用于向每个图像添加年份和日数作为带宽,另一个函数用于计算每个年份和日数的平均NDVI。最后,将所有年份和日数应用到reduceDaily函数中,生成逐日的NDVI

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

此星光明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值