I want to build a hydrogeology model program

Hi everyone.

I’m not really sure how to preface this. so I guess I’ll just provide my background, and my reason for wanting to try and build something useful in Julia for my usage.

I recently finished my master’s degree in geophysics – specifically in geodesy in time-series analysis. I couldn’t find a job in my area of study, so I ended up taking a job at a local environmental resource and engineering consulting firm. I’m very grateful for the job. They’re a small business with a great local reputation in my area.

However, my job is mostly focused around source water protection and hydrogeology. Both of which I have very minimal knowledge in. I can tell you what a watershed is, and give a decent technical explanation of an aquifer, but beyond that, I’m pretty clueless.

Part of my job is providing ground water models for public water systems where we provide long term (20-50 year) conservative projections for sources of contamination in the groundwater (PFAS for example).

The software we use currently is called the Wellhead Analytic Element Model (WhAEM). Positives of this software is that it is free, it is somewhat easy to use in terms of entering the parameters, and it relatively fast at running the model. it’s GUI and “quality of life” usage, is not all that great.
You cannot run iterations for multiple years in one go. You cannot pan around the map to view things easily. You cannot use standard .shp, or other file types, but instead use these .bbm formats only available (as far as I know) on the EPA website. And the coordinate system is limited to UTM, which is crazy to me.

My reasoning for wanting to make something on my own is two-fold. One, having to write the code and figure out how to get it to work will increase my knowledge in this area, and two, I don’t have a hobby and thought it might be fun to challenge my self to try something I haven’t done before.

I used Julia extensively throughout grad school for geodesy with the GenericMappingTool wrapper, GMT.jl, as well as general data cleaning and manipulation, but most of what I wrote myself would probably be considered fairly simply scripts.

I guess this is my long-winded way of saying: I don’t really know where to start. I know what I would like to do, conceptually. Nice maps from existing databases. Modern data presentation. Robust and accurate calculations for the groundwater models. Not limited to a single coordinate system/reference frame. Intuitive parameterization.

This feels like an overly-ambitious project, but I have to remind myself this isn’t really FOR work and I can take all the time in the world to work on this as a hobby that just would happen to eventually benefit my career as well.

I guess I’m just looking for some advice, and what would be a good place to start in terms of packages and organization?
Any and all advice is welcome, and I hope to keep the Julia community in the loop as I attempt to make progress on my little hobby project here.

  • Rob
2 Likes

I know that Homepage - Enabling Delta Life  | Deltares is modelling all the water above and below ground in NL using Julia. If you write them an email, perhaps they can give you a contact who might be able to provide some ideas?

They developed the GitHub - Deltares/Wflow.jl: Hydrological modeling package.

3 Likes

Sweet, thanks for the information. I’ll give them a shout.

There is no better way to learn a language than a project like this where you confront puzzles with a concrete goal, rather than just more stuff.

Groundwater—don’t sweat it. Permeability, porosity and Thiel’s equation will get you most of the way there.

Data tools—DataFrames is the Swiss army knife for tabular data. Bring it in via CSV or, if you are stuck with it Excel. Clean syntax for subsetting and subtotaling. Spring up PostgresSQL for a data back end. LibPQ provides clean query tools and if you are going to be dealing with biggest data, you’ll want it. Plus more, in a bit. BBM are “just” DLG plaintext files converted to binary. Both formats are evolutionary dead ends. I haven’t been able to find enough documentation to know what is in them besides the geometry. If it’s just the geometry, QGIS may be able to parse it outside Julia.

Surface mapping—Start with GeoDataFrames, which can read shapfiles into DataFrames as IGeometry types in ArchGDAL. The other formats, such as GeoJSON, are all easy to bring in also. Use GeoMakie with a CairoMakie back end to plot. GeoMakie will take a CRS string argument or ESPS codes for projections. ArchGDAL provides lots in the way of geocomputation, but consider PostGIS extension to Postgres, which provided optimized storage of geometries in Well Known Binaries.

Subsurface mapping—Here you will want GeoStats.jl which is specifically geared to 3D. Since I work primarily in 2D, I have’t found it congenial, but that’s where I’d go for 3D.

