{{argument|relat1=comment|id=arg2933|type=truth|content=ChlorineDose on jostain syystä evaluoimatta, mikä on kummaa ja aiheuttanee harmia. En vielä löytänyt syytä. Ajoin vähän analyysiä: [http://en.opasnet.org/en-opwiki/index.php?title=Special:RTools&id=WdFiTMCvjpIgDXbs]|sign=--[[User:Jouni|Jouni]] ([[User talk:Jouni|talk]]) 13:53, 29 August 2019 (UTC)}}
<rcode label="Run on own computer (currently doesn't work there either, though)" name="plotlydata">
<rcode label="Run on own computer (currently doesn't work there either, though)" name="plotlydata">
# layout(#sliders = list(list(active = 0, #Determines which button (by index starting from 0) is considered active.
layout(sliders = list(list(active = 0, #Determines which button (by index starting from 0) is active.
# currentvalue = list(prefix = "Raw water class"), # the text under the graph that tells what the slider values mean
currentvalue = list(prefix = "Chlorine dose: "),
# scale = steps_ch)),
# the text under the graph that tells what the slider values mean
# updatemenus = list(list(active= 0,
steps = steps_ch)),
# currentvalue = list(prefix = "Raw water class"),
updatemenus = list(list(active = 0,
# buttons = buttons_water)),
buttons = buttons_water)),
# barmode = 'stack', # stacked plot instead of each disease its own bar
title = paste('Burdens of disease of drinking water in a population of', total_population),
# title = paste('Burdens of disease of drinking water in a population of', total_population),
xaxis = list(title ="DALY"),
# xaxis = list(title ="DALY"),
yaxis = list(title =""))
# yaxis = list(title =""))
p
#p
</rcode>
</rcode>
Revision as of 11:38, 30 August 2019
Obs! Water guide will be updated during summer 2019. Currently the results can only be seen by updating the result page approximately a minute after beginning to run the code.
Water guide - An assessment of the health impacts of water quality addresses the potential microbiological health risks of drinking water. These microbiological risks are due to the contamination of raw water with microbes that cause potential health problems for people using tap water, as well as the efficiency of drinking water treatment, which can be insufficient for removing harmful microbes from drinking water. The assessment will be used to determine, how high the health risk is from certain microbes in raw water. The assessment is based on a mathematical Water guide -model, which can be found below.
How to assess the microbiological risks of drinking water as well as their health effects? Information of water treatment plants must be possible to use as raw data.
# This is code Op_en6177/ on page [[Water guide]]
library(OpasnetUtils)
library(ggplot2)
objects.latest("Op_en6177", code_name="waterguide") # [[Water guide]] fetch the whole model
# Create ovariables from user input data
RawClass <- Ovariable("RawClass", data=data.frame(RawWaterClass = rawclass, Result=1))
Treatment <- Ovariable("Treatment", data=data.frame(TreatmentMethod=c(treatment, "None"), Result=1))
ChlorineDose <- Ovariable("ChlorineDose", data=data.frame(Result=chlorinedose))
RawConsumption <- Ovariable("RawConsumption", data=data.frame(Result=rawconsumption))
# divide the given population size to different age groups based on age distribution of all of Finland
population <- Ovariable("population",
dependencies=data.frame(
Name=c("total_population")
),
formula=function (...) {
population2 <- Ovariable(
"population2",
ddata="Op_en2949", subset="Population"
)
population2 <- EvalOutput(population2)
population <- population2/oapply(population2, cols = "Age", FUN=sum) * total_population
return(population)
}
)
# if the raw concentrations were chosen to be given by hand, put them into an ovariable
# if some raw water class was chosen, this isn't done, and instead the data for microbe concentrations for that class is used
if (rawclass == "Hand input") {
RawConcentration <- Ovariable(
"RawConcentration",
data=data.frame(
Pathogen=c(
"campylobacter",
"E.coli O157:H7",
"rotavirus",
"norovirus",
"cryptosporidium",
"giardia"),
Result=c(
Campylo,
E.coli,
Rota,
Noro,
Crypto,
Giardia)
)
)
}
BoDattr <- EvalOutput(BoDattr, verbose=FALSE, forceEval=TRUE)
cat("Pathogen concentrations in the raw water, microbes/l.\n")
oprint(summary(RawConcentration))
cat("Exposure to people, number of microbes ingested in a day with drinking water.\n")
oprint(summary(exposure))
cat("Disease burden, DALYs caused per day (DALY = disability adjusted life years) \n")
oprint(summary(BoDattr, marginals=c("Response","Exposure_agent")))
ggplot(
oapply(unkeep(BoDattr, sources=TRUE), NULL, mean, "Iter")@output,
aes(x=Exposure_agent, weight=BoDattrResult, fill=Response)) +
geom_bar() +
coord_flip() + theme_gray(base_size=24)+
labs(
title="Disease burden of waterborne microbes",
subtitle=paste("in a population of", sum(result(population))),
y = "Disease burden (DALY/day)"
)
# calculate the number of cases
cases <- BoDattr/case_burden
ggplot(
oapply(unkeep(cases, sources=TRUE), NULL, mean, "Iter")@output,
aes(x=Exposure_agent, weight=Result, fill=Response)) +
geom_bar() +
coord_flip() +
theme_gray(base_size=24)+
labs(
title="Ilnesses caused by waterborne microbes",
subtitle=paste("in a population of", sum(result(population))),
y = "Cases of illness"
)
cat(paste("In Finland, the illness cases due to drinking water should be on average less than 0.01% of the population per year, or 1 case for every 10 000 people. The graphs here show the case burdens and numbers of cases for each of the pathogens that are caused in one day in a population of", total_population, ", with the average daily cold water consumption of", rawconsumption, "liters per person. \n"))
The result page opens in a new tab by pressing the Run model -box. It will take approximately 40 seconds for the model to run, after which the results will appear on the result page.
User instructions for the Water guide -model
1. Choose classification of raw water
Ground water - Clean: clean ground water
Ground water - Surface water load: f.ex. shore infiltration
Surface water - Low load: relatively clean surface water
Surface water - Medium load: f.ex. low waste water load
Surface water - High load: f.ex. waste water load
OR
Choose 'I will determine microbe concentration by hand'. Write pathogen concentrations in their respective boxes.
2. State the concumption of drinking water per 24 h in liters per day per person (default 1.153 l/d).
3. State the population size of target area. (default 100000)
4. Choose treatment processes used. Obs! You can choose multiple options. If none of the first six treatment processes are used, choose "None of the above cleaning methods". If neither UV nor ozone is used, choose "None of the above disinfection methods".
5. Choose whether chlorination is used or not by inputing the chlorine dose used (mg/l). If there is no chlorination, the dose will be 0 mg/l (default 1.5 mg/l).
6. You can see the results in a new tab by pressing 'Run code'
The first two tables and one Figure at the end of the page you can see the starting values inputed into the model. The health effects are reported as two measures:
How many cases of gastroenteritis there are in the area per year.
How many DALYs or disability adjusted life years are lost due to those cases of gastroenteritis each year in the area.
Rationale
The model has been translated from Analytica to R. You can find the original model here (page in Finnish, link to the model code at the top): op_fi:Tiedosto:Vesiopas.ANA. If the user does not give concentrations for the pathogens, the values on page Pathogen concentrations in raw water will be used.
Health-based quality requirements and recommendations have been implanted on the quality of household water. In Finland, the ministry of social affairs and health is responsible for the legislation of the quality, and monitoring it is the responsibility of municipal health protection officials. Upholding and developing good water quality require high-standard research and cooperation between different parties. Ground waters and artificial ground waters are usually not disinfected. The chemicals and microbes in raw water and byproducts of disinfection produced in household water production can present health risks to the people using the household water. Water leaving the treatment plant can stay in the pipes for a long time. If the circumstances are favourable for microbial growth, the water can become low in quality and even detrimental to health while in the pipe network.
Household water is produced from either ground or surface water. The problems of these types of waters as raw water are different. Using surface water always requires establishing an actual treatment plant and the associated knowledge, skills, technologies and educated monitoring personnel. Ground water on the other hand doesn't require very complex treatment, so not many treatment plant personnel are needed, and there is less monitoring. Additionally today there are many treatment plants that produce artificial ground water. The qualities of artificial ground water can be similar to good ground waters, but the quality of the water is often only be equal to medium quality surface water.
Treatment of ground water usually includes increasing the pH and and hardness of water. This can be done using different techniques, of which the use of calcium hydroxide and carbon dioxide to regulate pH are the most common. Sometimes also precipitation of iron or manganese is required using strong oxidisers such as permanganate or chlorine. Low quality ground water is also disinfected.
In order to make surface water drinkable, it has to be heavily treated. The hardest thing is to precipitate the humus. This is done by using not only different precipitation chemicals, also for example adjust pH and breaking down the humus with strong oxidisers such as ozone. On top of that, the precipitated chemicals (such as salts of aluminium and iron) need to be removed and water hardness raised so that the pipelines don't disintegrate over time. Also, the population has to be protected from the microbes always present in surface waters, so the water needs to be disinfected to remove pathogens.
The quality of water is also affected by the condition of the pipelines and the water spends in them. If there is a lot of coagulation in the pipelines, these dregs include not only different inorganic compounds but also a large amout of bacterial mass. The coagulates in the pipelines and their qualities have started to be researched in Finland only recently.
The purpose of risk assessment is to produce information of the true size of the risk for decision-making. Risk assessment is a scientific process in which experts hold a key role. Because there are any kinds of risks to study, risk assessment processes can be very different. In environmental health risk assessment consists of four steps:
Identifying the danger (does the variable researched pose a danger to humans?)
Assessing the exposure-response function (how big a dose results in how big a response?)
Assessing exposure (how much are humans exposed?)
Characterising the risk (how high is the health risk?)[1]
All water treatment plants should periodically do risk assessment on on the household water they produce. It is done to identify actions to be taken in different crisis situations and prepare plans for different problematic situations and possible damage. Different treatment plants and for example vacation centers need different kinds of plans and implementations.
library(OpasnetUtils)
library(ggplot2)
library(plotly)
objects.latest("Op_en6177", code_name="waterguide") # [[Water guide]] fetch the whole model
total_population <- 10000
# Create ovariables from user input data
RawClass <- Ovariable("RawClass", data=data.frame(RawWaterClass = "Surface water - high contamination", Result=1))
Treatment <- Ovariable("Treatment", data=data.frame(TreatmentMethod=c("None"), Result=1))
RawConsumption <- Ovariable("RawConsumption", data=data.frame(Result=0.8))
# divide the given population size to different age groups based on age distribution of all of Finland
population <- Ovariable("population",
dependencies=data.frame(
Name=c("total_population")
),
formula=function (...) {
population2 <- Ovariable(
"population2",
ddata="Op_en2949", subset="Population"
)
population2 <- EvalOutput(population2)
population <- population2/oapply(population2, cols = "Age", FUN=sum) * total_population
return(population)
}
)
# create data
aval <- list()
for(step in seq(0, 1, 0.1)){
ChlorineDose <- Ovariable("ChlorineDose", data=data.frame(Result=step))
BoDattr <- EvalOutput(BoDattr, verbose=FALSE, forceEval=TRUE)
plotdata <- oapply(unkeep(BoDattr, sources=TRUE), NULL, mean, "Iter")
plotdata <- oapply(plotdata, FUN=sum, cols="Age")
# creates a loist of lists, each list containing the data for the grapsh with one of the chlorine doses
aval[[((step+0.1)*10)]] <-list(visible = FALSE,
name = paste0('dose = ', step),
x=plotdata@output$BoDattrResult,
y=plotdata@output$Exposure_agent,
response=plotdata@output$Response)
}
aval[1][[1]]$visible = TRUE # the figure with clorine dose 0 is set to visible
# this bit is to move the first dose to be the last, because the figure is for some reason
# draws the last to be the first, and I don't understand, but like this they're in the right
# order in the picture
aval <- aval[c(2:length(aval), 1)]
# create steps and plot all traces
steps_micro <- list()
p <- plot_ly(type = 'bar', orientation = "h")
for (i in 1:length(aval)) {
p <- add_trace(p, # add bars to bar graph p
x=aval[i][[1]]$x, # x (DALYs) on x
y=aval[i][[1]]$y, # y (exposure agent) on y
visible = aval[i][[1]]$visible, # visibility was set earlier
text = aval[i][[1]]$response,
type="bar",
hoverinfo = "text+x", # what the info shown when mouse on top of it says
orientation="h")
step <- list(args = list('visible', rep(FALSE, length(aval))), # set all steps to not visible
method = 'restyle',
label= (i-1)/10) # Sets the text label to appear on the slider
step$args[[2]][i] = TRUE # set data on i step to be visible when step i is chosen
steps_micro[[i]] = step # make a list with all the steps
}
# add slider control to plot
p <- p %>%
layout(sliders = list(list(active = 0, #Determines which button (by index starting from 0) is considered active.
currentvalue = list(prefix = "Chlorine dose (mg/l): "), # the text under the graph that tells what the slider values mean
steps = steps_micro)),
barmode = 'stack', # stacked plot instead of each disease its own bar
title = paste('Burdens of disease of drinking water in a population of', total_population),
xaxis = list(title ="DALY"),
yaxis = list(title =""))
p
library(OpasnetUtils)
library(ggplot2)
library(plotly)
objects.latest("Op_en6177", code_name="waterguide") # [[Water guide]] fetch the whole model
total_population <- 10000
# Create ovariables from user input data
RawClass <- Ovariable("RawClass", data=data.frame(RawWaterClass = "Surface water - high contamination", Result=1))
Treatment <- Ovariable("Treatment", data=data.frame(TreatmentMethod=c("None"), Result=1))
ChlorineDose <- Ovariable("ChlorineDose", data=data.frame(Chlorine=c("None","Low","High"), Result=c(0, 0.5, 1)))
RawConsumption <- Ovariable("RawConsumption", data=data.frame(Result=0.8))
# divide the given population size to different age groups based on age distribution of all of Finland
population <- Ovariable(
"population",
dependencies=data.frame(
Name=c("total_population")
),
formula=function (...) {
population2 <- Ovariable(
"population2",
ddata="Op_en2949", subset="Population"
)
population2 <- EvalOutput(population2)
population <- population2/oapply(population2, cols = "Age", FUN=sum) * total_population
return(population)
}
)
BoDattr <- EvalOutput(BoDattr)#, verbose=FALSE), forceEval=TRUE)
plotdata <- oapply(unkeep(BoDattr, sources=TRUE), NULL, mean, "Iter")
plotdata <- oapply(plotdata, FUN=sum, cols="Age")
plot_ly(plotdata@output, x = ~BoDattrResult, y = ~Exposure_agent,
type = 'bar',
orientation = "h", # bars vertically or horizontally
color = ~Response, # what to use as a basis for colored groups
colors=c("sandybrown", "gray50", "darkorchid1", "aquamarine1", "firebrick1",
"cornflowerblue", "gold1", "chocolate3")) %>% # the colors used
# in the order that the diseases appear in the table. not level order. table order.
layout(barmode = 'stack', # stacked plot instead of each disease its own bar
title = paste('Burdens of disease of drinking water in a population of', total_population),
xaxis = list(title ="DALY"),
yaxis = list(title =""))
steps <- list()
pl <- plot_ly()
for(i in levels(ChlorineDose$Chlorine)) { # add data for each slider step (=each chlorine level)
tmp <- plotdata[plotdata$Chlorine==i , ] # Slice rows for each chlorine level at a time
pl <- add_trace( # Add a separate dataset for each step
pl,
x = tmp$Exposure_agent,
y = tmp$BoDattrResult,
name = tmp$Response,
type = "bar",
# orientation = "h",
visible = i==levels(ChlorineDose$Chlorine)[1] # Make only the first dataset visible by default SOMETHING STRANGE HERE
)
step <- list(
args = list('visible', i==levels(ChlorineDose$Chlorine)), # Make all datasets invisible in this step except this one
label = i,
value = match(i,levels(ChlorineDose$Chlorine)),
method = 'restyle' # I suppose this means that the graph is retyled when the step changes
)
steps[[match(i,levels(ChlorineDose$Chlorine))]] <- step
}
pl %>% layout(
sliders = list(list(
active = 0, # Make the first step active by default (counting starts from 0 in plotly)
currentvalue = list(prefix = "Chlorine: "),
steps = steps
)),
barmode="stack"
)
# calculate the number of cases
cases <- BoDattr/case_burden
cases <- oapply(unkeep(cases, sources=TRUE), NULL, mean, "Iter")
cases <- oapply(cases, FUN=sum, cols="Age")
plot_ly(cases@output, x = ~Result, y = ~Exposure_agent,
type = 'bar', orientation = 'h',
color = ~Response, width = 3,
colors=c("sandybrown", "gray50", "darkorchid1", "aquamarine1", "firebrick1",
"cornflowerblue", "gold1", "chocolate3")) %>%
layout(barmode = 'stack',
title = paste('Cases of disease from drinking water in a population of', total_population),
xaxis = list(title ="tautitapaukset"),
yaxis = list(title =""))
###############
doses <- c("None","Low","High")
plotdata <- data.frame(
Exposure_agent = rep(c("Noro","Ecoli"),each=3),
Response = c("Gastroenteritis","Fever"),
Chlorine = doses,
BoDattrResult = c(3,2,1,6,5,4)
)
steps <- list()
pl <- plot_ly()
for(i in doses) { # add data for each slider step (=each chlorine level)
tmp <- plotdata[plotdata$Chlorine==i , ] # Slice rows for each chlorine level at a time
pl <- add_trace( # Add a separate dataset for each step
pl,
x = tmp$Exposure_agent,
y = tmp$BoDattrResult,
color = tmp$Response,
name = tmp$Chlorine,
type = "bar",
# orientation = "h",
visible = i==doses[1] # Make only the first dataset visible by default SOMETHING STRANGE HERE
)
step <- list(
args = list('visible', i==dose), # Make all datasets invisible in this step except this one
label = i,
value = match(i,doses),
method = 'restyle' # I suppose this means that the graph is retyled when the step changes
)
steps[[match(i,doses)]] <- step
}
pl %>% layout(
sliders = list(list(
active = 0, # Make the first step active by default (counting starts from 0 in plotly)
currentvalue = list(prefix = "Chlorine: "),
steps = steps
)),
barmode="stack"
)
# This is code Op_en6177/plotlydata on page [[Water guide]]
library(OpasnetUtils)
library(ggplot2)
#library(plotly)
objects.latest("Op_en6177", code_name="waterguide") # [[Water guide]] fetch the whole model
total_population <- 10000
# Create ovariables from "user input data"
RawClass <- Ovariable("RawClass", data=data.frame(RawWaterClass = c(
"Ground water - clean", "Ground water - surface water contamination",
"Surface water - high contamination", "Surface water - low contamination",
"Surface water - medium contamination"),
Result=1))
Treatment <- Ovariable("Treatment", data=data.frame(TreatmentMethod=c("None"), Result=1))
RawConsumption <- Ovariable("RawConsumption", data=data.frame(Result=0.8))
# divide the given population size to different age groups based on age distribution of all of Finland
population <- Ovariable(
"population",
dependencies=data.frame(
Name=c("total_population")
),
formula=function (...) {
population2 <- Ovariable(
"population2",
ddata="Op_en2949", subset="Population"
)
population2 <- EvalOutput(population2)
population <- population2/oapply(population2, cols = "Age", FUN=sum) * total_population
return(population)
}
)
ChlorineDose <- Ovariable("ChlorineDose", data=data.frame(ClDose=seq(0,0.5,0.1), Result=seq(0,0.5,0.1)))
BoDattr <- EvalOutput(BoDattr, forceEval=T)
plotdata <- oapply(BoDattr, c("Response","Exposure_agent","ClDose","RawWaterClass", "Iter"), sum)
plotdata <- oapply(plotdata, FUN=mean, cols="Iter")
aval <- data.frame(
visible = FALSE,
cldose = plotdata$ClDose,
result=plotdata$BoDattrResult,
pathogen=as.character(plotdata$Exposure_agent),
response=as.character(plotdata$Response),
rawclass=as.character(plotdata$RawWaterClass)
)
aval$rawclass <- factor(aval$rawclass, levels(aval$rawclass)[c(1,2,4,5,3)])
aval$visible[aval$rawclass==levels(aval$rawclass)[1]] = T # clean ground water visible
oprint(aval)
objects.store(aval)
cat("aval stored. \n")
#From here forewards the code doesn't work in Opasnet, because plotly
# create steps and plot all traces
buttons_water <- list()
p <- plot_ly(type = 'scatter', mode="markers", showlegend=F)
for (i in 1:5) {
p <- add_trace(p, # add bars to bar graph p
x=aval$result[aval$rawclass==levels(aval$rawclass)[i]], # x (BoD) on x
y=aval$response[aval$rawclass==levels(aval$rawclass)[i]], # y (exposure agent) on y
visible = aval$visible[aval$rawclass==levels(aval$rawclass)[i]],
text = aval$pathogen[aval$rawclass==levels(aval$rawclass)[i]],
mode="markers",
marker = list(color = c(rep('rgba(128,0,128,0.7)', 17),
rep('rgba(0,128,128,0.7)', 17*5))),
hoverinfo = "text+x", # what the info shown when mouse on top of it says
# orientation="h",
showlegend=T)
bw <- list(args = list('visible', rep(FALSE, length(aval))), # set all steps to not visible
method = 'restyle',
label= levels(aval$rawclass)[i]) # Sets the text label to appear on the slider
bw$args[[2]][i] = TRUE # set data on i step to be visible when step i is chosen
buttons_water[[i]] = bw # make a list with all the steps
}
steps_ch <- list(list(args = list('marker.color',
c(rep('rgba(128,0,128,0.7)', 17), rep('rgba(0,128,128,0.7)', 17*5))),
method = 'restyle',
label = "0"),
list(args = list('marker.color',
c(rep('rgba(0,128,128,0.7)', 17), rep('rgba(128,0,128,0.7)', 17),
rep('rgba(0,128,128,0.7)', 17*4))),
method = 'restyle',
label = "0.1"),
list(args = list('marker.color',
c(rep('rgba(0,128,128,0.7)', 17*2), rep('rgba(128,0,128,0.7)', 17),
rep('rgba(0,128,128,0.7)', 17*3))),
method = 'restyle',
label = "0.2"),
list(args = list('marker.color',
c(rep('rgba(0,128,128,0.7)', 17*3), rep('rgba(128,0,128,0.7)', 17),
rep('rgba(0,128,128,0.7)', 17*2))),
method = 'restyle',
label = "0.3"),
list(args = list('marker.color',
c(rep('rgba((0,128,128,0.7)', 17*4), rep('rgba(128,0,128,0.7)', 17),
rep('rgba(0,128,128,0.7)', 17))),
method = 'restyle',
label = "0.4"),
list(args = list('marker.color',
c(rep('rgba(0,128,128,0.7)', 17*5), rep('rgba(128,0,128,0.7)', 17))),
method = 'restyle',
label = "0.5")
)
# add slider control to plot
p <- p %>%
layout(sliders = list(list(active = 0, #Determines which button (by index starting from 0) is active.
currentvalue = list(prefix = "Chlorine dose: "),
# the text under the graph that tells what the slider values mean
steps = steps_ch)),
updatemenus = list(list(active = 0,
buttons = buttons_water)),
title = paste('Burdens of disease of drinking water in a population of', total_population),
xaxis = list(title ="DALY"),
yaxis = list(title =""))
p