I am processing the NASA NEX-GDDP data on google earth engine for a polygon. This data has three varibales: pr
, tasmin
, tasmax
and is daily resolution. For each day and variable, there are 21 images till 2005 and 42 from 2005 onwards.
My goal is to calculate monthly sum (for pr
) and monthly mean (for tasmin
and tasmax
) in each year for each variable for each grid located in the polygon for every single image in a day. Therefore, for a given variable, a single row in my final output should look like:
lat long month year ACCESS1-0' 'bcc-csm1-1' 'BNU-ESM' 'GFDL-ESM2M' ...... 'NorESM1-M'
8.125 108.875 1 1950 350 380 320 333 322
The approach I am adopting is to write out daily values for each lat lon for each variable and do the summing up in R. In order to write out daily values, I used the following approach
// define which variable I want
var myvar = 'pr'
// define my polygon
var polygon = ee.Geometry.Polygon([120, -6, 120, 8, 99, 8, 99, -6]);
// Define a start and end date
var startDate = ee.Date('2006-01-01');
var endDate = ee.Date('2018-01-01');
// Filter the image collection by date range, polygon and variable
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
.filter(ee.Filter.date(startDate,endDate))
.filter(ee.Filter.bounds(polygon))
.select(myvar);
var dailyImg = dataset.toBands();
var collection = dailyImg.sample({
region: polygon,
geometries: true,
});
// Break point coordinates up into properties (table columns) explicitly.
var collection_with_latlon = collection.map(function (feature) {
var coordinates = feature.geometry().transform('epsg:4326').coordinates();
return feature.set('lon', coordinates.get(0), 'lat', coordinates.get(1));
});
Export.table.toDrive({
collection: collection_with_latlon,
description: 'tx_2006_2017',
fileFormat: 'CSV',
});
Each row in the resulting file is a lat lon from the polygon
and the days are arranged as columns. So the number of columns I have is number of days * 21 GCMs. This table can get very big column-wise if I increase the number of days
How can I write my output such that each row is lat/long and a day combination?