Modelling—You’ll find a lot to work from under the general heading of “mass transfer.” earthsciml.github.io has advection, SedTrace does sediment transport models. GMD - SedTrace 1.0: a Julia-based framework for generating and running reactive-transport models of marine sediment diagenesis specializing in trace elements and isotopes JutulDarcy.jl for porous media modelling, DPFEHM.jl for vadous flow, Anasol.jl for groundwater contamination transport flow, WFlow.jl for runoff. All sorts of stuff for dealing with differentials.

As you advance go to https://cran.r-project.org/ and look at the Task Views page for Hydrology, which has a bunch of stuff. R translates readily into Julia for rolling your own and you can call R from Julia, although it can be tricky.

I’m sure there’s more, but those are the ones I know about.

3 Likes

Is it PFAS?

Yes, sorry. Typo.

Thank you for all the insight and info! I’m familiar with a few of the packages you mentioned (DataFrames, Makie), but will definitely look into the others you mentioned I’ve not used before!

1 Like

Yes, it is. There are two aspects to it.

First, it is highly ambitious even if you just view it as a software project, especially if one of your aims is to produce something which could be useful for other people. You might learn more and produce more useful results and get more fun and/or frustration if you join some existing project (especially if you have no supercomputer in your garage :wink:).

Second thing is GIGO. Without good understanding of the science behind (either in your own head, or having some expert involved), “GI” is going to occure. And as you told us, in the subject area you are

pretty clueless

Personally I were to model PFAS contamination, I’d probably start by working through a textbook on soil chemistry. Which would presuppose some knowledge of general organic and inorganic chemistry.

I don’t think what I’m trying to compute will require anywhere near “super computer” capabilities. EPA’s WhAEM software runs on the very modest work computer perfectly fine.

I think looking to other projects as a reference, as well as collaboration will definitely be useful, but I don’t know that joining a project is necessarily the route I want to pursue.

Soil chemistry isn’t necessary at all. Soil is a surface property, and not considered in most geophysical studies. Aquifers are confined by lithology usually 10-100’s of feet deep.

I am reading through a textbook currently, though. Groundwater and Wells, by Robert J. Sterret, Ph.D. It has been an interesting and fun read.

3 Likes

Thanks for the shout out. Yes we are using Ribasim to model all the surface water. Though for the subsurface we rely on an online coupling with MODFLOW 6, which is a widely used groundwater model that we help to develop with the USGS, and is written in Fortran. (I did at one point make Deltares/ModflowInterface.jl)

I am not aware of any analytical element method (AEM) code in Julia, would be great to have one. I should tag my colleague @Huite who’s been hacking on both AEM code & QGIS plugins for them as well as Julia simulation, just not both in the same project yet :wink:

3 Likes

I have some python code for an AEM here: GitHub - vcantarella/study_project: rbf aem modelling script. I have been trying to find the time to port and update this to julia. Would love to contribute to groundwater modelling tools. I have some sketches myself.

1 Like

FWIW the page for EarthSciML is at a different URL: Home · EarthSciML. We’re friendly!

Super cool! I’m still reading through some text books and getting more familiar with WhAEM – making detailed notes on things I want to incorporate as well as change. But as soon as I start writing more meaningful code, we should chat :slight_smile:

You’ve got some fantastic stuff going on with Ribasim! I read a through a few of the publications and they’re super interesting.

I initially looked into MODFLOW for groundwater, but it was a little overkill for what I needed – but I should try and learn it anyway just for fun. Might give me a better picture of what exactly I’m aiming for with my hobby-project.

I’m sure I’ll be referencing back to both Wflow and Ribasim frequently!

1 Like

Hi @GeodeticR,

I work at the Deltares groundwater department, and I have interests in both Julia and analytic element modeling as @visr mentions.

WhAEM & GFLOW

I’m also somewhat familiar with WhAEM. WhAEM is based on Henk Haitjema’s GFLOW program. I’ve recently put some work in ensuring the GFLOW source code remains available. I’ve also made some changes such that it will run on Linux and macOS: USEPA/gflow1
I’ve also created a basic QGIS plugin to define GFLOW models: Huite/gflow-plugin: QGIS plugin for the GFLOW analytic element program

