Charts 更改从时间序列图下载CSV中的日期格式
我使用这个脚本生成NDVi与时间的关系图。问题是当我以CSV下载该系列时,日期格式很难使用,而且在所有观察中都不相同 原始CSV如下所示:Charts 更改从时间序列图下载CSV中的日期格式,charts,time-series,google-earth-engine,Charts,Time Series,Google Earth Engine,我使用这个脚本生成NDVi与时间的关系图。问题是当我以CSV下载该系列时,日期格式很难使用,而且在所有观察中都不相同 原始CSV如下所示: system:time_start,NDVI Mar 26, 2013,0.132 我需要的是将日期格式更改为2013-03-26(yyyy-mm-dd) 剧本 var roi = /* color: #98ff00 */ee.Geometry.Point([-72.18245324628742, -13.260203147923505]); var l8
system:time_start,NDVI
Mar 26, 2013,0.132
我需要的是将日期格式更改为2013-03-26(yyyy-mm-dd)
剧本
var roi = /* color: #98ff00 */ee.Geometry.Point([-72.18245324628742, -13.260203147923505]);
var l8toa = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT");
// This field contains UNIX time in milliseconds.
var timeField = 'system:time_start';
// Use this function to mask clouds in Landsat 8 imagery. (See https://landsat.usgs.gov/collectionqualityband)
var maskClouds = function(image) {var quality = image.select('BQA');
var cloud01 = quality.eq(61440);
var cloud02 = quality.eq(53248);
var cloud03 = quality.eq(28672);
var mask = cloud01.or(cloud02).or(cloud03).not();
return image.updateMask(mask);};
// Use this function to add variables for NDVI, time and a constant
// to Landsat 8 imagery.
var addVariables = function(image) {
// Compute time in fractional years since the epoch.
var date = ee.Date(image.get(timeField));
var years = date.difference(ee.Date('1970-01-01'), 'year');
// Return the image with the added bands.
return image
// Add an NDVI band.
.addBands(image.normalizedDifference(['B5', 'B4']).rename('NDVI')).float()
// Add a time band.
.addBands(ee.Image(years).rename('t').float())
// Add a constant band.
.addBands(ee.Image.constant(1));};
// Remove clouds, add variables and filter to the area of interest.
var filteredLandsat = l8toa .filterBounds(roi) .map(maskClouds) .map(addVariables);
// Plot a time series of NDVI at a single location.
var l8Chart = ui.Chart.image.series(filteredLandsat.select('NDVI'), roi)
.setChartType('ScatterChart')
.setOptions({title: 'Landsat 8 NDVI time series at ROI',trendlines: {0: {color: 'CC0000'
}},lineWidth: 1,pointSize: 3,
});
print(l8Chart);
使用
DATE\u ACQUIRED
作为xProperty
参数:
var l8Chart = ui.Chart.image.series({ imageCollection:filteredLandsat.select('NDVI'),
region:roi, xProperty:'DATE_ACQUIRED'})
.setChartType('ScatterChart')
.setOptions({title: 'Landsat 8 NDVI time series at ROI',trendlines: {0: {color: 'CC0000'
}},lineWidth: 1,pointSize: 3,
});