Skip to content

Commit

Permalink
A bit of cleanup and reworking on cmf3d-shapefile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkraft committed Jan 17, 2018
1 parent 0b93cbb commit 57df484
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 72 deletions.
31 changes: 16 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Modelling water and solute fluxes
===================================

cmf is a programming library to create hydrological models, which are highly modular and connectible to other
models developed using a multiple hypotheses background. Although written in C++, its primary usage is to be compiled as an extension to other programming languages, using SWIG. Researchers can build individual models,
models developed using a multiple hypotheses background. Although written in C++, its primary usage is to be compiled
as an extension to other programming languages, using SWIG. Researchers can build individual models,
targeting their scientific question by using the library objects like water storages, boundary conditions,
fluxes and solvers. cmf uses the finite volume method to set up a wide range of models of water flow through
your study area. Resulting models can range from **lumped conceptual models** to **fully distributed darcian models**
Expand Down Expand Up @@ -73,17 +74,17 @@ the formulation of different hypotheses. The principle of the connection of CMF
disciplines is shown by Kraft et al. (2010), and Haas et al. (2012) show the relevance of tightly connected
models of transport and turnover for the emission of greenhouse gases from ecosystems.

- Beven, K., 2006. Searching for the Holy Grail of scientific hydrology. Hydrol.Earth Syst.Sci 10, 609-618.
- Beven, K.J., 2002. Towards an alternative blueprint for a physically-based digitally simulated hydrologic response modelling system. Hydrol.Proc. 16, 189-206.
- Buytaert, W., Reusser, D., Krause, S., Renaud, J.P., 2008. Why can't we do better than Topmodel? Hydrol.Proc. 22, 4175-4179.
- Clark, M.P., Kavetski, D., Fenicia, F., 2011. Pursuing the method of multiple working hypotheses for hydrological modeling. Water Resour.Res 47.
- Haas, E., Klatt, S., Fröhlich, A., Kraft, P., Werner, C., Kiese, R., Grote, R., Breuer, L., Butterbach-Bahl, K., 2012. LandscapeDNDC: a process model for simulation of biosphere-atmosphere-hydrosphere exchange processes at site and regional scale. Landscape Ecol. DOI 10.1007/s10980-012-9772-x
- Kirchner, J., 2006. Getting the right answers for the right reasons: Linking measurements, analyses, and models to advance the science of hydrology. Water Resour.Res. 42, W03S04, doi:10.1029/2005WR004362.
- Kraft, P., Multsch, S., Vache, K. B., Frede, H.-G. and Breuer, L.: Using Python as a coupling platform for integrated catchment models, Adv. Geosci., 27, 51-56, doi:10.5194/adgeo-27-51-2010, 2010.
- Kraft, P., 2012. A hydrological programming language extension for integrated catchment models, Dissertation, Justus-Liebig-Universität, Gießen, 16 March. [online] Available from: http://geb.uni-giessen.de/geb/volltexte/2012/8759/
- Kraft, P., Vache, K. B., Frede, H.-G. and Breuer, L.: A hydrological programming language extension for integrated catchment models, Environ. Model. Softw., 26, 828-830, doi:10.1016/j.envsoft.2010.12.009, 2011.
- Qu, Y.Z., Duffy, C.J., 2007. A semidiscrete finite volume formulation for multiprocess watershed simulation. Water Resour.Res. 43, W08419, doi:10.1029/2006WR005752.
- Seibert, J., McDonnell, J.J., 2002. On the dialog between experimentalist and modeler in catchment hydrology: Use of soft data for multicriteria model calibration. Water Resour.Res. 38, doi: 10.1029/2001WR000978.
- Sivapalan, M., 2003. Process complexity at hillslope scale, process simplicity at the watershed scale: is there a connection? Hydrol.Proc. 17, 1037-1041.
- Tetzlaff, D., McDonnell, J.J., Uhlenbrook, S., McGuire, K.J., Bogaart, P.W., Naef, F., Baird, A.J., Dunn, S.M., Soulsby, C., 2008. Conceptualizing catchment processes: simply too complex? Hydrol.Proc. 22, 1727-1730.
- Vache, K.B., McDonnell, J.J., 2006. A process-based rejectionist framework for evaluating catchment runoff model structure. Water Resour.Res. W02409, doi:10.1029/2005WR004247.
- Beven, K., 2006. Searching for the Holy Grail of scientific hydrology. Hydrol.Earth Syst.Sci 10, 609-618.
- Beven, K.J., 2002. Towards an alternative blueprint for a physically-based digitally simulated hydrologic response modelling system. Hydrol.Proc. 16, 189-206.
- Buytaert, W., Reusser, D., Krause, S., Renaud, J.P., 2008. Why can't we do better than Topmodel? Hydrol.Proc. 22, 4175-4179.
- Clark, M.P., Kavetski, D., Fenicia, F., 2011. Pursuing the method of multiple working hypotheses for hydrological modeling. Water Resour.Res 47.
- Haas, E., Klatt, S., Fröhlich, A., Kraft, P., Werner, C., Kiese, R., Grote, R., Breuer, L., Butterbach-Bahl, K., 2012. LandscapeDNDC: a process model for simulation of biosphere-atmosphere-hydrosphere exchange processes at site and regional scale. Landscape Ecol. DOI 10.1007/s10980-012-9772-x
- Kirchner, J., 2006. Getting the right answers for the right reasons: Linking measurements, analyses, and models to advance the science of hydrology. Water Resour.Res. 42, W03S04, doi:10.1029/2005WR004362.
- Kraft, P., Multsch, S., Vache, K. B., Frede, H.-G. and Breuer, L.: Using Python as a coupling platform for integrated catchment models, Adv. Geosci., 27, 51-56, doi:10.5194/adgeo-27-51-2010, 2010.
- Kraft, P., 2012. A hydrological programming language extension for integrated catchment models, Dissertation, Justus-Liebig-Universität, Gießen, 16 March. [online] Available from: http://geb.uni-giessen.de/geb/volltexte/2012/8759/
- Kraft, P., Vache, K. B., Frede, H.-G. and Breuer, L.: A hydrological programming language extension for integrated catchment models, Environ. Model. Softw., 26, 828-830, doi:10.1016/j.envsoft.2010.12.009, 2011.
- Qu, Y.Z., Duffy, C.J., 2007. A semidiscrete finite volume formulation for multiprocess watershed simulation. Water Resour.Res. 43, W08419, doi:10.1029/2006WR005752.
- Seibert, J., McDonnell, J.J., 2002. On the dialog between experimentalist and modeler in catchment hydrology: Use of soft data for multicriteria model calibration. Water Resour.Res. 38, doi: 10.1029/2001WR000978.
- Sivapalan, M., 2003. Process complexity at hillslope scale, process simplicity at the watershed scale: is there a connection? Hydrol.Proc. 17, 1037-1041.
- Tetzlaff, D., McDonnell, J.J., Uhlenbrook, S., McGuire, K.J., Bogaart, P.W., Naef, F., Baird, A.J., Dunn, S.M., Soulsby, C., 2008. Conceptualizing catchment processes: simply too complex? Hydrol.Proc. 22, 1727-1730.
- Vache, K.B., McDonnell, J.J., 2006. A process-based rejectionist framework for evaluating catchment runoff model structure. Water Resour.Res. W02409, doi:10.1029/2005WR004247.
4 changes: 2 additions & 2 deletions demo/cmf2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def load_meteo(project):

