Skip to content

Commit

Permalink
Merge pull request #140 from nismod/water_demand
Browse files Browse the repository at this point in the history
Water demand integration
  • Loading branch information
tomalrussell authored Jul 9, 2019
2 parents b3b2fd6 + 4858a0d commit 6855abd
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ bash ./provision/install_energy_demand.sh .
bash ./provision/install_energy_supply.sh . ./path/to/xpress_install_dir
bash ./provision/install_transport.sh .
bash ./provision/install_water_supply.sh .
bash ./provision/install_water_demand.sh .
```

Run post-install scripts:
Expand Down
3 changes: 3 additions & 0 deletions config/dimensions/water_demand_population_areas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: water_demand_population_areas
description: Names of water demand population areas
elements: water_demand/water_demand_population_areas.csv
12 changes: 12 additions & 0 deletions config/model_runs/water_demand_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description: ''
name: water_demand_test
narratives: {}
scenarios:
water_demand_populations: actual
sos_model: water_demand_only
stamp: '2019-03-01T00:00:00.000Z'
timesteps:
- 2020
- 2030
- 2050
strategies: []
14 changes: 14 additions & 0 deletions config/scenarios/water_demand_populations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: water_demand_populations
description: Population numbers for water demand
provides:
- name: population
description: Population of GB
dims:
- water_demand_population_areas
dtype: int
unit: people
variants:
- name: actual
description: Population of GB
data:
population: water_demand/population.csv
30 changes: 30 additions & 0 deletions config/sector_models/water_demand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
classname: WaterDemandWrapper
description: Water demand model
initial_conditions: []
inputs:
- name: population
dims:
- water_demand_population_areas
dtype: int
unit: people
interventions: []
name: water_demand
outputs:
- name: water_demand
dims:
- water_demand_population_areas
dtype: float
unit: ML/day
parameters:
- name: per_capita_water_demand
description: The assumed per capita demand for water
abs_range:
- 0
- 2.0e-5
exp_range:
- 5.0e-6
- 1.5e-5
default: default_water_demand.csv
dtype: float
unit: 'ML/person/day'
path: models/water_demand/run.py
12 changes: 12 additions & 0 deletions config/sos_models/water_demand_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: water_demand_only
description: Future water demand for UK
sector_models: # Select 1 or more of the sector models
- water_demand
scenarios: [] # Select 0 or more of the scenario sets
narratives: []
scenario_dependencies:
- source: water_demand_populations
source_output: population
sink: water_demand
sink_input: population
model_dependencies: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name
England
Scotland
Wales
2 changes: 2 additions & 0 deletions data/parameters/default_water_demand.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
per_capita_water_demand
1.0e-5
10 changes: 10 additions & 0 deletions data/scenarios/water_demand/population.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
timestep,water_demand_population_areas,population
2020,England,55620000
2020,Scotland,5234000
2020,Wales,2773000
2030,England,58401000
2030,Scotland,5495700
2030,Wales,2911650
2050,England,64241100
2050,Scotland,6045270
2050,Wales,3202815
52 changes: 52 additions & 0 deletions models/water_demand/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Water demand model
"""
import numpy as np
import pandas as pd

from smif.model.sector_model import SectorModel
from water_demand import WaterDemand


class WaterDemandWrapper(SectorModel):
"""Water Model Wrapper
"""

def before_model_run(self, data_handle=None):
"""Implement this method to conduct pre-model run tasks
Arguments
---------
data_handle: smif.data_layer.DataHandle
Access parameter values (before any model is run, no dependency
input data or state is guaranteed to be available)
Info
-----
`self.user_data` allows to pass data from before_model_run to main model
"""
pass

def simulate(self, data_handle):
"""Runs the water supply model.
Arguments
---------
data_handle : dict
A dictionary containing all parameters and model inputs defined in
the smif configuration by name
"""

# The per capita demand (in ML/person/day) is set as a model parameter
per_capita_demand = data_handle.get_parameter('per_capita_water_demand')

# The population is currently a scenario dependency
pop_input = data_handle.get_data('population')

# Create the model
model = WaterDemand(population=pop_input.data, scale_factor=per_capita_demand.data)

# Simulate the water demand
demand = model.simulate()

data_handle.set_results('water_demand', demand)
4 changes: 4 additions & 0 deletions provision/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ model_version=6d8642567967f6168b6dc31c97043083bc644b0b
remote_data=water_supply/data_to_prepare_nodal_v3.zip
local_dir=models/water_supply
dim_dir=data/dimensions/water_supply

[water-demand]
local_dir=models/water_demand
model_version=v1.1
5 changes: 4 additions & 1 deletion provision/get_install_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ bash -x ./provision/install_transport.sh .
bash -x ./provision/get_data_et_module.sh .
bash -x ./provision/install_et_module.sh .

# Water supplysmif
# Water supply
bash -x ./provision/get_data_water_supply.sh .
bash -x ./provision/install_water_supply.sh .

# Water demand
bash -x ./provision/install_water_demand.sh .
13 changes: 13 additions & 0 deletions provision/install_water_demand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Expect NISMOD dir as first argument
base_path=$1

# Read remote_data, local_dir from config.ini
source <(grep = <(grep -A2 "\[water-demand\]" $base_path/provision/config.ini))

# Locations for the git repo (temporary) and the nodal-related files
repo_dir=$local_dir/repo

# Clone repo and copy necessary files to the model directory
pip install git+https://github.com/nismod/water_demand.git@$model_version#egg=water_demand
3 changes: 3 additions & 0 deletions provision/vm_provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ bash -x $base_path/provision/install_et_module.sh $base_path
bash -x $base_path/provision/get_data_water_supply.sh $base_path
bash -x $base_path/provision/install_water_supply.sh $base_path

# Water demand
bash -x $base_path/provision/install_water_demand.sh $base_path


#
# User config
Expand Down

0 comments on commit 6855abd

Please sign in to comment.