Anda di halaman 1dari 2

Technology Spotlight/ Yu-Feng Forrest Lin, Technology Editor

Python Scripting: The Return to Programming


Mark Bakker1

More than 30 years ago, before the first public version creation of publication-ready graphics. Conveniently,
of MODFLOW, programming was an essential skill for Python is the scripting language adopted by GIS software
groundwater modelers. With the advent of graphical user such as ArcGIS and QGIS.
interfaces, models could be built by clicking a series Python scripts can run MODFLOW and friends by
of buttons. This allowed modelers to spend more time using the FloPy (pronounce: Flow Pie) package (FloPy
on simulation without the need for programming skills. 2014). The FloPy package consists of a set of scripts to run
Unfortunately, models created with a user interface are MODFLOW, MT3DMS, SEAWAT, SWI, PHT3D, and
not easily reproduced, archived, or independently verified. other MODFLOW-related groundwater programs. FloPy
Modeling errors are easily made, yet difficult to find and is functional for most MODFLOW packages. It is a
correct. community project and is actively being developed by
In recent years, computer programming is making a volunteers to add new capabilities.
comeback in the form of scripting. A script is a piece of There are several analytic element computer pro-
computer code designed to perform one or more specific grams written in Python, such as the TTim code for
tasks. A script can be written, for example, to read simulating transient multi-layer flow (e.g., Bakker 2013).
GIS files, build a model, run it, analyze the output, and TTim makes use of Pythons capabilities to seamlessly
create graphical output. Scripts are also well-suited to interface with FORTRAN and C code by including small
perform data analysis from the original measurements pieces of FORTRAN code to boost performance. TTim
to the final result. As scripts are readable files, it is can be run interactively from the Python prompt or
much easier to catch and correct errors. A script is a from a Python script. You can even write your own
record of the entire modeling or data analysis process. basic analytic element program in Python as was out-
By simply running the script you reprocess the entire lined in Ground Water a few years ago (Bakker and
model or analysis. How about that for reproducible Kelson 2009).
results? There is one more important capability that needs
The advantage of using scripts to document modeling to be mentioned here: the IPython Notebook (IPython
and data analysis is recognized in many fields. For 2014). An IPython Notebook combines Python scripts
example, Baggerly and Coombes (2009) recommend the with text, mathematics, and graphical output into a single
use of scripts in response to the well-published cancer document. The amazing part is that a Notebook can
research scandal at Duke University, where patients actually be executed, which means that all Python code
were put at risk as a consequence of errors in data in the Notebook is run and all output is regenerated.
analysis. A Notebook is a full executable report of the entire
The free and open-source computer language Python modeling endeavor. Notebooks can be sent directly to
is ideal for writing scripts. Python has a simple yet clients, or can be converted to static pdf or html files.
powerful syntax and is becoming increasingly popular Entire books are written as IPython Notebooks. It is
among hydrogeologists. There are many packages for
not inconceivable that scientific journals will accept (or
Python to perform advanced tasks from statistical analysis
require?) modeling papers as IPython Notebooks in the
of large datasets to parameter optimization and the
future.
Excited about a return to programming? There are
1
many free tutorials on the web to get you started
Water Resources Section, Civil Engineering and Geosciences,
Delft University of Technology, Delft, The Netherlands; mark.bakker with Python scripting. A good introduction is the free
@tudelft.nl book Python in Hydrology which provides a practical
2014, National Ground Water Association. introduction into the language including many examples
doi: 10.1111/gwat.12269 related to hydrology (Tomer 2011).

NGWA.org Groundwater 1
References Bakker, M., and V.A. Kelson. 2009. Writing analytic element
programs in Python. Ground Water 47, no. 6: 828834.
Baggerly, K.A., and K.R. Coombes. 2009. Deriving chemosen- FloPy. 2014. http://code.google.com/p/flopy/
sitivity from cell lines: Forensic bioinformatics and repro- IPython. 2014. http://ipython.org/notebook.html
ducible research in high-throughput biology. Annals of Tomer, S.K. 2011. Python in Hydrology. http://www.green
Applied Statistics 3, no. 4: 13091334. teapress.com/pythonhydro/pythonhydro.html
Bakker, M. 2013. Semi-analytic modeling of transient multi-
layer flow with TTim. Hydrogeology Journal 21, no. 4:
935943.

2 Groundwater NGWA.org

Anda mungkin juga menyukai