Skip to content
Snippets Groups Projects
Commit e1d12ea0 authored by Nauta, Lisanne's avatar Nauta, Lisanne
Browse files

Changes for new mapping tools. Nothing working yet, not tested, everything...

Changes for new mapping tools. Nothing working yet, not tested, everything still under construction.

Main.R will be used to run the model.
All plotting,writing,map creation removed. will be inserted later from code avaiable on master branch.
parent a5b0708a
No related branches found
No related tags found
No related merge requests found
iso,subarea,hdi,population,fraction_urban_pop,fraction_pop_<5,sheddingRate,prevalence_urban,prevalence_rural,flushSewer_urb,flushSeptic_urb,flushPit_urb,flushOpen_urb,flushUnknown_urb,pitSlab_urb,pitNoSlab_urb,compostingTwinSlab_urb,compostingTwinNoSlab_urb,compostingToilet_urb,bucketLatrine_urb,containerBased_urb,hangingToilet_urb,openDefecation_urb,other_urb,isShared_urb,sewerLeak_urb,emptied_urb,isWatertight_urb,hasLeach_urb,coverBury_urb,emptiedTreatment_urb,emptyFrequency_urb,pitAdditive_urb,flushElsewhere_urb,pitVIP_urb,pitTraditional_urb,otherLatrine_urb,otherImproved_urb,otherUnimproved_urb,dontKnow_urb,pitLined_urb,pitUnlined_urb,flushSewer_rur,flushSeptic_rur,flushPit_rur,flushOpen_rur,flushUnknown_rur,pitSlab_rur,pitNoSlab_rur,compostingTwinSlab_rur,compostingTwinNoSlab_rur,compostingToilet_rur,bucketLatrine_rur,containerBased_rur,hangingToilet_rur,openDefecation_rur,other_rur,isShared_rur,sewerLeak_rur,emptied_rur,isWatertight_rur,hasLeach_rur,coverBury_rur,emptiedTreatment_rur,emptyFrequency_rur,pitAdditive_rur,flushElsewhere_rur,pitVIP_rur,pitTraditional_rur,otherLatrine_rur,otherImproved_rur,otherUnimproved_rur,dontKnow_rur,pitLined_rur,pitUnlined_rur,FractionPrimarytreatment,FractionSecondarytreatment,FractionTertiarytreatment,FractionQuaternarytreatment,FractionPonds,FractionNontreatment
1,Central,0.493,63206,1,0.177278887,1.00E+10,0.15,0.15,0.263426061,0.202395075,0.057237316,0.012221734,0.007753772,0.41097414,0.02447696,0,0,0.006835904,0,0,0,0.011578119,0.003100918,0.363873646,0,0.469944575,0,0.733457483,0,0.436780403,3,None,0,0,0,0,0,0,0,0.23077419,0.211512815,0.263426061,0.202395075,0.057237316,0.012221734,0.007753772,0.41097414,0.02447696,0,0,0.006835904,0,0,0,0.011578119,0.003100918,0.363873646,0,0.469944575,0,0.733457483,0,0.436780403,3,None,0,0,0,0,0,0,0,0.23077419,0.211512815,0.035,0.035,0,0,0.45,0.48
2,Kawempe,0.493,333024,1,0.177278887,1.00E+10,0.15,0.15,0.036860622,0.142274476,0.057601288,0.001679583,0.00524847,0.736130931,0.014416174,0,0,0.00033069,0,0,0.0001061,0.00459866,0.000745624,0.439653607,0,0.218648771,0,0.705524168,0,0.211244894,3,None,0,0,0,0,0,0,0,0.321520783,0.429357014,0.036860622,0.142274476,0.057601288,0.001679583,0.00524847,0.736130931,0.014416174,0,0,0.00033069,0,0,0.0001061,0.00459866,0.000745624,0.439653607,0,0.218648771,0,0.705524168,0,0.211244894,3,None,0,0,0,0,0,0,0,0.321520783,0.429357014,0.035,0.035,0,0,0.45,0.48
3,Makindye,0.493,385309,1,0.177278887,1.00E+10,0.15,0.15,0.028570368,0.259280693,0.082540034,0.003821692,0.017477095,0.574689697,0.024289707,0,0,0.001400786,0,0,3.45E-05,0.006082428,0.001834099,0.428658959,0,0.248507909,0,0.740031033,0,0.236410709,3,None,0,0,0,0,0,0,0,0.2588795,0.341499759,0.028570368,0.259280693,0.082540034,0.003821692,0.017477095,0.574689697,0.024289707,0,0,0.001400786,0,0,3.45E-05,0.006082428,0.001834099,0.428658959,0,0.248507909,0,0.740031033,0,0.236410709,3,None,0,0,0,0,0,0,0,0.2588795,0.341499759,0.035,0.035,0,0,0.45,0.48
4,Nakawa,0.493,317023,1,0.177278887,1.00E+10,0.15,0.15,0.098606697,0.282278627,0.065945258,0.002724668,0.016024352,0.49795729,0.027461236,0,0,0.000559863,0,0,0.000678506,0.006932757,0.000831023,0.389882378,0,0.196882531,0,0.788037462,0,0.190629622,3,None,0,0,0,0,0,0,0,0.215936282,0.310042107,0.098606697,0.282278627,0.065945258,0.002724668,0.016024352,0.49795729,0.027461236,0,0,0.000559863,0,0,0.000678506,0.006932757,0.000831023,0.389882378,0,0.196882531,0,0.788037462,0,0.190629622,3,None,0,0,0,0,0,0,0,0.215936282,0.310042107,0.035,0.035,0,0,0.45,0.48
5,Rubaga,0.493,383216,1,0.177278887,1.00E+10,0.15,0.15,0.004654201,0.164638786,0.089541423,0.001799026,0.010791608,0.688829209,0.031009589,0,0,0.000566465,0,0,2.01E-05,0.003735057,0.004392258,0.441673466,0,0.256076888,0,0.98927109,0,0.243857358,3,None,0,0,0,0,0,0,0,0.312687133,0.407713566,0.004654201,0.164638786,0.089541423,0.001799026,0.010791608,0.688829209,0.031009589,0,0,0.000566465,0,0,2.01E-05,0.003735057,0.004392258,0.441673466,0,0.256076888,0,0.98927109,0,0.243857358,3,None,0,0,0,0,0,0,0,0.312687133,0.407713566,0.035,0.035,0,0,0.45,0.48
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"These are the columns the new input file will have. It would be nice to get it to run for this example, but I will need to look for a isoraster for this area and resolution. The isocodes could then also change.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Columns J - X (for urban and further down for rural) are standard JMP inputs.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"Columns AH - AN (I think) are former JMP inputs. Matt's function can deal with those, in case they are provided.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"Columns Y - AG and AO - AP are inputs that are provided by the user, or we will use standard assumptions (need to come up with those still).",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
This diff is collapsed.
This diff is collapsed.
#This code is the main code to run the GloWPa model. The model can be run for various waterborne pathogens
#and and various spatial scales and resolutions. This code is the basis for the K2P mapping tool, among others.
#This code was written by Nynke Hofstra in May 2019
#still to do:
# add possible multiplying variables for all other variables than the ones already done
# test the makeisogrids part
# do we need to perform some checks everywhere to make sure the data are in the right format? We probably do. To be done.
#In case you want to set up scenarios, you can simply change the file overall_inputs.csv
#by adding more lines.
# Set paths ---------------------------------------------------------------
rm(list=ls(all=TRUE))
model_path<<-"/home/nauta/Data/Software/GloWPa/"
wd<<-paste0(model_path,"Model output/Uganda/")
working.path.in<<-paste0(model_path,"Model input/Uganda/")
working.path.in.pathogens<<-paste0(model_path,"Model input/")
working.path.script<<-paste0(model_path,"Model scripts/")
working.path.out<<-paste0(model_path,"Model output/Uganda/")
# SET ISO READ FORMAT -------------------------------------------------------
# Options
#ISO_READ_FORMATS <- list(POLYGON=1,RASTER=2)
EMISSION_MODULES <- list(NYNKE=1,MATT=2)
SCENARIO_MODES <- list(ON=T,OFF=F)
# Set option here
#iso_read_format <- ISO_READ_FORMATS$POLYGON
emissions_module <- EMISSION_MODULES$MATT
scenario_mode <- SCENARIO_MODES$ON
#############AFTER THIS LINE THERE IS NO NEED TO CHANGE ANYTHING IN THIS SCRIPT OR OTHER SCRIPTS#####################
setwd(wd)
source(file.path(working.path.script,"GloWPa configuration.R"))
# Open the overall input files and select the runs ------------------------
# For the online tool, this should not be read in from a .csv file, but be initialised in the code
# so there needs to be a switch selecting which of the two (model in R or tool with Rplumber)
# will have to be run.
# run original GloPWa
if(scenarion_mode){
#read in overall input file
input_file<-read.csv(paste0(working.path.in,"overall_inputs.csv"),stringsAsFactors=FALSE)
} else{
# run GloWPa for mapping tool
input_file <- file.path(working.path.in,"input_data.csv")
}
model.start(overall_inputs,emissions_module,scenario_mode)
# End to open the overall input files and run selection -------------------
\ No newline at end of file
#devtools::install_github('mverbyla/pathogenflows')
library(pathogenflows)
pathogenflow.model.run <- function(input_data,pathogen){
emissions <- data.frame()
# 1) extract pathogen type from pathogen
pathogenType <- "Virus"
# 2a) prepare data for urban and rural
# 2b) call loadings function twice for urban and rural areas
onsite_urban = data.frame()
onsite_rural = data.frame()
rural_loadings <- pathogenflows::getLoadings(onsite_rural,pathogenType)
urban_loadings <- pathogenflows::getLoadings(onsite_urban,pathogenType)
# 2c) postprocess output
# 3) create similair emissions data.frame as original human emissions
# 4) return emissions
return(emissions)
}
\ No newline at end of file
#script is written by Nynke 15-5-2019. It works for the Uganda rasters. No clue if it also works for other areas in the world.
setwd(paste0(working.path.in,"polygons/"))
area <- readOGR(dsn = ".", layer = layer)
a<-extent(area)
#number of rows and cols:
lon1<-round(a[1],digits=1)-(resolution*12)
lon2<-round(a[2],digits=1)+(resolution*12)
lat1<-round(a[3],digits=1)
lat2<-round(a[4],digits=1)+(resolution*12)
rows<-(lat2-lat1)/resolution
cols<-(lon2-lon1)/resolution
rast<-matrix(data=NA,nrow=rows,ncol=cols)
rast<-raster(rast)
extent(rast) <-c(lon1,lon2,lat1,lat2)
projection(rast) <- CRS("+proj=longlat +datum=WGS84")
area_rast<-rasterize(area,rast,"OBJECTID")
areas<-data.frame(area$OBJECTID,area$DNAME2014)
write.csv(areas, file=paste0(working.path.in,"polygons/isoareas.csv"))
writeRaster(area_rast,paste0(working.path.in,"isoraster.asc"),overwrite=TRUE)
rm(c(area,a,lon1,lon2,lat1,lat2,rows,cols,rast,area_rast))
#script is written by Nynke 15-5-2019. It works for the Uganda rasters. No clue if it also works for other areas in the world.
make.iso.grids <- function(layer,resolution){
#Identify the area. Here the grids within the area are assigned to the code of the area. Here a file is read in
#that has either the polygons of areas or is a gridded file. The polygon file should always be transformed to the
#set resolution.
message("Start making iso grids")
setwd(paste0(working.path.in,"polygons/"))
area <- readOGR(dsn = ".", layer = layer)
a<-extent(area)
#number of rows and cols:
lon1<-round(a[1],digits=1)-(resolution*12)
lon2<-round(a[2],digits=1)+(resolution*12)
lat1<-round(a[3],digits=1)
lat2<-round(a[4],digits=1)+(resolution*12)
rows<-(lat2-lat1)/resolution
cols<-(lon2-lon1)/resolution
rast<-matrix(data=NA,nrow=rows,ncol=cols)
rast<-raster(rast)
extent(rast) <-c(lon1,lon2,lat1,lat2)
projection(rast) <- CRS("+proj=longlat +datum=WGS84")
area_rast<-rasterize(area,rast,"OBJECTID")
areas<-data.frame(area$OBJECTID,area$DNAME2014)
write.csv(areas, file=paste0(working.path.in,"polygons/isoareas.csv"))
writeRaster(area_rast,paste0(working.path.in,"isoraster.asc"),overwrite=TRUE)
message("Finished making iso grids")
#rm(c(area,a,lon1,lon2,lat1,lat2,rows,cols,rast,area_rast))
}
"","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.
Please register or to comment