Pre-process with efdcr

The time series data used by EEMS or EFDC is usually saved in .wq format, which is a text file with first line be the number of data points and the other lines be the time series data. The data lines will be repeated for all data points. Frankly, it is a simple and clear data structure but not tidy. Hence I design the dt_to_wq() function to handle that issue.

Load required packages

Hydrological Data

Below is the tidy hydrological data, with Date column as the index. I suggest you store your hydrological data in this kind of format and then use the dt_to_wq() function to convert it into .wq files.

#>          Date Ganjiang_Q Fuhe_Q Xinjiang_Q Raohe_Q Xiushui_Q
#> 1: 1953-01-01        511   96.0       75.6    39.6  74.25928
#> 2: 1953-01-02        625   84.0       69.3    40.6  76.54360
#> 3: 1953-01-03        619   80.3       67.2    38.8  76.54360
#> 4: 1953-01-04        591   75.2       63.0    36.8  71.97496
#> 5: 1953-01-05        524   92.0       61.0    33.6  69.69064
#> 6: 1953-01-06        480   88.0       57.0    34.8  69.69064

Now we can convert it to .wq files.

dt_to_wq(measure.vars = c('Ganjiang_Q', 'Fuhe_Q'), src.dt = hydro_data, path = 'D:', 
         start.date = '1953-01-01', end.date = '1953-01-20', interval = '1 day')

Then you will find 2 .wq files in your path (‘D:’ in this case). After that you can use the import button in EEMS when setting the boundaries. It will save you much time.

Water quality data

Compared to other boundaires, prepare the water quality boundaries (i.e., cwqsrs01-21.inp) is the most trival thing when buidling a water enviroment model. However, the EEMS seems to have bugs in reading the water quality boundaies, i.e., it can not import the cwqsrsXX.inp files at once. Consequently, I come up with the set_wqbc() function. To use the set_wqbc() function, you should first convert your water quality data to .wq files with the dt_to_wq() function. After that you may easily prepare the 21 input files required by EEMS.

When use the dt_to_wq() function with water quality data, you should store your water quality data in the format below:

#>          Date     STN   DO    TP COD
#> 1: 2010-01-12 Waizhou 11.6 0.054 1.9
#> 2: 2010-01-12 Lijiadu 11.6 0.050 2.1
#> 3: 2010-02-03 Waizhou 10.8 0.005 2.2
#> 4: 2010-02-03 Lijiadu 10.5 0.042 3.6
#> 5: 2010-03-12 Waizhou  9.7 0.035 2.3
#> 6: 2010-04-14 Waizhou 10.2 0.081 3.2

Then you can use the melt() and dacast() to rehshape your water quality into the prefered format:

wq_data %>% 
  melt(id.vars = c('Date', 'STN')) %>%
  dcast(Date ~ variable + STN) -> wq_data
#>          Date DO_Lijiadu DO_Waizhou TP_Lijiadu TP_Waizhou COD_Lijiadu
#> 1: 2010-01-12       11.6       11.6      0.050      0.054         2.1
#> 2: 2010-02-03       10.5       10.8      0.042      0.005         3.6
#> 3: 2010-03-11        9.3         NA      0.085         NA         3.6
#> 4: 2010-03-12         NA        9.7         NA      0.035          NA
#> 5: 2010-04-13        8.7         NA      0.042         NA         4.6
#> 6: 2010-04-14         NA       10.2         NA      0.081          NA
#>    COD_Waizhou
#> 1:         1.9
#> 2:         2.2
#> 3:          NA
#> 4:         2.3
#> 5:          NA
#> 6:         3.2

After that, you can use the dt_to_wq() function to covert the water quality data into .wq files.

dt_to_wq(measure.vars = c(2:7), src.dt = wq_data, path = 'D:/wqs', 
         start.date = '2010-01-01', end.date = '2010-12-31', interval = '1 day')

Then you will find 6 .wq files in your path (‘D:/wqs’ in this case). After that you can use the set_wqbc() function to generate the 21 cwqsrsXX.inp files.

set_wqbc(wq_path = 'D:/wqs', cwqsrs_path = 'D:/')

Replace the original 21 cwqsrsXX.inp files with the new generated ones in your EFDC model folder. Reopen the EEMS project with the EEMS software, now the EEMS can read the new water quality boundaries.

Note that the EFDC model can only model the 21 water quality variables below. And the efdcr package match the water qualiy boundaries with corresponding abbreviations

No. Full Names abbreviation
1. Cyanobacteria Cyanobacteria
2. Diatoms Diatoms
3. Green Algae GA
4. Refractory POC RPOC
5. Labile POC LPOC
6. Dis Org Carbon DOC
7. Ref Part Org Phosphorus RPOP
8. Lab Part Org Phosphorus LPOP
9. Dis Org Phosphorus DOP
10. Total Phosphate TP
11. Ref Part Org Nitrogen RPON
12. Lab Part Org Nitrogen LPON
13. Dis Org Nitrogen DON
14. Ammonia Nitrogen NH4N
15. Nitrate Nitrogen NO3N
16. Part Biogenic Silica PBS
17. Dis Available Silica DAS
18. Chemical Oxygen Demand COD
19. Dissolved Oxygen DO
20. Total Active Metal TAM
21. Fecal Coliform FC