-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYearly Rainfall-Aggregate
86 lines (70 loc) · 2.4 KB
/
Yearly Rainfall-Aggregate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//This script is used to assess monthly rainfall indeces with Chirps rainfall data
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Orginial Author: Ujaval Gandhi
// Modified Author: Desmond Lartey
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Determine the area of interest
var point = table.filter(ee.Filter.eq('NAME', 'Kainji Lake'))
var chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/PENTAD');
var year = 2019;
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = startDate.advance(1, 'year');
var yearFiltered = chirps
.filter(ee.Filter.date(startDate, endDate));
print(yearFiltered, 'Date-filtered CHIRPS images');
print(startDate, 'Start date');
print(endDate, 'End date');
print('Start date as timestamp', startDate.millis());
print('End date as timestamp', endDate.millis());
// Aggregate this time series to compute monthly images.
// Create a list of months
var months = ee.List.sequence(1, 12);
// Write a function that takes a month number
// and returns a monthly image.
var createMonthlyImage = function(beginningMonth) {
var startDate = ee.Date.fromYMD(year, beginningMonth, 1);
var endDate = startDate.advance(1, 'month');
var monthFiltered = yearFiltered
.filter(ee.Filter.date(startDate, endDate));
// Calculate total precipitation.
var total = monthFiltered.reduce(ee.Reducer.sum());
return total.set({
'system:time_start': startDate.millis(),
'system:time_end': endDate.millis(),
'year': year,
'month': beginningMonth
});
};
// map() the function on the list of months
// This creates a list with images for each month in the list
var monthlyImages = months.map(createMonthlyImage);
// Create an ee.ImageCollection.
var monthlyCollection = ee.ImageCollection.fromImages(monthlyImages);
print(monthlyCollection);
var chart = ui.Chart.image.series({
imageCollection: monthlyCollection,
region: point,
reducer: ee.Reducer.mean(),
scale: 5566,
});
print(chart);
var chart = ui.Chart.image.series({
imageCollection: monthlyCollection,
region: point,
reducer: ee.Reducer.mean(),
scale: 5566
}).setOptions({
lineWidth: 1,
pointSize: 3,
title: 'Monthly Rainfall at Kainji Lake',
vAxis: {
title: 'Rainfall (mm)'
},
hAxis: {
title: 'Month',
gridlines: {
count: 12
}
}
});
print(chart);