{"id":19270673,"url":"https://github.com/emanuelhuber/gwmodbac","last_synced_at":"2025-07-14T08:12:56.010Z","repository":{"id":97063879,"uuid":"84201540","full_name":"emanuelhuber/gwModBac","owner":"emanuelhuber","description":"Groundwater flow and microbes transport modelling with R and Modflow / Modpath","archived":false,"fork":false,"pushed_at":"2018-09-28T20:39:50.000Z","size":3568,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-05T13:10:42.100Z","etag":null,"topics":["bacteria","groundwater","modeling","modflow-usg","modpath"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emanuelhuber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-07T13:21:35.000Z","updated_at":"2021-02-21T06:34:31.000Z","dependencies_parsed_at":"2023-03-13T16:19:46.685Z","dependency_job_id":null,"html_url":"https://github.com/emanuelhuber/gwModBac","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":0.09677419354838712,"last_synced_commit":"0164455332272b4f10d55493bac61f553569869f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelhuber%2FgwModBac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelhuber%2FgwModBac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelhuber%2FgwModBac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelhuber%2FgwModBac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emanuelhuber","download_url":"https://codeload.github.com/emanuelhuber/gwModBac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240371761,"owners_count":19790888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bacteria","groundwater","modeling","modflow-usg","modpath"],"created_at":"2024-11-09T20:26:26.107Z","updated_at":"2025-02-23T20:15:11.364Z","avatar_url":"https://github.com/emanuelhuber.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gwModBac\n\nGroundwater flow simulation and particle tracking to forecast microbial concentration in a drinking water extraction well.\n\n\n## Installation/Run\n\n\n### Requirement\n- \"gdal_polygonize.py\" must be installed (--\u003e `install python-gdal`)\n- MODFLOW and MODPATH must be installed (`mfusg` for MODFLOW usgs,  `mp6` for MODPATH). If you need binaries compiled for linux (ubuntu) please contact me\n- [R](https://cran.r-project.org/) must be installed\n\n### Run (file `run.R`)\nTwo possiblities:\n\n* Open R, copy-paste `run.R` or source `run.R` (but don't forget to adapt line 15 in `run.R` the `DIR` variable to your directory structure\n* Open terminal, change directory to \"gwModBac\" (`cd path/gwModBac`), enter \n\n    ```\n    Rscript --vanilla run.R sim_name 15 50 10 4 NULL 100 200 20 OK\n    ```\n\n    * `run.R` --\u003e path of the file `run.R`\n    * `sim_name` name of the simulation (an output file `sim_name.txt` will be created in the directory `gwModBac`)\n    * `15` --\u003e nx: number of cells along the x-direction = number of columns\n    * `50` --\u003e ny: number of cells along the y-direction = number of rows\n    * `10` --\u003e nz: number of cells along the z-direction = number of layers\n    * `4` --\u003e number of runs (but one output file with all the output together)\n    * `NULL` --\u003e no seed are used. To set a seed for the random number simulator, replace `NULL` by any numeric value (e.g., `10`). With a seed, you can reproduce the simulation exactly.\n    * `100` --\u003e nx_ref: number of columns of the reference simulation (nx_ref \u003e= nx), used to scale down the Gaussian Random Field (only used if a seed number is set)\n    * `200` --\u003e ny_ref: number of rows of the reference simulation (ny_ref \u003e= ny), used to scale down the Gaussian Random Field (only used if a seed number is set)\n    * `20` --\u003e nz_ref: number of layers of the reference simulation (nz_ref \u003e= nz), used to scale down the Gaussian Random Field (only used if a seed number is set)\n    * `OK` [optional] --\u003e can be anything; if the 7th argument is present, an overview plot is created for each single simulation (in the directory `simulations`): same plot as in section [Groundwater flow simulation and particle tracking](#groundwater-flow-simulation-and-particle-tracking). If absent, no plot will be created (faster).\n    \n    \nExample with fixed seed:\n    \n    ```\n    Rscript --vanilla run.R sim01 10 20 10 1 102343643 100 200 10 OK\n    ```\n\nExample without fixed seed and without plot:\n    \n    ```\n    Rscript --vanilla run.R sim01 10 20 10 1 NULL 100 200 10\n    ```\n\n### Run with config file and pre-defined \"random variables\"  (file `run_para.R`)\n\nOnly one argument: the config file `*.yaml`. All the parameters as well as their prior distributions are explained in the test file `sim_parameters.yaml`.\nTo simulate the 3D hydraulic conductivity field (random Gaussian field), you have two options:\n\n- either assign the values the 3D random Gaussian field parameter (`para: TRUE`)\n- or give directly the values of the 3D random Gaussian field parameter (`para: FALSE` and the code read the file given by `file:    'HK.txt'`): one big vector column of length (nx x ny x nz),\n   corresponding to an array of dimension **ny** x nx x nz ( = nrow x ncol x nlayers, notice that here **nrow = ny**). I haven't tested what is the order of this big vector.\n\n\n\n    ```\n    Rscript --vanilla run_para.R sim_parameters.yaml\n    ```\n\nOutput: \n\n- a text file with name  `projectName/simName.txt` (see `sim_parameters.yaml`) with a vector column corresponding to the 10-days ahead forecast\n- if `plot: TRUE` a plot `projectName/simName.png`\n\n\n### Notes\nMinimal possible grid size:\n\n* nx \u003e= 10\n* ny \u003e= 10\n* nz \u003e= 2\n\n## What does \"run.R\" Do?\n1. Read the hyperparameters/parameters from `para.R`\n2. Read the data (river stage time-series, groundwater head time-series) from `data/`\n3. Create the simulation grid (according to parameters)\n4. Define \n   * the river properties (location, stage, riverbed), \n   * the location of the specified head boundary, \n   * the particles to estimate the microbila concentration in the drinking water extraction well.\n5. Run Monte Carlo simulations (unconditional)\n    1. simulate the hydraulic properties: hydraulic conductivity (Gaussian random field), porosity, etc.\n    2. simulate the specified head boundary conditions (Gaussian process)\n        for the 10-days ahead forecast:\n        1. simulate the precipitation for the next 10 days\n        2. using a convolution model between precipitation and river stage, simulate the river stage for the next 10 days\n        3. using a convolution model between river stage and groundwater\n\t\t\theads at the observation wells, simulate the groundwater heads \n\t\t\tat the observation wells for the next 10 days\n        4. Simulate the head boundary conditions conditional on the\n\t\t\tgroundwater heads the observation wells\n        5. Interpolate from the head boundary conditions the initial heads\n    3. run MODFLOW\n    4. run MODPATH to simulate pathway of the microbes that reach the well drinking water extraction well\n    5. Simulate the microbial concentration in the river from the river stage\n    6. Predict the microbial concentration in the well according to an exponential decay model that simulates the mechanical filtration of microbes in the aquifer\n\n### Model overview\n![Model overview](model_overview.png \"Model overview\")\n\n### Groundwater flow simulation and particle tracking\n\n* contours and colour bar = hydraulic heads of the first layer\n\u003c!-- \n* blue square = drinking water extraction well \n--\u003e\n* coloured lines = paths of the particles entering into the well\n* green dots = start positions of the particles coming from the river\n* red dots = start positions of the particles that do not come from the river\n* light blue multipolygon (corner at (0, 0), (0, 150), (5, 150), (5, 0) = the river\n\n![Groundwater flow simulation and particle tracking](rea_0001.png \"Groundwater flow simulation and particle tracking\")\n\n### Convergence grid scaling with fixed seed?\n\nSome simulation results (with seed = 102343643):\n\n* Target value as a function of nx, ny, nz:\n\n![Target value as a function of nx, ny, nz](all_sim.png \"Target value as a function of nx, ny, nz\")\n\n* Target value as a function of nx, ny for nz = 10 (z-axis = target value!)\n\n![Target value as a function of nx, ny for nz = 10](nz_equal_10.png \"Target value as a function of nx, ny for nz = 10\")\n\nFor these results, I recommand to keep nz = 10 and to only vary nx and ny (more stable, better convergence).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelhuber%2Fgwmodbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femanuelhuber%2Fgwmodbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelhuber%2Fgwmodbac/lists"}