1

I am looking to just extract the area weighted mean value of hourly precipitation using the NLDAS-2 dataset in Google Earth Engine. I can do this using a chart, but it is very limiting considering it only produces 5,000 data points. I know there is a way to just export to table, but am having a challenging time doing so as I am a new user.

Right now I can get it to run with this code, but only 10 days at a time and I am looking to download 2002-2018.

// load in PRISM data and select dates 
var PRECIP = ee.ImageCollection("NASA/NLDAS/FORA0125_H002")      
                 .filterDate('2002-10-01','2002-11-30')   

print(ui.Chart.image.series({
  imageCollection:PRECIP.select('total_precipitation'),
  region: Elv,
  reducer: ee.Reducer.mean(),
  scale:13875
}).setOptions({title:'hourly precip'}));

1 Answer 1

2

As you don't provide an Elv region, I arbitrarily consider one in USA country. On the other hand, you said that above code it is only for 10 days but .filterDate('2002-10-01','2002-11-30') method take in account 60 days in your Image Collection (1440 images).

So, you need to consider a function with an ee.Reducer for your region (Elv), for mapping all 1440 images and extracting precipitation values (kg/m^2 = mm). It is also necessary to extract the system:time_start for each image for pairing them with its respective precipitation value. Following code does that:

var Elv = ee.Geometry.Polygon(
        [[[-110.85799164250078, 38.053804827042335],
          [-110.85799164250078, 37.92825803418136],
          [-110.66023773625078, 37.92825803418136],
          [-110.66023773625078, 38.053804827042335]]]);

// load in PRISM data and select dates 
var PRECIP = ee.ImageCollection("NASA/NLDAS/FORA0125_H002")   
                 .filterDate('2002-10-01','2002-11-30');

print(PRECIP);

var getPrecipit = function(image) {
  
  var time = ee.Date(ee.Image(image).get('system:time_start')).format().slice(0, 10); 
  
  var value_precipt = ee.Image(image)
    .reduceRegion(ee.Reducer.first(), Elv)
    .get('total_precipitation');
  
  return [time, value_precipt];
  
};

var count = PRECIP.size();

var precipit_list = PRECIP.toList(count).map(getPrecipit);

print(precipit_list);

After running it in GEE console editor, as follows, I selected a sample of 1440 produced paired values. It can be observed there were produced 24 values per day. You need to decide before (it is another question) how these values must be grouped and exported as CSV to Google Drive.

["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-01",0]
["2002-10-02",0]
["2002-10-02",0]
["2002-10-02",2.0696]
.
.
.

Editing Note:

A complete code for producing 10224 values of total precipitation and exporting them to Google Drive looks as follows.

var Elv = ee.Geometry.Polygon(
        [[[-110.85799164250078, 38.053804827042335],
          [-110.85799164250078, 37.92825803418136],
          [-110.66023773625078, 37.92825803418136],
          [-110.66023773625078, 38.053804827042335]]]);

// load in PRISM data and select dates 
var PRECIP = ee.ImageCollection("NASA/NLDAS/FORA0125_H002")   
                 .filterDate('2002-10-01','2003-12-01');

//print(PRECIP);

var getPrecipit = function(image) {
  
  var time = ee.Date(ee.Image(image).get('system:time_start')).format().slice(0, 10); 
  
  var value_precipt = ee.Image(image)
    .reduceRegion(ee.Reducer.first(), Elv)
    .get('total_precipitation');
  
  return [time, value_precipt];
  
};

var count = PRECIP.size();

print("Number of values", count);

var precipit_list = PRECIP.toList(count).map(getPrecipit);

//print(precipit_list);

var myFeatures = ee.FeatureCollection(precipit_list.map(function(el){
  el = ee.List(el); // cast every element of the list
  var geom = Elv;
  return ee.Feature(geom, {
    'date': ee.String(el.get(0)),
    'value':ee.Number(el.get(1))
  });
}));

//print(myFeatures);

// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"precipitation", //my task
"GEE_Folder", //my export folder
"precipit_values",  //file name
"CSV");

After running 2 minutes the corresponding task in Google Code Editor, I got the CSV file in my Google Drive. It can be downloaded to my PC and edited with a spreadsheet software as Excel.

6
  • Thanks so much for the response! The timestep is different here as I was using the chart output, sorry for that. What you posted makes a lot of sense. Can you clarify in "var time = ee.Date(ee.Image(image).get('system:time_start')).format().slice(0, 10); " what the slice is doing and what 0,10 represents?
    – JKurzweil
    Feb 23, 2021 at 21:33
  • It also seems that this code runs into the same issue of exceeding the 5000 elements. Is there a way to overcome this?
    – JKurzweil
    Feb 23, 2021 at 21:36
  • It is not the code. It is the approach. This code was only a demonstration. If you want to extract, for instance 80,000 values, you cannot print them in console. You need to export them as CSV to Google Drive.
    – xunilk
    Feb 23, 2021 at 23:46
  • After your comments, I understood completely your request. I edited my answer where you can get a code for processing 10224 values of precipitation and export them to Google Drive. In this case, it is not printed in console the Image Collection or the precipit_list for avoiding execution errors. I hope this help.
    – xunilk
    Feb 24, 2021 at 0:42
  • Sorry for the delay, it does seem to not run into any execution errors, but instead of a value field it just gives a column of the coordinates.
    – JKurzweil
    Mar 4, 2021 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.