-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhydrus1d.Rmd
572 lines (437 loc) · 25.8 KB
/
hydrus1d.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
---
title: "ENVT5503 Hydrus-1D Beginners` Guide"
subtitle: "Remediation of Soil and Groundwater"
author: "Andrew Rate"
date: "`r Sys.Date()`"
output:
html_document:
theme: yeti
code_folding: show
self_contained: no
number_sections: no
smart: no
toc: true
toc_depth: 2
toc_float: true
---
<style type="text/css">
body{
font-size: 12pt;
}
</style>
<p style="text-align:center;">![](./images/pulseAnim.gif){alt="animation of vertical solute transport pulse" width=200 height=300}<br />
<span style="text-align:center; font-size:10pt;">*Figure 1: Animation representing simulated solute transport, made with the `gganimate`<br />R package. For the `R code` to make this animation and some background information,<br />go to [https://ratey-atuwa.github.io/cybloRg/pulse.html](https://ratey-atuwa.github.io/cybloRg/pulse.html){target="_blank"}.*</span></p>
# Getting Started
This guide should enable you to create a working simulation of solute transport
using Hydrus-1D.
Start by opening the `Project Manager`, and click the `New` button:
![](./images/01a-open-project-mgr-new.png){alt="Hydrus-1D startup screen screenshot"}
In the `New Project` dialog box, type the name (and optional description), then click `OK`:
![](./images/02a-new-proj-name-callout.png){alt="New Project dialog screenshot"}
This should open the `input dialog` (the sub-window name will be the name you gave it above under `New Project`).
- Double-click on the items in the `Pre-processing` pane (left) to open them, which allows you to change input parameters.
- The right side of the window (`Post-processing`) will have items in it after a Hydrus-1D project is run
![](./images/03-input-dialog.png){alt="input dialog screenshot"}
Double-clicking on `Main Processes` gives a new dialog box – you should make sure that you check the ☑`Solute Transport` checkbox:
![](./images/04-main-processes-callout.png){alt="Main Processes dialog screenshot"}
You can just keep clicking the `Next` button to get to each part of the input set-up:
(Remember you can click the `Help` button for assistance on any screen!)
<p id="geom"> </p>
# Hints for parameter selection in each input dialog
The instructions below get you a very basic simulation with a single
substrate ("soil") material, reacting with a single solute. The
reaction is defined by simple partitioning using a *K*~d~ value, and
equilibrium is achieved instantaneously.
## `Geometry Information`
- Set `Length Units` to desired value<br />(we recommend m, but cm is OK) ![Geometry Information dialog screenshot](./images/05-geometry-info.png){align="right" width=393 height=159}
- Use one Soil Material for simple transport, but two or more for reactive barriers *etc*.
- For horizontal transport use `Decline from Vertical...` of ≤ 0.1
- Set `Depth` to desired value – this represents our flow path length, so choose something realistic for groundwater! (*e.g*. if your units are cm, Depth needs to be ≥ 1000)
## `Time Information`
- Set Time Units to desired value (days is OK) ![Time Information dialog screenshot](./images/06-time-info.png){align="right" width=266 height=248}
- Set Final Time to match column length and (later) hydraulic conductivity
- You can scale Initial/Minimum/Maximum Time Step up or down depending on whether you increase or decrease Final Time
- Leave other settings as default (for now)
You may need to return to the `Time Information` dialog later depending on the output of your initial simulation.
## `Print Information`
- Set Number of Print Times to enable plotting profile information at different times (*e.g*. 5-10)
- Then click `Select Print Times...` and click `Default` (you can try the other settings later)
![Print Information dialog screenshot](images/07-print-info.png){width=366 height=359} ![ dialog screenshot](images/07a-print-times.png){width=383 height=119}
## `Iteration Criteria`
- Leave these at their default settings for now (we don`t usually need to change these values).
![](images/08-iteration.png){width=346 height=246 alt="Iteration Criteria dialog screenshot"}
## `Soil Hydraulic Model`
- Leave at default settings for now (the van Genuchten model is a good and widely-used option for relating soil physical properties to the water retention curve.)
![](images/09-soil-hydraulic.png){width=392 height=353 alt="Soil Hydraulic Model dialog screenshot"}
## `Water Flow Parameters`
- Select the desired pre-set from the `Soil Catalog` ![Water Flow Parameters dialog screenshot](images/10-water-flow.png){align="right" width=414 height=229}
`Qr` = Residual soil water content, *q~r~*
`Qs` = Saturated soil water content, *q~s~*
`Alpha` = Parameter *a* in the soil water retention function [L^−1^]
`n` = Parameter *n* in the soil water retention function
`Ks` = Saturated hydraulic conductivity, *K~s~* [LT^−1^]
`l` = Tortuosity parameter in the conductivity function [-]
The individual values can be set manually too.
## `Water Flow Boundary Conditions`
- Leave at default settings for now
![Water Flow Boundary Conditions dialog screenshot](images/11-water-flow-BCs.png){width=310 height=311}
<p id="Solute-Transport"> </p>
## `Solute Transport`
- the default `Mass Units` are mmol, but we recommend changing to g.<br />If we set the length units to m earlier, this makes our concentration units g/m^3^, which is equivalent to mg/L
- Make sure `Number of Solutes` = 1
- Choose `Pulse Duration` to be a fraction (*e.g*. ≤ 0.1 × the `Final Time` set earlier)
![Solute Transport dialog screenshot](images/12-solute-transport.png){width=414 height=347}
<p id="Solute-Transport-Parameters"> </p>
## `Solute Transport Parameters`
- You can leave these at defaults, but FYI: ![Solute Transport Parameters dialog screenshot](images/13-solute-transp-pars.png){align="right" width=413 height=230}
(dimensions are in square brackets [ ] )
#### `Soil Specific Parameters`:
`Bulk.d.` = Bulk density, *r* [ML^−3^]
`Disp` = Longitudinal dispersivity, *D~L~* [L]
`Frac` = ...fraction of adsorption sites with instantaneous sorption...; Set = 1 for equilibrium transport
`ThIm` = Immobile water content. Set equal to 0 when *physical nonequilibrium* is not considered.
#### `Solute Specific Parameters`:
`Diffus.W` = diffusion coefficient in water, *D~w~* [L²T^−1^]
`Diffus.G` = diffusion coefficient in soil air, *D~a~* [L²T^−1^]
<p id="STRP"> </p>
## `Solute Transport and Reaction Parameters`
- Set partition coefficient `Kd` > 0 for reactive transport (leave `Kd` = 0 for non-reactive)
- for [more advanced simulations (see below)](#advanced), add a reaction rate constant (`Alpha`) parameter
- Click the `Help` button for details!
![Solute Transport and Reaction Parameters dialog screenshot](images/14-solute-transp-react-pars.png){width=680 height=231}
## `Solute Transport Boundary Conditions`
- `Bound. Cond` > 0 for each solute (`Sol. No.`) – this is the initial solute concentration, so it can`t be zero!
- Ensure concentrations are realistic and in the correct units set under `Dimensions`
- Click the `Help` button for details of the other options.
![Solute Transport Boundary Conditions dialog screenshot](images/15-solute-transp-BCs.png){width=397 height=294}
## `Do you want to run PROFILE application ?`
- Yes, you do! Click [OK].
![PROFILE application screenshot](images/16-run-profile.png){width=298 height=93}
<p id="profile"> </p>
# `Profile Information` dialog
- Click `Pressure Head...`, then click the `Edit Condition` button, and select the whole column by clicking top then bottom, then set `Top` and `Bottom` value to 0 (zero) *i.e*. **saturated with water**
- You can also set other soil parameters, *e.g*. material types and observation points
– see the video!
- Make sure you click save 💾 (you might need to press the [`esc`] key first), check the soil profile table display, then you are ready to run Hydrus – see the video!
![](images/17-profile-info.png){alt="Profle Information dialog screenshot" width=1200 height=1131}
<span style="font-size:14pt;">👉</span> When the `Profile Information` window is saved and closed, the
`Soil Profile Summary` will open automatically.
### `Soil Profile Summary`
![](images/18-profile-summary.png){align="right" width=367 height=253 alt="Hydrus-1D Soil Profile Summary screenshot"}This is a good opportunity to check that the profile is set up the way you want it to be.
- for groundwater, all values in the `h [m]` column should be zero (you might have `h [cm]` depending on your length units)
- scroll down the `Mat` column to check that all soil materials are at the depth/distance (`z [m]`) that you want them to be
- you can edit the values directly in the `Soil Profile Summary` table
When you click `Next` in the `Soil Profile Summary`, the Hydrus-1D
program will ask `Do you want to run HYDRUS-1D application ?` Usually
you do, so click `OK`.
![](images/19-H1D-calc.png){width=552 height=320 alt="Hydrus-1D Calculation screenshot"}
Look for the text `Calculations have finished successfully.` If it's
there, press Enter or just close the window.
After a successful Hydrus-1D simulation run, you can use the options in the post-processing window to visualise the output within Hydrus-1D. Alternatively, you can read the data file(s) into Excel® or R and make better graphs!
<div id="advanced" style="border: 2px solid #039; background-color:#f0f0f0; padding: 8px;">
For many applications we would want to include more complexity into
our simulation. For example, in the ENVT5503 class, we set an
assignment to simulate remediation of groundwater contamination with a
permeable reactive barrier (PRB). In this case we should consider
including:
- at least 2 'soil' materials with different properties to represent the aquifer material and the PRB (see the [`Geometry Information` dialog](#geom))
* this would be further defined as a depth range in the `Material Distribution` options of the [`Profile Information` dialog](#profile)
- a One-site sorption model (Chemical Nonequilibrium) (in the [`Solute Transport` dialog](#Solute-Transport))
- a diffusion coefficient for our solute in water (`Diffus. W.` in the [`Solute Transport Parameters` dialog](#Solute-Transport-Parameters))
- a `Frac = 1` value of zero to match non-equilibrium conditions (in the [`Solute Transport Parameters` dialog](#Solute-Transport-Parameters))
- a non-zero `Kd` value for the material representing the PRB (and potentially a lower `Kd` value for the surrounding material) in the [`Solute Transport and Reaction parameters` dialog](#STRP)
- an `alpha` value (first-order reaction rate constant) for each material (in the [`Solute Transport and Reaction parameters` dialog](#STRP) - scroll to the right; `alpha` is at the end)
</div>
```{r table1, message=FALSE, warning=FALSE, echo=FALSE}
windowsFonts(fixed=windowsFont("Courier New"))
library(flextable)
library(officer)
set_flextable_defaults(theme_fun = "theme_zebra",
font.size = 11, font.family = "Arial",
padding = 2, text.align = "right")
BorderDk <- officer::fp_border(color = "#B5C3DF", style = "solid", width = 1)
BorderLt <- officer::fp_border(color = "#FFFFFF", style = "solid", width = 1)
table1 <- data.frame(filename=c("Nod_Inf.out","Obs_Node.out",
"Solute1.out\n(& Solute2.out,...)"),
Contents=c("Separate data matrices at selected `Print times` during simulation.\nUseful columns: Depth, Conc(1..NS), Sorb(1..NS)",
"Side-by side data matrices for each node depth.\nUseful columns: time, theta, conc",
"Single data matrix for each solute. Contains columns for time, fluxes and concentrations (including cumulative values) at start of flow path (Top), Root zone, end of flow path (Bot)."))
flextable(table1) |> width(j=c(1,2), width=c(6,14), unit="cm") |>
valign(valign = "top", part="body") |>
border_outer(border=BorderDk) |> border_inner(border=BorderLt) |>
set_header_labels(filename="File name") |> fontsize(size=11, part="all") |>
set_caption(caption="Table 1: The following HYDRUS-1D output files contain useful data.", align_with_table=F, fp_p=fp_par(text.align = "left", padding.bottom = 6))
```
More detail is available in the Hydrus-1D manual. We recommend the [Hydrus-1D Tutorial (Rassam *et al*. 2018)](https://www.pc-progress.com/Downloads/Public_Lib_H1D/HYDRUS-1D_Tutorial_V1.00_2018.pdf){target="_blank"}.
Various versions of Hydrus manuals are available at [https://www.pc-progress.com/](https://www.pc-progress.com/en/Default.aspx?Downloads){target="_blank"}, the most relevant probably being Šimůnek *et al*. (2008).
# Reading HYDRUS-1D data into `R`
Users of
[Hydrus-1D](https://www.pc-progress.com/en/Default.aspx?H1d-downloads){target="_blank"}
either need to use the limited graphics in Hydrus itself, open the
output files in Excel, or devise a way of using more flexible
software like `R`.
## Reading data copied from a Hydrus-1D plot
![](images/20-copy-from-H1D-plot.png){width=262 height=315 align="right" alt="Profile information output window opened from Hydrus-1D Post-processing pane, with Concentration selected at Horizontal Variable"} This is an easier alternative to reading the data stored in the
`Nod_Inf.out` file ([described below](#reading-data-in-hydrus-1d-output-files)).
Right-click on Hydrus-1D plot of Profile Information: Concentration,
and select Copy; this will copy the data table for the plot in
tab-separated format.
Then run the following code:
```{r read-hydrus-clipboard, eval=FALSE}
hydrus0 <- read.table("clipboard", header=TRUE, sep="\t")
```
On some Mac computers this does not work, giving an error message such as:<br />
`Error in file(file, "rt") : X11 module cannot be loaded`
In that case, copy the data from the Hydrus-1D plot into Excel, and
save as a `.csv` file (*e.g*. `hydrus1.csv`) into your current RStudio
working directory.
Then just use `read.csv` to input the Hydrus-1D data:
```{r read-hydrus-csv}
hydrus0 <- read.csv("hydrus1.csv") # remember what name you gave the file!
```
<p id="settimes">Then it's useful to input some of the Hydrus-1D information
(`Final Time` (≡ total time), and number of `Print Times`):</p>
```{r set-finaltime-nprinttimes}
# specify Final Time here
# (from Hydrus-1D 'Time Information' input)
# 👇
ft <- 365 # run this line!
# specify number of Print times here
# (from Hydrus-1D 'Print Information' input)
# 👇
pt <- 10 # run this line!
(simTimes <- seq(0,ft, len=pt+1))
colnames(hydrus0)[seq(2,ncol(hydrus0),2)] <- paste("Day",round(simTimes))
colnames(hydrus0)[seq(3,ncol(hydrus0),2)] <- paste0("Dist",round(simTimes))
```
Then, **reformat the data for easier plotting** using `melt()` from
the `reshape2` package. If `Distance` is negative, we make it
positive. To enhance plots, strip off the last concentration at each time step.
```{r melt-pasted-data}
library(reshape2)
# convert to long-form using melt()
hydrus1 <- melt(hydrus0[,2:ncol(hydrus0)],
id.vars = c("T0"),
measure.vars = paste("Day",round(simTimes)))
colnames(hydrus1) <- c("Distance","Time","Concentration")
# reverse sign of distance variable
if(min(hydrus1$Distance)<0) hydrus1$Distance <- -1*hydrus1$Distance
# make final concs NA
hydrus1[which(hydrus1$Distance==max(hydrus1$Distance)),"Concentration"] <- NA
```
Check the data file:
```{r check-melted-data}
str(hydrus1)
```
### Plot the data (option 1: symbols only)
We plot the concentration (*y-axis*) *vs*. distance (*x-axis*) since
this is relevant to horizontal transport, such as flow of
**groundwater** containing solute(s).
```{r plot-melted-1, fig.width=8, fig.height=4, fig.cap="Figure 2: Plot of simulated solute concentration vs. horizontal distance for each simulation time step (showing individual simulation points), using Hydrus-1D", results='hold'}
par(mar=c(4,4,1,1), mgp=c(1.7,0.3,0), tcl=0.25,
font.lab=2, cex.lab=1.2)
palette(c("black",viridis::plasma(pt, alp=0.7)))
with(hydrus1, plot(Distance, Concentration, type="b",cex=1,
pch=rep(c(21:25),3)[Time],
bg=seq_along(simTimes)[Time],
xlab="Distance (m)",
ylab="Solute concentration (mg/L)"))
legend("topright", bty="n", inset=0.02, ncol=2,
title=expression(italic("Simulation times [days]")),
legend=round(simTimes[-1]), pt.bg=seq_along(simTimes)+1,
pch=c(22:25,21:25,21), pt.cex=1.2)
```
### Plot the data (option 2: just the lines)
If you don't like all the symbols in the plot above, try the following
(or, you can adapt the code to plot concentration on the horizontal
axis - [see below](#vert)):
```{r plot-melted-2, fig.cap="Figure 3: Plot of simulated solute concentration vs. horizontal distance for each simulation time step (showing smooth lines only), fig.height=4, fig.width=8, paged.print=FALSE, using Hydrus-1D", results='hold'}
par(mar=c(4,4,1,1), mgp=c(1.7,0.3,0), tcl=0.25,
font.lab=2, cex.lab=1.2)
palette(c("black",viridis::turbo(pt)))
with(subset(hydrus1, hydrus1$Time==levels(hydrus1$Time)[1]),
plot(Concentration ~ Distance, type="l",
ylim=c(0, max(hydrus1$Concentration, na.rm=TRUE)),
xlab="Distance (m)", ylab="Solute concentration (mg/L)") )
for (i in 2:(pt+1)){
with(subset(hydrus1, hydrus1$Time==levels(hydrus1$Time)[i]),
lines(Concentration ~ Distance, col=i,lwd=3,lty=i))
}
legend("topright", bty="n", inset=0.02, ncol=2,
title=expression(italic("Simulation times [days]")),
lty=seq_along(simTimes)+1, seg.len=4.5, legend=round(simTimes[-1]),
col=seq_along(simTimes)+1, pch=NA, lwd=rep(3,pt),
x.intersp=0.5)
```
### Of course you can use ggplot if you want!
Note that the legend uses the levels names for the factor `Time` that we made after setting the Final Time and number of Print Times ([above](#settimes)).
```{r hydrus-plot-gg, fig.width=10, fig.height=4, fig.cap="Figure 4: Plot of simulated solute concentration vs. horizontal distance for each simulation time step, using Hydrus-1D (the `ggplot` version).", message=FALSE, warning=FALSE, results='hold'}
require(ggplot2)
ggplot(hydrus1) +
geom_line(aes(x=Distance, y=Concentration, colour=Time,
linetype=Time), linewidth=1.5) +
scale_color_manual(values=c("grey",viridis::turbo(10, beg=0.05))) +
guides(color=guide_legend(title="Simulation times")) +
guides(linetype=guide_legend(title="Simulation times")) +
labs(x="Distance (m)", y = "Concentration (mg/m³)") +
theme_bw() +
theme(axis.title = element_text(face="bold", size=14),
legend.key.width = unit(4, "line"),
legend.title = element_text(face="bold", size=12))
```
## Reading data in Hydrus-1D output files
Here's my code to read the node (Profile) information
output files from Hydrus-1D (`Nod_Inf.out` in the relevant Hydrus-1D
project folder) into an **R** data frame.
```{r set-hydrus-dir-dontshow, message=FALSE, warning=FALSE, include=FALSE}
MyPC <- "C:/Users/00028958/OneDrive - The University of Western Australia/My Documents/aaTeaching/"
```
```{r read Nod_Inf.out, results='hide'}
# R code to read Hydrus-1D Nod_Inf.out files into an R data frame
# set full path to Hydrus-1D project directory (folder)
# -=-=-=-=- EDIT THIS TO MATCH THE FOLDER ON YOUR COMPUTER ! -=-=-=-=-
PCdir <- paste0(MyPC,"ENVT5503/Hydrus1D ENVT5503/PRB")
# read Nod_Inf.out file into a vector of character (text) strings
Nod_Inf_out <- readLines(paste0(PCdir,"/","Nod_Inf.out"))
# View(Nod_Inf_out) # optionally check what we just read
# find indices of some rows we want to delete
head_rows <- grep("Node", Nod_Inf_out)
# use indices to delete the rows
Nod_Inf_out <- Nod_Inf_out[-c(seq(1,7),head_rows-2, head_rows-1,
head_rows+1, head_rows+2)]
# find indices of some more rows we want to delete
ends <- grep("end",Nod_Inf_out)[-1*NROW(grep("end",Nod_Inf_out))]
# use indices to delete the rows
Nod_Inf_out <- Nod_Inf_out[-c(ends, ends+1, ends+2)]
# find indices of rows that have the Hydrus-1D print times
time_rows <- grep("Time:", Nod_Inf_out)
# extract the rows with Hydrus-1D print times into a vector
timz <- Nod_Inf_out[time_rows]
# get rid of text around the Hydrus-1D print time values...
timz <- gsub("Time: ","",timz)
timz <- gsub(" ","",timz)
# ...and convert to numbers...
timz <- as.numeric(timz)
# ...then delete the Hydrus-1D print time rows
Nod_Inf_out <- Nod_Inf_out[-c(time_rows)]
# find the rows with column names for each block of print data...
head_rows <- grep("Node", Nod_Inf_out)
# and remove all except the first one
Nod_Inf_out <- Nod_Inf_out[-c(head_rows[-1])]
# strip out all but single spaces from data...
while(NROW(grep(" ", Nod_Inf_out)) > 0) {
Nod_Inf_out <- gsub(" "," ", Nod_Inf_out)
}
# ...and (finally!) delete the very last row (an 'end' statement)
Nod_Inf_out <- Nod_Inf_out[-1*NROW(Nod_Inf_out)]
#
# write the edited output to a file...
writeLines(Nod_Inf_out, con="./NodInf3.out")
# ...and read the file in as space-delimited
node_data <- read.table(file = "NodInf3.out", header = TRUE, sep = " ")
# the is a blank column 1; rename it to "Time"
colnames(node_data)[1] <- "Time"
# use the print times vector to make a vector with
# the relevant time repeated for each block
timz0 <- rep(timz[1], NROW(node_data)/NROW(timz))
for (i in 2:NROW(timz)) {
timz0 <- append(timz0, rep(timz[i], NROW(node_data)/NROW(timz)))
}
# replace the Time colum with the vector we just made...
node_data$Time <- timz0
# ...and convert Time to a factor
node_data$Time <- as.factor(node_data$Time)
# remove temporary objects...
rm(list = c("i","head_rows","Nod_Inf_out","timz","timz0","ends"))
# ...and check the cleaned-up data
str(node_data)
```
### Plot concentration *vs*. depth
<p id="vert">This is the type of plot we would use for vertical transport, such as leaching through a soil profile.</p>
```{r conc-depth, fig.width=4, fig.height=6, fig.cap="Figure 5: Plot of simulated solute concentration vs. vertical depth for each simulation time step, using Hydrus-1D", results='hold'}
# check it with a plot
# plot as concentration vs. depth
palette(c("black",viridis::rocket(6, beg=0.15, end=0.7)))
par(mar = c(1,4,4,1), mgp = c(1.7,0.3,0), tcl = 0.3, font.lab=2)
plot(-1*(node_data$Depth) ~ node_data[,13],
type = "l", col = 1,
xlim = c(0, max(node_data[,13], na.rm=T)),
ylim = c(-1*min(node_data$Depth, na.rm=T), 0),
subset = node_data$Time==levels(node_data$Time)[1],
xaxt = "n", xlab = "", ylab = "Depth (cm)")
axis(3)
mtext("Concentration", side = 3, line = 1.7, font = 2)
symz <- c(15,19,17,8,12,9)
for (i in 2:nlevels(node_data$Time)) {
points(-1*node_data$Depth ~ node_data[,13], col = i,
subset = node_data$Time==levels(node_data$Time)[i],
type = "o", pch = symz[i-1], cex = 0.6)
}
legend("bottomright", legend = levels(node_data$Time),
col = seq(1,nlevels(node_data$Time)),
pch = c(NA,symz),
lwd = 1,
pt.cex=0.85, bty = "n", inset = 0.02,
title = expression(bold("Time (days)")))
```
### Plot as concentration *vs*. horizontal distance
This type of plot is relevant to horizontal transport, such as flow of
**groundwater** containing solute(s).
```{r conc-hdist, fig.width=8, fig.height=4, fig.cap="Figure 6: Plot of simulated solute concentration vs. horizontal distance for each simulation time step, using Hydrus-1D", results='hold'}
palette(c("black",viridis::plasma(6)))
symz <- rep(21:25,2)
par(mar = c(4,4,1,1), mgp = c(1.7,0.3,0), tcl = 0.3, font.lab=2)
node_data$Distance <- -1*node_data$Depth
plot(node_data[,13] ~ -1*node_data$Distance,
type = "l", col = 1,
ylim = c(0, max(node_data[,13], na.rm=T)),
xlim = c(0, max(node_data$Distance, na.rm=T)),
subset = node_data$Time==levels(node_data$Time)[1],
ylab = "Concentration", xlab = "Distance (cm)")
for (i in 2:nlevels(node_data$Time)) {
points(node_data[,13] ~ -1*node_data$Distance, bg = i,
subset = node_data$Time==levels(node_data$Time)[i],
type = "o", pch = symz[i-1], cex = 1)
}
legend("topright", legend = levels(node_data$Time),
pt.bg = seq(1,nlevels(node_data$Time)),
pch = c(NA,symz),
lwd = 1,
pt.cex=1, bty = "n", inset = 0.02,
title = expression(bold("Time (days)")))
```
# References
Rassam, D., J. Šimůnek, D. Mallants, and M. Th. van Genuchten, *The HYDRUS-1D Software Package for Simulating the One-Dimensional Movement of Water, Heat, and Multiple Solutes in Variably-Saturated Media: Tutorial*, CSIRO Land and Water, Adelaide, Australia, 183 pp., ISBN 978-1-4863-1001-2, 2018. [https://www.pc-progress.com/Downloads/Public_Lib_H1D/HYDRUS-1D_Tutorial_V1.00_2018.pdf](https://www.pc-progress.com/Downloads/Public_Lib_H1D/HYDRUS-1D_Tutorial_V1.00_2018.pdf){target="_blank"}
Šimůnek, J., M. Šejna, H. Saito, M. Sakai, and M. Th. van Genuchten, *The Hydrus-1D Software Package for Simulating the Movement of Water, Heat, and Multiple Solutes in Variably Saturated Media*, Version 4.0, HYDRUS Software Series 3, Department of Environmental Sciences, University of California Riverside, Riverside, California, USA, pp. 315, 2008. ([PDF 2.7MB](https://www.pc-progress.com/downloads/Pgm_Hydrus1D/HYDRUS1D-4.08.pdf){target="_blank"})
# R packages
Garnier S, Ross N, Rudis R, Camargo AP, Sciaini M, Scherer C (2024). `viridis(Lite)` - Colorblind-Friendly Color Maps for R. `viridis` package version 0.6.5. [https://sjmgarnier.github.io/viridis/](https://sjmgarnier.github.io/viridis/){target="_blank"}
Wickham, H. (2007). Reshaping Data with the `reshape` Package. *Journal of Statistical Software*, **21(12)**, 1-20. URL [http://www.jstatsoft.org/v21/i12/](http://www.jstatsoft.org/v21/i12/){target="_blank"}.
Wickham, H. (2016). `ggplot2`: *Elegant Graphics for Data Analysis*. Springer-Verlag: New York. [https://ggplot2.tidyverse.org](https://ggplot2.tidyverse.org){target="_blank"}