1

I would like to have a CSV file which contain a time-series of 30 minutes rainfall from last 10-days before Landslide occurs from certain (landslide) location. I used NASA GPM IMERG data for the rainfall, and try to write a GEE script (compiling from others too) as below:

// Define a point of interest as a landslide location.
var POI = ee.Geometry.Point(111.19165, -8.08875); // Adjust the coordinate
Map.centerObject(POI, 9);

// Date when landslide occurs
var lsevent = new Date('2017-11-29'); // Adjust date period with landslide event
var start = new Date(lsevent.getTime() - 10*24*60*60*1000); // 10-days before
var end = new Date(lsevent.getTime() + 1*24*60*60*1000); // 1-day after
print(start);
print(end);

// Import NASA GPM IMERG 30 minute data.
var imerg = ee.ImageCollection('NASA/GPM_L3/IMERG_V06');
var imergHH = imerg.filterBounds(POI)
                   .filterDate(start, end) 
                   .select('precipitationCal');

// Add rainfall accumulation into map
var precip = imergHH.select('precipitationCal').sum();

// Rainfall vis parameter
var palette = [
  '000096','0064ff', '00b4ff', '33db80', '9beb4a',
  'ffeb00', 'ffb300', 'ff6400', 'eb1e00', 'af0000'
];
var precipVis = {min: 0.0, max: 1000.0, palette: palette, opacity:0.5};

Map.addLayer(precip, precipVis, "10-days rainfall", false);
Map.addLayer(POI, {palette:"#ff0000"}, "Landlside location", true);

// Create a function that takes an image, calculates the mean over a geometry and returns
// the value and the corresponding date as a feature.
var timeSeries = imergHH.map(function (image) {
  var imergdate1 = image.date().format('yyyy-MM-dd-hh-mm');
  var value = image
    .clip(POI)
    .reduceRegion({
      reducer: ee.Reducer.mean(),
      scale: 30
    }).get('precipitationCal');
  return ee.Feature(null, {value: value, date: imergdate1});
});

var accumulation = imergHH.map(function (image) {
  var imergdate2 = image.date().format('yyyy-MM-dd-hh-mm');
  var value = image
    .clip(POI)
    .reduceRegion({
      reducer: ee.Reducer.sum(),
      scale: 30
    }).get('precipitationCal');
  return ee.Feature(null, {value: value, date: imergdate2});
});

// Create a graph of the time-series.
var graphTS = ui.Chart.feature.byFeature(timeSeries,'date', ['value']);
print(graphTS.setChartType("LineChart")
           .setOptions({title: 'NASA GPM IMERG 30-minute rainfall time-series',
                        vAxis: {title: 'Rainfall estimates (mm)'},
                        hAxis: {title: 'Date'}}));

// Create a graph of the accumulation.
var graphAcc = ui.Chart.feature.byFeature(accumulation,'date', ['value']);
print(graphAcc.setChartType("LineChart")
           .setOptions({title: 'NASA GPM IMERG 30-minute rainfall accumulation',
                        vAxis: {title: 'Rainfall estimates (mm)'},
                        hAxis: {title: 'Date'}}));

// Export the result to Google Drive as a CSV.
Export.table.toDrive({
  collection: timeSeries,
  description:'LS_20191129',
  folder:'GEE',
  selectors: 'date, value', 
  fileFormat: 'CSV'
});

// End of script

So far, I got the time-series Chart and CSV, and I happy for that as my first goal. Next step: (1) I would like to have a Chart and CSV for the accumulation data from start to end of the period. The graphAcc (2nd chart) doesn't seem to give me the results I want. Did I missed something in the script?

(2) If I have a CSV file with information on ID,Lon,Lat,Date How to integrate this data as input? So the script above can directly read the list and do rainfall extraction and export to multiple CSVs or append to the list. Any reference or example?

For reference, attached is the data from Chart 1, and I calculate the accumulation manually, and total rainfall for start to end is 558.557 milimeters.

1

Your region POI is a single point. So you will never have more than a single pixel when you reduce that region. The mean() and sum() of a single pixel is the same, which is why the two charts are identical. Try with something like this:

var days = ee.Date(end).difference(ee.Date(start), 'days')
var dayOffsets = ee.List.sequence(1, days)
var accumulation = dayOffsets.map(
  function (dayOffset) {
    var endDate = ee.Date(start).advance(ee.Number(dayOffset), 'days')
    var image = imergHH.filterDate(start, endDate).sum()
    var date = endDate.advance(-1, 'days').format('yyyy-MM-dd')
    var value = image
      .clip(POI)
      .reduceRegion({
        reducer: ee.Reducer.mean(),
        geometry: POI,
        scale: 30
      }).get('precipitationCal')
    return ee.Feature(null, {value: value, date: date})
  })

https://code.earthengine.google.com/b5d9a2daf09800963ac3732de779abf1

As for your second question, make a separate post for that, describing it more in detail.

| improve this answer | |
  • Thanks, so for Q1 - What should I do to make accumulation chart? I only need accumulation data in single location. – user97103 May 5 at 9:13
  • Well something like accumulation data from day1 to day 10. For example d1 = 2, d2 = 4, d3 = 7, ... Then the data for chart input will be 2, 6, 13, ... – user97103 May 5 at 9:25
  • Yes correct. Do you have any example on how to do that? – user97103 May 5 at 9:37
  • Wow, thank you. Thats exactly I want to have. But, the rainfall accumulation value seems very high. Usually in 10 days if all extreme rainfall, less than 500mm in 10 days. – user97103 May 5 at 9:58
  • Thank you very much, its perfect! – user97103 May 5 at 10:13

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.