# Load climate data from csv file
# could be simplified with numpy's
csvfile = open('data/climate.csv')
csvfile = open('data/climate.csv')
csvfile.readline() # Read the headers, and ignore them
for line in csvfile:
# split the line in to columns using commas
columns = line.split(',')
# Get the values, but ignore the date, we have begin and steo
# Get the values, but ignore the date, we have begin and step
# of the data file hardcoded
# If you don't get this line - it is standard Python, I would recommend the official Python.org tutorial
for timeseries,value in zip([rain,meteo.Tmax,meteo.Tmin,meteo.rHmean,meteo.Windspeed,meteo.Sunshine],
Expand Down
149 changes: 94 additions & 55 deletions demo/cmf3d-shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,63 +59,102 @@ def load_meteo(project):
# Use the meteorological station for each cell of the project
project.use_nearest_meteo()


def soiltype(depth):
"""
Creates a retention curve for a depth below ground
using an exponential Ksat decline
:param depth: depth below ground in m
:return: Retention curve
"""
return cmf.BrooksCoreyRetentionCurve(ksat=15 * np.exp(-depth),
porosity=0.5,
_b=5.5,
theta_x=0.35)

def build_cell(c, layercount=0):
class Model:
"""
Shapes and makes a cell, by adding layers and connections
:param c: cmf.Cell
:return: None
The 3d model based on irregular polygons from a shapefile
"""

for d in [0.05, 0.1, 0.2, 0.3, 0.5, 0.75, 1.0, 1.3, 1.7, 2.][-layercount:]:
c.add_layer(d, soiltype(d))
c.saturated_depth = 5.
c.surfacewater_as_storage()
# use Richards connection
c.install_connection(cmf.Richards)
c.install_connection(cmf.MatrixInfiltration)
c.install_connection(cmf.CanopyOverflow)
c.install_connection(cmf.SimpleTindexSnowMelt)
c.install_connection(cmf.PenmanMonteithET)


def create_project(subsurface_lateral_connection,
surface_lateral_connection,
layercount=0):

p = cmf.project()
shp = Shapefile('data/soil_lu_gw.shp')

# Create cells
for feature in shp:
c = cmf.geometry.create_cell(p, feature.shape, feature.HEIGHT, feature.OID)
build_cell(c, layercount)

# Build topology
cmf.geometry.mesh_project(p, verbose=True)

cmf.connect_cells_with_flux(p, subsurface_lateral_connection)
cmf.connect_cells_with_flux(p, surface_lateral_connection)

load_meteo(p)

return p


p = create_project(cmf.DarcyKinematic, cmf.KinematicSurfaceRunoff, 1)

print(cmf.describe(p))
def build_cell(self, c, layercount=0):
"""
Shapes and makes a cell, by adding layers and connections
:param c: cmf.Cell
:return: the now enhanced cell
"""

def soiltype(depth):
"""
Creates a retention curve for a depth below ground
using an exponential Ksat decline
:param depth: depth below ground in m
:return: Retention curve
"""
return cmf.BrooksCoreyRetentionCurve(ksat=15 * np.exp(-depth),
porosity=0.5,
_b=5.5,
theta_x=0.35)

for d in [0.05, 0.1, 0.2, 0.3, 0.5, 0.75, 1.0, 1.3, 1.7, 2.][-layercount:]:
c.add_layer(d, soiltype(d))
c.saturated_depth = 1.
c.surfacewater_as_storage()
# use Richards connection
c.install_connection(cmf.Richards)
c.install_connection(cmf.GreenAmptInfiltration)
c.install_connection(cmf.CanopyOverflow)
c.install_connection(cmf.SimpleTindexSnowMelt)
c.install_connection(cmf.PenmanMonteithET)
return c

def connect_outlet_cell(self, outlet_cell: cmf.Cell, subsurface_lateral_connection,
surface_lateral_connection):
o = outlet_cell.surfacewater
for neighbor, width in outlet_cell.neighbors:
for l in neighbor.layers:
subsurface_lateral_connection(l, o, width)
surface_lateral_connection(neighbor.surfacewater, o, width)

def get_outflow(self, t):
return sum(o.surfacewater(t) for o in self.outlet_cells)

def get_rainfall(self, t):
return sum(c.get_rainfall(t)/c.area for c in self.project) * 1000

def __init__(self, subsurface_lateral_connection,
surface_lateral_connection=None,
layercount=0):
"""
Creates the cmf project
:param subsurface_lateral_connection: Type of lateral subsurface connection, eg. cmf.Darcy
:param surface_lateral_connection: Type of lateral surface flux connection, eg. cmf.KinematicSurfaceRunoff or None
:param layercount: Number of layers in the subsurface
:return:
"""

p = cmf.project()
shp = Shapefile('data/vollnkirchner_bach_cells.shp')

# Create cells
outlet_cells = []
for feature in shp:
c = cmf.geometry.create_cell(p, feature.shape, feature.HEIGHT, feature.OID, with_surfacewater=False)

if feature.LANDUSE_CU.starts_with('outlet'):
outlet_cells.append(c)
else:
self.build_cell(c, layercount)

# Build topology
cmf.geometry.mesh_project(p, verbose=True)

cmf.connect_cells_with_flux(p, subsurface_lateral_connection)
if surface_lateral_connection:
cmf.connect_cells_with_flux(p, surface_lateral_connection)

for o_cell in outlet_cells:
self.connect_outlet_cell(o_cell, subsurface_lateral_connection, surface_lateral_connection)





load_meteo(p)

self.project = p
self.outlet_cells = outlet_cells

if __name__ == '__main__':

p = Model(cmf.DarcyKinematic, cmf.KinematicSurfaceRunoff, 1)


Binary file removed demo/data/soil_lu_gw.dbf
Binary file not shown.
Binary file added demo/data/vollnkirchner_bach_cells.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions demo/data/vollnkirchner_bach_cells.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.

0 comments on commit 57df484

Please sign in to comment.