Modeling soil water flow in Python and Excel

0 downloads 0 Views 622KB Size Report
Modeling soil water flow in Python and Excel. Christopher Teh ..... This book is also not an introduction or tutorial of how to program in Python language or how ...
Modeling soil water flow in Python and Excel Christopher Teh Boon Sung

Contents

Contents

..................................................................................................... ii

Preface

......................................................................................................v

Chapter 1

Soil and water ..............................................................................1

1.1

Soil components and phases .......................................................1

1.2

Soil moisture content ..................................................................4

1.3

Interrelationships between soil properties ...................................5

1.4

Soil texture .................................................................................7

1.5

Soil water characteristics ............................................................9

Chapter 2

Water balance ............................................................................ 14

2.1

Water balance components ....................................................... 14

2.2

Rain interception by canopies ................................................... 17

2.3

Evapotranspiration: Potential and actual ................................... 20

Chapter 3

Water flow ................................................................................. 27

3.1

Soil water potential ................................................................... 27

3.2

Soil water flow ......................................................................... 32

Chapter 4 4.1

Mathematical modeling of soil water flow ................................ 38 Soil profile partitioning............................................................. 38

ii

4.2

Soil moisture characteristics ..................................................... 40

4.3

Soil layer depth and cumulative thickness ................................. 42

4.4

Root extraction of water ........................................................... 43

4.5

Hydraulic conductivity ............................................................. 44

4.6

Matric suction and gravity heads............................................... 45

4.7

Water content ........................................................................... 46

4.8

Scaling potential to actual evapotranspiration ........................... 49

4.9

Water table (ground water) ....................................................... 50

4.10

Net rainfall ............................................................................... 50

4.11

Model information to be provided by user ................................ 51

4.12

A note of time step for modeling soil flow ................................ 52

Chapter 5

Python implementation of the soil water model ....................... 54

5.1

Program structure of PyWaterBal ............................................. 54

5.2

Model input file: initializing the model ..................................... 57

5.3

Daily information: daily data file .............................................. 61

5.4

Soil water modeling .................................................................. 66

5.5

Storing the simulation results .................................................... 80

5.6

Plotting the simulation results ................................................... 85

5.7

Executing or running the soil water model ................................ 98

Chapter 6

Excel implementation of the soil water model ........................ 102

iii

6.1

Program structure of xlWaterBal ............................................ 102

6.2

Cell names .............................................................................. 103

6.3

Daily data ............................................................................... 106

6.4

Implementing the equations: Model worksheet ....................... 109

6.5

Model loop, initialization, and update: Control worksheet ...... 120

6.6

Model output: Output worksheet............................................. 122

Chapter 7

Soil water simulations ............................................................. 127

7.1

Soil texture and homogeneity of soil profile ............................ 127

7.2

Water table ............................................................................. 133

7.3

Rainfall amount and distribution ............................................. 135

References

.................................................................................................. 139

Appendix A Installing Python...................................................................... 142 Appendix B Installing BuildIt...................................................................... 146

iv

Preface Soil water is one of the most important factors in crop growth and yield. The availability of water in the soil determines if a given crop is experiencing water stress and if so, to what degree. For maximum growth rate and yield, a crop needs, among other factors, sufficient amount of water. In water-stressed conditions, plants reduce the opening size of the stomata; thereby, protecting themselves against excessive water loss via transpiration, but the drawback is the gas exchange between the stomata and atmosphere becomes also limited. Thus, photosynthesis is reduced, and if this condition is prolonged, plant growth and yield are in turn reduced. Soil water content is not constant but dynamic because water is not static within the soil but flows, albeit slowly, driven by a potential gradient, from a wet area of a soil to a dry area, for instance, or from the top soil to the subsoils beneath. A soil receives water from various sources such as rain, irrigation, run-in, and groundwater, and a soil can also lose water via evaporation, plant water uptake, deep percolation, and run-off. These various components of soil water input and output define the soil water balance, and solving the water balance for a given period determines the amount and availability of water to the crop, and, if required, the amount of additional water that needs to be supplied via irrigation to overcome any shortfall in soil water. Considering its importance to agriculture, soil water is therefore an essential subject taught to all agriculture, particularly soil science, students. Soil water flow, however, are often taught in a rather abstract and theoretical manner. Emphasis on calculus to describe soil water flow, though understandably necessary to be

v

mathematically rigorous, unfortunately compounds the learning problem because calculus can be daunting to most students as they find calculus concepts difficult to grasp and apply in practice. Therefore, this book is designed to be more practical in nature, that aims to bridge the gap between theory and practice, between understanding how soil water flow can be described in a series of equations and how these equations can be applied in practice to work out how much water is in a soil, even down to a particular depth or layer of a soil. To accomplish this task, this book first describes how soil water flow can be modeled using mathematical principles, then how the various soil water equations can be implemented as a computer program. Finally, this book describes how the computer program can be used to simulate the various soil water fluxes and soil water content in various soil layers in the soil profile. That readers undergo these three successive steps is essential because these steps help to actualize the theoretical concepts of soil water flow into a concrete and practical tool that enables readers to understand how soil water theory is applied in practice. Purpose of book and target audience: This book is primarily intended for soil science students (both senior undergraduates and postgraduates), as well as researchers, to: 1) understand how and why water flows in the soil and what factors affect its flow; 2) how the soil water flow can be described as a set of mathematical equations; and vi

