Geographic Information Systems Asked by Sharma ND on August 3, 2021
I am trying to get 3 hourly rainfall data for my region using TRMM/3B42. There seems to be an error but I am unable to find it.
var rain = ee.ImageCollection("TRMM/3B42").select("precipitation")
var startDate = ee.Date('2020-10-01'); // set analysis start time
var endDate = ee.Date('2020-10-31'); // set analysis end time
var region = table
var ntime = ee.Number(endDate.difference(startDate,'hour')).round()
print(ntime)
var TimeList = ee.List.sequence(0, ntime,3).map(function (n) {
return startDate.advance(n, 'hour').format('YYMMdd:HH');
})
print(TimeList)
var result = region.map(function(feature){
// map over each month
var timeSeries = ee.List.sequence(0,ntime).map(function (n){
// calculate the offset from startDate
var ini = startDate.advance(n,'hour');
// advance just one month
var end = ini.advance(3,'hour');
// filter and reduce
var data = rain.filterDate(ini,end).median().reduceRegion({
reducer: ee.Reducer.mean(),
geometry: feature.geometry(),
scale: 30,
bestEffort: true
});
// get the value and check that it has data
var val = ee.Number(data.get("precipitation"));
val = ee.Number(ee.Algorithms.If(val,val,-999));
// return max
return val;
});
// create new dictionary with date strings and values
var timeDict = ee.Dictionary.fromLists(TimeList,timeSeries);
// return feature with a timeseries property and results
return feature.set(timeDict);
});
// print to see if it is doing what we expect...
print(result);
There are some issues in your code. Despite this page reports dataset availability until 2020-12-31, this is not true. Dataset (Image Collection) is not empty only with 2019 dates (there is not data with your range for 2020). On the other hand, you should map Image Collection (in your case rain); not feature collection region. Also, it is preferable to use a list instead a dictionary for pairing dates and precipitation values. As you don't include in your code a valid reference to region, I assumed it as an arbitrary point in following code.
var table = ee.Geometry.Point([-104.66755876817389, 35.39339787387425]);
var startDate = ee.Date('2019-10-01'); // set analysis start time
var endDate = ee.Date('2019-11-01'); // set analysis end time
var rain = ee.ImageCollection("TRMM/3B42")
.select("precipitation")
.filterDate(startDate, endDate);
print(rain);
Map.addLayer(rain);
var region = table;
var getPrecipitation = function(image) {
// Reducing region and getting value
var value_prec = ee.Image(image)
.reduceRegion(ee.Reducer.first(), region)
.get('precipitation');
var time = ee.Image(image).get('system:time_start');
// Return the time (in milliseconds since Jan 1, 1970) as a Date
var prec_list = value_prec;
return prec_list;
};
var count = rain.size();
var prec_list = rain.toList(count).map(getPrecipitation);
//print("preipitation list", prec_list);
var allDates = ee.List(rain.aggregate_array('system:time_start'));
var allDatesSimple = allDates.map(function(date){
return ee.Date(date).format().slice(0,13);
});
//print(allDatesSimple);
var paired = allDatesSimple.zip(prec_list);
print(paired);
After running it in GEE editor, paired (dates,values) are printed in GEE console. In following image you can see an extract of these values for referred arbitrary point.
Correct answer by xunilk on August 3, 2021
Not your fault; there's no data in that collection beyond 2019-12-31. The TRMM team didn't make any data past 2019-12-31. See: https://trmm.gsfc.nasa.gov/ for more info.
Answered by Noel Gorelick on August 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP