-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
philippkraft
committed
Dec 20, 2018
1 parent
f608e1e
commit 1103c8f
Showing
7 changed files
with
108 additions
and
22 deletions.
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
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,37 @@ | ||
|
||
import cmf | ||
import pandas as pd | ||
|
||
def load_climate_data(project, climate_file): | ||
""" | ||
Loads climate data from 1980 to 2006 for Giessen from | ||
a csv file and adds it to a cmf project as a meteorological station | ||
and a rain station. | ||
Data provided by DWD | ||
:param project: A cmf project | ||
:returns: meteo station, rainfall station | ||
""" | ||
data = pd.read_csv(climate_file, parse_dates=['date'], index_col=0) | ||
|
||
meteo = project.meteo_stations.add_station( | ||
'giessen', position=(0, 0), latitude=51 | ||
) | ||
begin = data.index[0].to_pydatetime() | ||
|
||
def col2ts(column_name): | ||
return cmf.timeseries.from_array(begin, cmf.day, data[column_name]) | ||
|
||
meteo.Tmin = col2ts('T min [degC]') | ||
meteo.Tmax = col2ts('T max [degC]') | ||
meteo.rHmean = col2ts('rH mean [%]') | ||
meteo.Sunshine = col2ts('sunshine [h/h]') | ||
meteo.Windspeed = col2ts('windspeed [m/s]') | ||
|
||
rainstation = project.rainfall_stations.add( | ||
'Giessen', | ||
col2ts('Prec [mm/day]'), | ||
Position=(0, 0, 0) | ||
) | ||
|
||
return meteo, rainstation |
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,66 @@ | ||
""" | ||
A simple lumped 2 stoarge model with ET, snow but no canopy interception | ||
""" | ||
|
||
import cmf | ||
|
||
from .load_climate import load_climate_data | ||
|
||
class Cmf2StorageModel: | ||
def __init__(self, climate_file='data/climate.csv'): | ||
self.project = cmf.project() | ||
self.cell = self.project.NewCell(0, 0, 0, 1000) | ||
|
||
self.soil = self.cell.add_layer(1.0) | ||
self.gw = self.cell.add_layer(1.0) | ||
self.snow = self.cell.add_storage('Snow', 'S') | ||
|
||
self.outlet = self.project.NewOutlet('outlet') | ||
|
||
self.meteo, self.rainstation = load_climate_data(self.project, climate_file) | ||
|
||
|
||
def mm_to_m3(self, vol): | ||
return vol * self.cell.area * 1e-3 | ||
|
||
def create_connections(self): | ||
# Route snow melt to surface | ||
cmf.SimpleTindexSnowMelt(self.cell.snow, self.cell.surfacewater, rate=7) | ||
# Infiltration | ||
cmf.SimpleInfiltration(self.soil, self.cell.surfacewater, W0=0.8) | ||
# Route infiltration / saturation excess to outlet | ||
cmf.WaterBalanceFlux(self.cell.surfacewater, self.outlet) | ||
# Parameterize soil water capacity | ||
self.soil.soil.porosity = 0.2 | ||
C = self.soil.get_capacity() | ||
# Parameterize water stress function | ||
self.cell.set_uptakestress(cmf.VolumeStress(0.2 * C, 0 * C)) | ||
cmf.TurcET(self.soil, self.cell.transpiration) | ||
|
||
# Route water from soil to gw | ||
cmf.PowerLawConnection(self.soil, self.gw, | ||
Q0=self.mm_to_m3(50), | ||
V0=0.5 * C, | ||
beta=4 | ||
) | ||
# Route water from gw to outlet | ||
cmf.LinearStorageConnection( | ||
self.gw, self.outlet, | ||
residencetime=20, | ||
residual=0 * C | ||
) | ||
|
||
def run(self, begin=None, end=None): | ||
begin = begin or self.rainstation.data.begin | ||
end = end or self.rainstation.data.end | ||
|
||
solver = cmf.CVodeIntegrator(self.project, 1e-9) | ||
outlet = cmf.timeseries(begin, cmf.day) | ||
outlet.add(self.outlet(begin)) | ||
for t in solver.run(begin, end, cmf.day): | ||
outlet.add(self.outlet.add) | ||
print(t) | ||
|
||
return outlet | ||
|
||
|
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