-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from nismod/water_demand
Water demand integration
- Loading branch information
Showing
14 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
4 changes: 4 additions & 0 deletions
4
data/dimensions/water_demand/water_demand_population_areas.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name | ||
England | ||
Scotland | ||
Wales |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
per_capita_water_demand | ||
1.0e-5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters