Reservoir in- & outflow modeling

In & outflow  of a reservoir from a height – volume curve.

1. Copy the template into a new script and fill in the author details, date and contact information.

2. Add the upstream Area of Ban Ve. Add the id of the fusion table.

3. Import Chirps data.

4. Setup the period of interest.

// variables for start and end year
var startyear = 2009;
var endyear = 2016; 

// 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);

5. Select the data for the period of interest

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

6. Use the script below to calculate the total precipitation for each month.

// Make a list with months
var months = ee.List.sequence(1,12);

// calculate the total amount of precip 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());

7. Now we are going to setup the visualization for an image and a barchart.

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

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

8. Create a chart from the yearly precipitation data, using the redriver polygon as the area and a reducer to calculate the mean precipitation in that area.

var chart = Chart.image.seriesByRegion({
  imageCollection:allP,
  regions: BanVEupstream,
  reducer: ee.Reducer.mean(),
  band: 'precipitation',
  scale: 500,
  xProperty: 'system:time_start',
  seriesProperty: 'label'})
    .setOptions(title)
    .setChartType('ColumnChart');

9. Display the result.

// plot the chart
print(chart)

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

// plot the map
Map.addLayer(allP.mean().clip(BanVEupstream),p_viz, "mean Montlhy P")

10. Export the data as a csv file.

11. Copy the template into a new script and fill in the author details, date and contact information.

12. Import the ET dataset.

// ET dataset
var ET = ee.ImageCollection("users/atepoortinga/etdata")

13. import the Ban Ve upstream fusion table.

14. Define the time range.

// Define the start and end year
var startyear = 2003;
var endyear = 2007; 

// set the start and enddate
var startdate = ee.Date.fromYMD(startyear,1,1);
var enddate = ee.Date.fromYMD(endyear,12,31);

15. Create a list with months and years.

// list with the months
var months = ee.List.sequence(1,12);

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

16. Use the code below to calculate the mean monthly ET

// 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 monthly et
var monthlyET =  ee.ImageCollection.fromImages(
  months.map(function (m) {
  var w = allET.filterMetadata('month', 'equals', m).mean();
  return w.set('month', m)
          .set('date', ee.Date.fromYMD(1,m,1))
          .set('system:time_start',ee.Date.fromYMD(1,m,1));
}).flatten());

17. Define the chart title.

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

18. Create the chart

// create a chart with a reducer
var chart = ui.Chart.image.seriesByRegion(monthlyET,
                                          BanVeUpstream,
                                          ee.Reducer.mean(),
                                          'b1',
                                          250,
                                         'system:time_start',
                                         'Sub_Basin')
                  .setOptions(title)
                  .setChartType('ColumnChart');

19. Plot the data.

20. Export the data as a csv file.

// plot the map
var et_viz = {min:0.0, max:150, palette:"000000,0000FF,FDFF92,FF2700,FF00E7"};
Map.addLayer(allET.mean().clip(BanVeUpstream),et_viz, "mean Montlhy ET")
Map.addLayer(BanVeUpstream);
Map.centerObject(BanVeUpstream, 5);

Assignment: Calculate how long it takes for the reservoir to fill up. Use a dead water level of 155 and a normal water level of 200m.

4 comments

  1. Hi Thisearthsite,
    Please show me how to calculate inflow and outflow (discharge, unit m3/s) of the reservoir (not ET and Rain).
    Thank you so much for the interesting topic.

    Like

  2. Dear Sir,

    Thanks for the code write up.

    How to collect the Water surface Area of a Reservoir over a period using the above code?

    Like

Leave a Reply