3) how these equations can be implemented into a computer program in Python language and in Microsoft Excel to simulate the soil water flow in one dimension (vertical direction only). What this book is not about: The soil water model developed in this book is for educational purposes, developed from the general principles of soil water flow. This model is a hands-on example of how theory can be applied in practice by implementing a soil water model as a computer program and running simulations to answer some basic scenarios. It is hoped that by learning how a simple soil water model can be developed and used, readers would be able to extend this model or even develop their own from scratch for their specific research purposes. The soil water model is this book is not meant to be as comprehensive as possible or to be applicable in various environments or scenarios. This book's model is certainly not meant to compete with or an attempt to supplant other soil water models, such as the widely used Hydrus model (Šimůnek et al., 1998). This book is also not an introduction or tutorial of how to program in Python language or how to use the spreadsheet Microsoft Excel. This book assumes readers have at least a fair knowledge in either Python or Excel (but knowledge in Visual Basic for Applications, Excel's programing language, is not needed). Readers are spoilt for choice for learning materials on Python and Excel, for there are many good introductory books as well as free online video tutorials on these topics. For Python, the book by Lubanovic (2014) is particularly recommended for a quick start for beginners.

vii

Python and Excel are among the most widely used in the world because of their ease of use, versatility, and power. Python is an open source, high-level programming language, whereas Excel is a spreadsheet. Where Python is directly suitable to build simple to complex models, Excel is much less so. Excel however has some advantages over Python as a potential tool or platform for modeling. Unlike Python, Excel’s open tabular worksheet allows users to more easily and quickly develop mathematical models, without the need to be know any computer programming language. Moreover, Excel frees users from having to design and manage the program flow: users merely enter the various formulas, and Excel would work out the order of calculations. Nonetheless, Excel has some notable weaknesses that prevent the implementation of larger, more complex models, two of which are the lack of an explicit loop control and read-only cells feature in Excel. In model simulations, iterative calculations are very common, where a same set of equations are repeatedly used to simulate a given process or phenomenon. In native Excel, iterative calculations are done by copying formulas into new spreadsheet cells, so if a formula is used ten times in calculations, this formula has to be copied into ten cells. This copy-and-paste approach may work for simpler models, but would become very unwieldy and unmanageable for larger and more complicated models because such models often have many equations. This issue is particularly pertinent for soil water modeling. As this book will later show, modeling soil water flow and content involves about 40 equations that would be repeatedly used, as many as 18,000 times, to simulate the soil water content of a given soil profile over a period of 90 simulation days. Consequently, copying-and-

viii

pasting these 40 equations into 18,000 spreadsheet cells would be impractical and very error-prone. Another major drawback of using Excel as a modeling platform is the read-only cells feature, where a cell can read the contents of other cells but not to modify them. To modify the contents of a cell, one has to directly edit (by typing) the cell contents or use Excel's programming language, Visual Basic for Applications (VBA). Because of this read-only feature, it is impossible to programmatically update the values of cells without relying on VBA. So, to overcome these two weaknesses and further make Excel more suitable as modeling platform, an addin called BuildIt was developed by Teh (2011, 2015). BuildIt is a tool developed primarily for agriculturists, most of whom are noncomputer programmers, to develop and run their mathematical models in Excel, without needing to program in VBA. BuildIt frees agriculturists to focus more on the task of modeling rather than being distracted by the intricacies of computer programming or getting their model to correctly run in a computer. However, instructions of how to use BuildIt is again beyond the scope of this book, and readers are referred to Teh (2015). Both the Python interpreter and BuildIt addin are free and can be downloaded from the websites listed in the Appendices. Book outline: The book is outlined as such that the book is divided into seven chapters, where Part 1 comprises the first four chapters that deal with the theory of soil water flow and Part 2 comprises the last three chapters that deal with how the soil water model is implemented into a computer program, first in Python, then in

ix

Excel. How simulations can be run for various scenarios are also discussed in this second part. Part 1: Chapter 1 discusses about the three phases that make up a soil, the physical properties of soils and the interrelationships between these properties, soil texture, soil water content and how it is represented, and soil water characteristics. Chapter 2 deals with the soil water balance and its various components, in particular the rainfall interception by plant canopies (net rainfall) and evapotranspiration. This chapter

also

discusses

the

difference

between

potential

and

actual

evapotranspiration, plant water stress, and how potential evaporation and transpiration values are scaled down to respective actual values. Chapter 3 primarily discusses what governs the direction and rate of water flow in the soil. Water flows in the soil because of potential gradient. Consequently, water potentials (matric and gravity potentials) and hydraulic conductivity are discussed and how they are used in Darcy law’s to describe direction and rate of soil water fluxes. Chapter 4 is the crux of the first part of the book. This chapter shows how soil water flow can be described as a series of mathematical equations. These equations will be later implemented as a computer program in Chapter 5 and 6. Part 2: Chapter 5 shows how the soil water model can be implemented in a computer program using Python language. Complete source code is included in this chapter, and sections of the code that implement the various equations governing soil water flow are individually highlighted and discussed. Likewise, Chapter 6 also shows how the soil water model can be implemented in a computer program but this time in Excel with the help of the BuildIt addin. This chapter shows how Excel formulas and cell names are used to implement the various soil water equations. x

Chapter 7 shows how the soil water model can be used to simulate the effects of various scenarios on soil water content, such as the effect of having different soil textures, heterogeneous soil profile, different water table depths, absence of rainfall, and a uniform rainfall distribution. Simulation results from these scenarios are also briefly explained, with the help of charts, in this last chapter. The Python source code for this book's soil water model can be downloaded from: http://www.christopherteh.com/soilwaterbook/python and the Excel workbook implementing the soil water model can likewise be downloaded from: http://www.christopherteh.com/soilwaterbook/excel This book is dedicated to my wife and son. Christopher Teh Boon Sung Serdang, May 2017

xi

Suggest Documents