# Calculate Blue and Green water in GEE

In the dry season a lot of blue water is used by vegetation.

Use the code below to make the distinction between Blue an Green water used for evapotranspiration.

```//SERVIR-MEKONG 2016
//AUTHORS: Ate Poortinga
//CONTACT INFORMATION:
//Date:

//////////////////////
//BUILD: Land Cover
//PURPOSE:
//SENSORS:
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////

// User specified parameters

// Data

// import ET data
var ET = ee.ImageCollection("users/atepoortinga/MekongEtdata")

// setup the vizualization
var et_viz = {min:0.0, max:150, palette:"000000,0000FF,FDFF92,FF2700,FF00E7"};
// Data
// variables for start and end year
var startyear = 2006;
var endyear = 2006;

var months = ee.List.sequence(1,12);

// variables for start and end month
var startmonth = 1;
var endmonth = 1;

// define start and end date
var startdate = ee.Date.fromYMD(startyear,startmonth,1);
var enddate = ee.Date.fromYMD(endyear+1,endmonth,1);

// create list for years
var years = ee.List.sequence(startyear,endyear);

// polygon for the red river
var Ca = ee.FeatureCollection('ft:11uQewh4u7NFXneH99YPs6P9F1Au6wxBq959BZWt_','geometry');

// set visualizaton parameters
var et_viz = {min:0.0, max:200, palette:"000000,0000FF,FDFF92,FF2700,FF00E7"};

// Functions

// select ET for time range
var ET = ET.filterDate(startdate, enddate)
// Sort chronologically in descending order.
.sort('system:time_start', false)
.filterBounds(Ca);

// select P for time range
var P = chirps.filterDate(startdate, enddate)
// Sort chronologically in descending order.
.sort('system:time_start', false)
.filterBounds(Ca);

// calculate the et for each month
var allET =  ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function(m){
var w = ET.filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.sum();
return w.set('year', y)
.set('month', m)
.set('date', ee.Date.fromYMD(y,m,1))
.set('system:time_start',ee.Date.fromYMD(y,m,1))

});
}).flatten());

// calculate the P for each month
var allP =  ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function(m){
var w = P.filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.sum();
return w.set('year', y)
.set('month', m)
.set('date', ee.Date.fromYMD(y,m,1))
.set('system:time_start',ee.Date.fromYMD(y,m,1))

});
}).flatten());

// combine the two datasets
var myCollection = allP.combine(allET);

print(myCollection)

// calculate the Incremental ET
myCollection = myCollection.map(function(img){
var myimg = img.expression("(p - et) ",
{
p: img.select("precipitation"),
et: img.select("b1"),
});

myimg = myimg.lt(0).multiply(myimg).multiply(-1)
})

print(myCollection)

var viz = {min:0.0, max:1000, palette:"ff0000,ff8800,fffa00,4cff00,00ffe1,0400ff,ff00ff"};

// landuse map
var luse = ee.FeatureCollection('ft:1Hgt_gN4R7opnaFxamqJsJnkic_WWunxgbBtHsT5J','geometry');

// Predefine the chart titles.
var title = {
title: 'ET',
hAxis: {title: 'Time'},
vAxis: {title: 'ET (mm)'},
};

// setup the chart
var chart = ui.Chart.image.seriesByRegion(myCollection, luse, ee.Reducer.mean(), 'b1', 2500, 'system:time_start', 'landuse')
.setOptions(title)
.setChartType('ColumnChart');
// plot the chart
print(chart)
// Predefine the chart titles.
var title = {
title: 'Incremental ET',
hAxis: {title: 'Time'},
vAxis: {title: 'ET incremental (mm)'},
};

// setup the chart
var chart = ui.Chart.image.seriesByRegion(myCollection, luse, ee.Reducer.mean(), 'incrementalET', 2500, 'system:time_start', 'landuse')
.setOptions(title)
.setChartType('ColumnChart');

// plot the chart
print(chart)

// center the map
Map.centerObject(Ca, 5);

```