knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

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

library(efdcr)
library(data.table)

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.

hydro_data <- structure(list(Date = structure(c(-6209, -6208, -6207, -6206, 
    -6205, -6204, -6203, -6202, -6201, -6200, -6199, -6198, -6197, -6196, 
    -6195, -6194, -6193, -6192, -6191, -6190, -6189, -6188, -6187, -6186, 
    -6185, -6184, -6183, -6182, -6181, -6180, -6179), class = "Date"), 
    Ganjiang_Q = c(511L, 625L, 619L, 591L, 524L, 480L, 450L, 428L, 405L, 
        398L, 386L, 367L, 377L, 380L, 366L, 360L, 380L, 395L, 352L, 350L, 
        372L, 380L, 440L, 482L, 548L, 610L, 717L, 1330L, 2300L, 2390L, 
        2270L), Fuhe_Q = c(96, 84, 80.3, 75.2, 92, 88, 86, 84, 84, 82, 
        78.5, 70.1, 66.7, 68.4, 70.1, 70.1, 76.9, 80.3, 82, 84, 88, 121, 
        152, 133, 127, 190, 752, 1250, 734, 453, 334), Xinjiang_Q = c(75.6, 
        69.3, 67.2, 63, 61, 57, 55, 57, 55, 55, 55, 55, 53, 55, 55, 59, 
        63, 77.7, 86.1, 96.6, 103, 105, 109, 109, 124, 337, 1580, 1620, 
        791, 461, 355), Raohe_Q = c(39.6, 40.6, 38.8, 36.8, 33.6, 34.8, 
        33.2, 34, 33.6, 30.9, 30.9, 31.3, 31.7, 32.1, 32.8, 34, 35.6, 35.6, 
        35.6, 36, 37.2, 36, 36.8, 36.8, 59.4, 407.9, 681, 396, 240.5, 173.8, 
        142.7), Xiushui_Q = c(74.25928, 76.5436, 76.5436, 71.97496, 69.69064, 
        69.69064, 67.40632, 67.40632, 67.40632, 65.122, 62.83768, 62.83768, 
        60.55336, 62.83768, 67.40632, 69.69064, 62.83768, 69.69064, 69.69064, 
        69.69064, 76.5436, 76.5436, 76.5436, 74.25928, 95.19888, 495.3356, 
        815.1404, 415.3844, 235.68456, 167.15496, 154.5912)), row.names = c(NA, 
    -31L), class = c("data.table", "data.frame"))
head(hydro_data)

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:

wq_data <- structure(list(Date = structure(c(14621, 14621, 14643, 14643, 
    14680, 14713, 14741, 14741, 14770, 14770, 14802, 14832, 14867, 14867, 
    14893, 14893, 14929, 14956, 14956, 14831, 14679, 14712, 14803, 14928), 
    class = "Date"), STN = c("Waizhou", "Lijiadu", "Waizhou", "Lijiadu", 
    "Waizhou", "Waizhou", "Waizhou", "Lijiadu", "Waizhou", "Lijiadu", "Waizhou", 
    "Waizhou", "Waizhou", "Lijiadu", "Waizhou", "Lijiadu", "Waizhou", "Waizhou", 
    "Lijiadu", "Lijiadu", "Lijiadu", "Lijiadu", "Lijiadu", "Lijiadu"), 
    DO = c(11.6, 11.6, 10.8, 10.5, 9.7, 10.2, 7.9, 7.9, 6.8, 7.6, 6.4, 
        6.4, 7.5, 6, 7.9, 6.8, 8.6, 9.7, 9.7, 6.4, 9.3, 8.7, 7.2, 8.6), 
    TP = c(0.054, 0.05, 0.005, 0.042, 0.035, 0.081, 0.027, 0.05, 0.096, 
        0.1, 0.085, 0.046, 0.089, 0.073, 0.096, 0.127, 0.012, 0.074, 0.066, 
        0.031, 0.085, 0.042, 0.081, 0.023), COD = c(1.9, 2.1, 2.2, 3.6, 
        2.3, 3.2, 2, 4, 2.3, 4.1, 1.9, 1.8, 1.7, 3.2, 2.3, 3.4, 2.6, 3.5, 
        3.2, 1.6, 3.6, 4.6, 4.1, 3)), row.names = c(NA, -24L), class = c("data.table", 
    "data.frame"))
head(wq_data)

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
head(wq_data)

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|



hxfan1227/efdcr documentation built on July 21, 2023, 9:50 p.m.