I haven’t looked to closely at WhAEM specifically yet, but it’s essentially a pared-down version of GFLOW if memory serves me right. The limitations you mention are mostly limitations (or simplifications) by the user interface, not the computational kernel. The GUI writes text input for GFLOW. I reckon that the QGIS plugin solves several of your complaints (file formats, UTM, panning, etc.). I’ve also considered setting a basic Python library to produce model input and read back the GFLOW outputs (the equivalent of what Flopy is to MODFLOW 6 if that makes sense to you). A QGIS-centered version can be found here: gflow-plugin/plugin/gflow/core/elements at main · Huite/gflow-plugin

Something like this would make it relatively straightforward to run multiple iterations, run scenarios, etc. (You just write a little Python script with whatever logic you’d like). GFLOW is used with some regularity, also e.g. by midwest USGS folks. But anyway, this is all within the existing confines of WhAEM/GFLOW.

AEM modeling

You might be interested in a bit of background / context:

The analytic element method is a rather nice technique for groundwater modeling; Darcy’s law is linear so we can define some potential and superpose the different elements (i.e. points, lines, polygons). We can skip several steps that finite difference/element/volume methods require: no spatial discretization and the domain is infinite. The primary benefits in my view are transparency and simplicity, which makes it very suitable to quickly get a basic model running – and basic models are sufficient for the majority of geohydrological problems.

The most active AEM models are:

MLAEM (Otto Strack) and GFLOW/WhAEM (Henk Haitjema) are Fortran77 codes, and don’t have great prospects for the future. Though Otto’s son is working on a new ImGui user interface for MLAEM and I’ve obviously been spending a little bit of effort myself in keeping GFLOW usable. AEM modeling is a rather small niche though; especially in the US most people just use MODFLOW. To give an impression, there is a bi-annual AEM conference (before the MODFLOW & More conference) which has around 15 attendees (of which at least half are over sixty years old). Nevertheless, AEM still manages to attract some younger nerds. :wink:

The situation for WhAEM / GFLOW is also a bit shaky: Steve Kraemer is the person at EPA responsible for it, and he’ll be retiring soon. I’ve been in touch with Steve for publishing the GFLOW code, and as far as I know, he has no successor at the EPA.

Julia and AEM

I’ve done some basic AEM exercises in Julia; it’s straightforward to get a simple model running. If you’d like to get a feel, I recommend this paper by Mark Bakker: Writing Analytic Element Programs in Python - Bakker - 2009 - Groundwater - Wiley Online Library

You can basically convert the Python classes to Julia structs and you’ll have a basic single-layer AEM modeling tool. Julia is obviously well suited for writing an AEM simulator, since the basic components are just (special) mathematical functions, a linear solver, and multi-dimensional arrays. I mostly work with TimML and TTim since we almost always need multiple aquifers in the Netherlands. GFLOW supports only a single layer, though it does support unconfined flow where potential is a function of h^2 with h measured from the bottom of the aquifer. This doesn’t generalize to multiple layers.

Anyway, by my impression both GFLOW and WHAEM see quite some use in the US I believe a new and maintable program would be both useful and relevant. This wouldn’t be too bad to do: GFLOW/WhAEM is a comparatively simple and limited AEM program (single-layer, steady-state). My ideal view would be to start with a GFLOW replacement and gradually add multi-layer and transient capabilities. TimML and TTim are Python programs and suffer somewhat in the performance department because of it; in particular if Julia’s static compilation capabilities improve, we’d get best of both worlds: a scriptable open source library (like TimML) and a fast executable (like GFLOW) which can easily be called from e.g. QGIS.

Getting funding will not be easy though. AEM is niche and most organizations will probably have an abstract ambition to move towards MODFLOW 6 instead. It’ll have to start out as a hobby project / internally funded.

Anyway, feel free to get in touch with me; I’ve sent a direct message to you with my e-mail address.

Suggested reading

I’d recommend starting out with the paper mentioned above, it’s very concrete and should align with your interests directly. Secondly, Henk Haitjema has written a practical and approachable book which is also very relevant for day-to-day modeling. You might also be interested in Mark Bakker’s latest book:

8 Likes