Skip to content
Snippets Groups Projects
Commit a5d34339 authored by Matthew Verbyla's avatar Matthew Verbyla
Browse files

took out subregion

parent 1407f132
No related branches found
No related tags found
No related merge requests found
#' The getLoadings function
#'
#' This function predicts the flow of pathogens through onsite sanitation systems for data available through the UNICEF/WHO Joint Monitoring Program and provides an output that can be used directly by the Pathogen Mapping Tool.
#' This function predicts the pathogen loadings from onsite sanitation systems for data available through the UNICEF/WHO Joint Monitoring Program and provides an output that can be used directly by the Pathogen Mapping Tool.
#' @param onsiteData A CSV file containing your onsite sanitation data. Defaults to example template from http://data.waterpathogens.org/dataset/5374462b-5bb5-456f-bfc0-816ea572666d/resource/4d9e5fba-9280-4b8b-acce-d1c87952acc1/download/onsitedata_example.csv
#' @param by Specify if you want to run the analysis by region or by subregion
#' @param pathogenType Pathogen group of interest (Virus, Bacteria, Protozoa, Helminths)
#' @keywords pathogens
#' @export
......@@ -16,7 +15,7 @@
#' 4 Nakawa 1.740476e+17 4.848475e+15 5.834954e+15 4.363628e+16 1.023125e+17 1.109438e+14 1.716174e+16 2.795611e+16 0.79 0.8394
#' 5 Rubaga 2.103805e+17 4.278101e+15 5.257688e+15 3.850291e+16 1.602164e+17 2.221318e+14 9.808800e+14 1.073880e+16 1.29 0.9490
#'
getLoadings<-function(onsiteData="http://data.waterpathogens.org/dataset/5374462b-5bb5-456f-bfc0-816ea572666d/resource/4d9e5fba-9280-4b8b-acce-d1c87952acc1/download/onsitedata_example.csv",by,pathogenType){
getLoadings<-function(onsiteData="http://data.waterpathogens.org/dataset/5374462b-5bb5-456f-bfc0-816ea572666d/resource/4d9e5fba-9280-4b8b-acce-d1c87952acc1/download/onsitedata_example.csv",pathogenType){
df1<-read.csv(onsiteData,header=TRUE) #bring in the inputs CSV file
......@@ -72,46 +71,6 @@ getLoadings<-function(onsiteData="http://data.waterpathogens.org/dataset/5374462
kValues<-c(Virus=kValueV,Bacteria=kValueB,Protozoa=kValueP,Helminth=kValueH);kValues #the units here are 1/days
# &&&&& END GWPP Inputs &&&&&
dfR<-df1
head(dfR) #the purpose of this code is to aggregate by region or by subregion
dfR[,c("sheddingRate","prevalence","flushSewer","flushSeptic","flushPit","flushOpen","flushUnknown","pitSlab",
"pitNoSlab","compostingTwinSlab","compostingTwinNoSlab","compostingToilet","bucketLatrine","containerBased",
"hangingToilet","openDefecation","other","isShared","sewerLeak","emptied","isWatertight","hasLeach",
"coverBury","emptiedTreatment","flushElsewhere","pitVIP","pitTraditional","otherLatrine",
"otherImproved","otherUnimproved","dontKnow","pitLined","pitUnlined")] <-
dfR$population*dfR[,c("sheddingRate","prevalence","flushSewer","flushSeptic","flushPit","flushOpen","flushUnknown","pitSlab",
"pitNoSlab","compostingTwinSlab","compostingTwinNoSlab","compostingToilet","bucketLatrine","containerBased",
"hangingToilet","openDefecation","other","isShared","sewerLeak","emptied","isWatertight","hasLeach",
"coverBury","emptiedTreatment","flushElsewhere","pitVIP","pitTraditional","otherLatrine",
"otherImproved","otherUnimproved","dontKnow","pitLined","pitUnlined")]
dfR$pitAdditive<-as.character(dfR$pitAdditive)
dfRe<-aggregate(.~region,data=dfR[,c("region","population")],FUN=sum)
dfR$scenario<-as.character(dfR$scenario)
pops<-aggregate(.~region,data=dfR[,c("region","sheddingRate","prevalence","flushSewer","flushSeptic","flushPit","flushOpen","flushUnknown","pitSlab",
"pitNoSlab","compostingTwinSlab","compostingTwinNoSlab","compostingToilet","bucketLatrine","containerBased",
"hangingToilet","openDefecation","other","isShared","sewerLeak","emptied","isWatertight","hasLeach",
"coverBury","emptiedTreatment","flushElsewhere","pitVIP","pitTraditional","otherLatrine",
"otherImproved","otherUnimproved","dontKnow","pitLined","pitUnlined")],FUN=sum)
pops<-pops[,-1]/dfRe$population
dfRe<-cbind(dfRe,pops)
adds<-aggregate(.~region,data=dfR[,c("region","scenario","pitAdditive")],FUN=unique)
empfreq<-aggregate(.~region,data=dfR[,c("region","emptyFrequency")],FUN=mean)
dfRe<-cbind(dfRe,adds[,-1],empfreq)
if(by=="region"){
df1<-dfRe
df1<-df1[,c("scenario","region","population","sheddingRate","prevalence",
"flushSewer","flushSeptic","flushPit","flushOpen","flushUnknown","pitSlab",
"pitNoSlab","compostingTwinSlab","compostingTwinNoSlab","compostingToilet",
"bucketLatrine","containerBased","hangingToilet","openDefecation","other",
"isShared","sewerLeak","emptied","isWatertight","hasLeach","coverBury",
"emptiedTreatment","emptyFrequency","pitAdditive","flushElsewhere","pitVIP",
"pitTraditional","otherLatrine","otherImproved","otherUnimproved","dontKnow",
"pitLined","pitUnlined")]
}else{
df1<-df1[,-which(names(df1) == "region")]
colnames(df1)[which(names(df1)=="subregion")]<-"region"
}
loops<-nrow(df1)
loadings.names <- c("virus", "bacteria", "protozoa", "helminth")
......@@ -277,7 +236,7 @@ getLoadings<-function(onsiteData="http://data.waterpathogens.org/dataset/5374462
Onsite_LRV=round(log10(excreted/(to_groundwater+to_surface+In_Sewage+In_Fecal_Sludge)),2),
Onsite_PR=round(((excreted-(to_groundwater+to_surface+In_Sewage+In_Fecal_Sludge))/excreted),4))
onsite_results=rbind(onsite_results,newRow)
};onsite_results
}
return(summaryEmissions=onsite_results)
}
......@@ -30,18 +30,19 @@ The `getloadings` function requires the following three inputs:
### Inputs:
* onsiteData
* by
* pathogenType
The input `onsiteData` should refer to a data input file from the K2P Data Portal (data.waterpathogens.org). This file must be in a very specific format. An example file can be found [here](http://data.waterpathogens.org/dataset/5374462b-5bb5-456f-bfc0-816ea572666d/resource/4d9e5fba-9280-4b8b-acce-d1c87952acc1/download/onsitedata_example.csv).
The input **`pathogenType`** should be equal to either one of the following strings: c("Virus","Bacteria","Protozoa","Helminth").
## Example
The following shows the use of the getLoadings function for data from Kampala, Uganda, grouping the data by 'region' and showing results for the 'Virus' group.
``` r
getLoadings(onsiteData,by="region",group="Virus")
getLoadings(onsiteData,pathogenType="Virus")
#> region excreted to_groundwater to_surface retained_in_soil decayed In_Fecal_Sludge In_Sewage stillViable Onsite_LRV Onsite_PR
#> 1 Central 3.470412e+16 7.208736e+14 1.241347e+15 6.487862e+15 1.696317e+16 4.204900e+13 9.142680e+15 1.114695e+16 0.49 0.6788
......
"","scenario","region","population","sheddingRate","prevalence","flushSewer","flushSeptic","flushPit","flushOpen","flushUnknown","pitSlab","pitNoSlab","compostingTwinSlab","compostingTwinNoSlab","compostingToilet","bucketLatrine","containerBased","hangingToilet","openDefecation","other","isShared","sewerLeak","emptied","isWatertight","hasLeach","coverBury","emptiedTreatment","emptyFrequency","pitAdditive","flushElsewhere","pitVIP","pitTraditional","otherLatrine","otherImproved","otherUnimproved","dontKnow","pitLined","pitUnlined"
"1","baseline","Central",63206,1e+10,0.15,0.263426061367924,0.202395074691311,0.0572373161687182,0.0122217340838053,0.00775377157635351,0.410974140237098,0.0244769600894535,0,0,0.00683590443184191,0,0,0,0.0115781193985065,0.00310091817879632,0.36387364579445,0,0.469944574538651,0,0.733457482834968,0,0.436780402865203,3,"None",0,0,0,0,0,0,0,0.230774190234282,0.211512814667089
"2","baseline","Kawempe",333024,1e+10,0.15,0.0368606217961078,0.14227447559426,0.0576012883347567,0.00167958320478404,0.00524846958020743,0.736130930539763,0.0144161741099741,0,0,0.000330690191268497,0,0,0.000106099855235659,0.00459866016635137,0.000745623980511915,0.439653607422885,0,0.218648771243003,0,0.705524168198433,0,0.211244893857533,3,"None",0,0,0,0,0,0,0,0.321520783153581,0.429357013881636
"3","baseline","Makindye",385309,1e+10,0.15,0.0285703675021632,0.259280692820702,0.0825400339090185,0.00382169240651789,0.017477094795263,0.574689696679052,0.0242897068008611,0,0,0.00140078561706319,0,0,3.44716601974e-05,0.00608242824133358,0.00183409933622884,0.428658958837024,0,0.248507908586903,0,0.740031033462107,0,0.236410708631101,3,"None",0,0,0,0,0,0,0,0.258879499859754,0.341499759151105
"4","baseline","Nakawa",317023,1e+10,0.15,0.0986066973730739,0.282278626806923,0.0659452582342858,0.0027246676720648,0.0160243515935279,0.497957290035411,0.0274612361403494,0,0,0.00055986299041079,0,0,0.000678506261280727,0.00693275665168773,0.000831022547266287,0.389882378053103,0,0.196882530687556,0,0.788037461603035,0,0.190629622132038,3,"None",0,0,0,0,0,0,0,0.215936281700867,0.31004210721095
"5","baseline","Rubaga",383216,1e+10,0.15,0.00465420135546793,0.164638786281507,0.0895414225568452,0.00179902595000731,0.0107916084996399,0.688829208869262,0.0310095892878116,0,0,0.000566465476892927,0,0,2.01319678719051e-05,0.00373505714504875,0.00439225758659868,0.441673465718561,0,0.256076888079015,0,0.989271090110588,0,0.243857357512468,3,"None",0,0,0,0,0,0,0,0.312687132801582,0.407713566210458
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment