District Pages

library(ramp.uganda)
my_box_path = "/Users/smitdave/Library/CloudStorage/Box-Box/RAMP/"

For each district, V1.0 has two nested pages that take deep dives:

These webpages include provisions for adding district-specific background, analysis, or detail. The webpages use include to read in district-specific pages.

For example, the neighbors for each page are created separately and output to a file in the district directory called _neighbors.qmd. This is read into the landing page with the command:

Touch Notes

for(i in 1:146){
  ddir = district_dir$dir[i]
  cmd = paste("touch ../", ddir,"/_notes_", ddir, ".qmd", sep="")
  system(cmd)
  cmd = paste("touch ../", ddir,"/_facility_data_notes_", ddir, ".qmd", sep="")
  system(cmd)
} 

cmd

Update District Maps

update_district_pfpr_map = function(i, debug=FALSE){
  dname = district_dir$district_name[i]
  source_file = paste(district_maps_path, dname, "/yearly_avg_", dname, "_2025_pfpr.png", sep="") 
  if(debug==TRUE) print(source_file)
  ddir = district_dir$dir[i]
  local_file = paste("../", ddir, "/", ddir, "_map.png", sep="") 
  if(debug==TRUE) print(local_file)
  file.copy(source_file, local_file, overwrite=TRUE)
  
  source_file = paste(district_maps_path, dname, "/population_by_pixel_", dname, "_.png", sep="") 
  if(debug==TRUE) print(source_file)
  ddir = district_dir$dir[i]
  local_file = paste("../", ddir, "/", ddir, "_pop_density.png", sep="") 
  if(debug==TRUE) print(local_file)
  file.copy(source_file, local_file, overwrite=TRUE)
  
  source_file = paste(district_maps_path, dname, "/access_to_care_", dname, "_.png", sep="") 
  if(debug==TRUE) print(source_file)
  ddir = district_dir$dir[i]
  local_file = paste("../", ddir, "/", ddir, "_access_to_care.png", sep="") 
  if(debug==TRUE) print(local_file)
  file.copy(source_file, local_file, overwrite=TRUE)
  
  return(invisible())
}

Set the location of the pixelated regional maps

district_maps_path = paste(my_box_path, "data/pfpr_estimates/monthly/pixelated_maps/", sep="")
for(i in 1:146) update_district_pfpr_map(i)

Neighbors

The function make_neighbors creates the file _neighbors.qmd that is included in the district landing page by the line:

This is used to put the

clock_order = function(i, ix){
  with(district_dir,{
    xx = x[ix] - x[i]
    yy = y[ix] - y[i]
    rev(order(atan2(xx,-yy)))
})}
make_neighbors = function(i, debug=FALSE){
  
  dname = district_dir$district_name[i]
  reg_name = district_dir$in_region[i]
  ix = which(region_dir$region_name == reg_name)
  rdir = region_dir$region_dir[ix]
  dname_snake = district_dir$dir[i]
  
  qmd_file = paste("../", dname_snake, "/_neighbors.qmd", sep="")

  short2 = row.names(district_adjacency) 
  
  nbrs = list() 
  adj_ix = which(short2 == dname)
  
  
  n_ix = which(district_adjacency[adj_ix,]==TRUE)
  N = length(n_ix)
  nnix = rep(0, N) 
  if(debug == TRUE) print(short2[n_ix]) 
  for(j in 1:N){
    if(debug == TRUE) print(c(j=j, nnix=nnix[j])) 
    nnix[j] = which(district_dir$district_name == short2[n_ix[j]])  
  }  
  
  cot = nnix[clock_order(i, nnix)]
  
  
  cat(paste(dname, ", in [", reg_name, " Region](../", rdir, "/", rdir, ".qmd), shares a border with ", N, " districts. In clockwise order, these are: ", sep=""), file=qmd_file, append=FALSE)
  
  for(j in 1:(N-1))
     cat(paste("[", district_dir$district_name[cot[j]], "](../", district_dir$dir[cot[j]], "/", district_dir$dir[cot[j]], ".qmd),  ", sep=""), file=qmd_file, append=TRUE)
  
  cat(paste("& [", district_dir$district_name[cot[N]], "](../", district_dir$dir[cot[N]], "/", district_dir$dir[cot[N]], ".qmd).", sep=""),file=qmd_file, append=TRUE)

  if(debug == TRUE) browser() 
  
  return(invisible())
}
for(i in 1:146) make_neighbors(i)

District Pages

ix = 1:146
make_district = function(i){
   dname = district_dir$district_name[i]
   ddir = district_dir$dir[i]
   rname = district_dir$in_region[i]
   
   qmd_file = paste("../", ddir, "/", ddir, ".qmd", sep="")
   
   cat("---\n", file=qmd_file) 
   cat(paste("title: ", dname, "\n"), file=qmd_file, append=TRUE) 
   cat("format: html\n", file=qmd_file, append=TRUE)
   cat("editor:\n", file=qmd_file, append=TRUE) 
   cat("  mode: source\n", file=qmd_file, append=TRUE) 
   cat("---\n", file=qmd_file, append=TRUE)
   
   cat("\n\n{{< include _neighbors.qmd >}}\n\n", file=qmd_file, append=TRUE)
   
   cat("| | |\n", file=qmd_file, append=TRUE)
   cat("| --- | --- |\n", file=qmd_file, append=TRUE)
   cat(paste("| ![](", ddir, "_icon.png) | ![](", ddir, "_pop_density.png) |\n\n", sep=""), file=qmd_file, append=TRUE)
   cat(": {tbl-colwidths=\"[50,50]\"}\n\n", file=qmd_file, append=TRUE)
  
   
   cat(paste("\n\n"), file=qmd_file, append=TRUE)
   
   cat(paste("![Average *Pf*PR for 2025 at ~1 km.](", ddir, "_map.png)\n\n", sep=""), file=qmd_file, append=TRUE)
   
   movie_link = paste("Click to watch an animation of PfPR at pixel level (in a new tab) by [Year](", ddir, "_yearly_movie.mp4){target=\"_blank\"} or by [Month](", ddir, "_monthly_movie.mp4){target=\"_blank\"}).\n\n", sep="") 
   
   cat(movie_link, file=qmd_file, append=TRUE)
   
   cat(paste("\n\n---\n\n"), file=qmd_file, append=TRUE)
   
   cat(paste("\n\nTo learn more about ", dname, " facility data [Click Here](facility_data.qmd)\n\n", sep=""), file=qmd_file, append=TRUE)
   
   cat(paste("![](", ddir, "_incidence_bands.png){width=85%}\n", sep=""), file=qmd_file, append=TRUE)
   cat(paste("---\n\n"), file=qmd_file, append=TRUE)
   
   
   
   
   cat(paste("![](", ddir, "_access_to_care.png)\n\n", sep=""), file=qmd_file, append=TRUE)
    
   cat("{{", file=qmd_file, append=TRUE)
   cat(paste("< include _notes_", ddir, ".qmd >}}\n", sep=""), file=qmd_file, append=TRUE)
  
   return(invisible())
}
for(i in ix) make_district(i) 
i=133
make_district(133)
for(i in c(1:146)) make_district(i) 

Facility Data

Figures

Set the location of the facility data images

update_facility_data_figures = function(i, debug=FALSE){
  dname = district_dir$district_name[i]
  ddir = district_dir$dir[i]
  source_file = paste(facility_data_path, dname, "_incidence_timeseries.png", sep="") 
  local_file = paste("../", ddir, "/", ddir, "_incidence.png", sep="") 
  file.copy(source_file, local_file, overwrite=TRUE)
  source_file = paste(facility_data_path, dname, "_diagnostic_time_series.png", sep="") 
  local_file = paste("../", ddir, "/", ddir, "_reporting.png", sep="") 
  file.copy(source_file, local_file, overwrite=TRUE)
  source_file = paste(facility_data_path, dname, "_incidence_with_bands_timeseries.png", sep="") 
  local_file = paste("../", ddir, "/", ddir, "_incidence_bands.png", sep="") 
  file.copy(source_file, local_file, overwrite=TRUE)
  source_file = paste(facility_data_path, dname, "_tpr_timeseries.png", sep="") 
  local_file = paste("../", ddir, "/", ddir, "_tpr.png", sep="") 
  file.copy(source_file, local_file, overwrite=TRUE)
  source_file = paste(facility_data_path, dname, "_pfpr_timeseries.png", sep="") 
  local_file = paste("../", ddir, "/", ddir, "_pfpr.png", sep="") 
  file.copy(source_file, local_file, overwrite=TRUE)
  return(invisible())
}

Run this:

for(i in 1:146)  update_facility_data_figures(i) 

Facility Data Pages

make_facility_data = function(i){
  dname = district_dir$district_name[i]
  reg_name = district_dir$in_region[i]
  dname_snake = district_dir$dir[i]
  
  qmd_file = paste("../", dname_snake, "/facility_data.qmd", sep="")

  # ------------
  # the header  
  # ------------
  cat("---\n", file=qmd_file) 
  cat("title: Facility Data\n", file=qmd_file, append=TRUE) 
  cat(paste("subtitle:", dname, "Facility Data\n"), file=qmd_file, append=TRUE) 
  cat("format: html\n", file=qmd_file, append=TRUE) 
  cat("editor:\n", file=qmd_file, append=TRUE) 
  cat("  mode: source\n", file=qmd_file, append=TRUE) 
  cat("---\n",file=qmd_file, append=TRUE) 
  
  # Link Back
  cat(paste("\n\nBack to [", dname, "](./", dname_snake, ".qmd)\n\n", sep=""), file=qmd_file, append=TRUE)

  cat(paste("![](./", dname_snake, "_incidence_bands.png){width=85%}\n\n", sep=""), file=qmd_file, append=TRUE)
  cat(paste("![](./", dname_snake, "_incidence.png){width=85%}\n\n", sep=""), file=qmd_file, append=TRUE)
  cat(paste("![](./", dname_snake, "_reporting.png){width=85%}\n\n", sep=""), file=qmd_file, append=TRUE)
  cat(paste("![](./", dname_snake, "_tpr.png){width=85%}\n\n", sep=""), file=qmd_file, append=TRUE)
  cat(paste("![](./", dname_snake, "_pfpr.png){width=85%}\n\n", sep=""), file=qmd_file, append=TRUE)
  
 cat("\n\n{{", file=qmd_file, append=TRUE)
  
 cat(paste("< include _facility_data_notes_", dname_snake, ".qmd >}}", sep=""), file=qmd_file, append=TRUE)
  

}
for(i in c(1:146)) make_facility_data(i) 

Vector Control

make_vector_control = function(i){
  dname = district_dir$district_name[i]
  reg_name = district_dir$in_region[i]
  dname_snake = district_dir$dir[i]
  
  qmd_file = paste("../", dname_snake, "/vector_control.qmd", sep="")

  # ------------
  # the header  
  # ------------
  cat("---\n", file=qmd_file) 
  cat("title: Vector Control\n", file=qmd_file, append=TRUE) 
  cat(paste("subtitle: Evaluating Vector Control in ", dname, "\n"), file=qmd_file, append=TRUE) 
  cat("format: html\n", file=qmd_file, append=TRUE) 
  cat("editor:\n", file=qmd_file, append=TRUE) 
  cat("  mode: source\n", file=qmd_file, append=TRUE) 
  cat("---\n", file=qmd_file, append=TRUE) 
  
  # Link Back
  cat(paste("\n\nBack to [", dname, "](./", dname_snake, ".qmd)\n\n", sep=""), file=qmd_file, append=TRUE)
}
i=3
make_vector_control(3)
for(i in c(1:146)) make_vector_control(i) 

Movies

Movie Pages

make_district_movies = function(i){
  dname = district_dir$district_name[i]
  reg_name = district_dir$in_region[i]
  dname_snake = district_dir$dir[i]
  
  qmd_file = paste("../", dname_snake, "/movies.qmd", sep="")

  # ------------
  # the header  
  # ------------
  cat("---\n", file=qmd_file) 
  cat("title: Movies\n", file=qmd_file, append=TRUE) 
  cat(paste("subtitle: ", dname, " Movies\n"), file=qmd_file, append=TRUE) 
  cat("format: html\n", file=qmd_file, append=TRUE) 
  cat("editor:\n", file=qmd_file, append=TRUE) 
  cat("  mode: source\n", file=qmd_file, append=TRUE) 
  cat("---\n", file=qmd_file, append=TRUE) 
  
  # Link Back
  cat(paste("\n\nBack to [", dname, "](./", dname_snake, ".qmd)\n\n", sep=""), file=qmd_file, append=TRUE)
  
  cat(paste("\n\nWatch [", dname, " by Month](./", dname_snake, "_monthly_movie.mp4)\n\n", sep=""), file=qmd_file, append=TRUE)
  
  cat(paste("\n\nWatch [", dname, " by Year](./", dname_snake, "_yearly_movie.mp4)\n\n", sep=""), file=qmd_file, append=TRUE)
}
for(i in c(1:146)) make_district_movies(i) 

Update Movies

update_district_movies = function(i, debug=FALSE){
  dname = district_dir$alt_name[i]
  ddir = district_dir$dir[i]
  if(debug==TRUE) print(ddir)
  source_file = paste(district_maps_path, dname, "_monthly.mp4", sep="") 
  if(debug==TRUE) print(source_file)
  local_file = paste("../", ddir, "/", ddir, "_monthly_movie.mp4", sep="") 
  if(debug==TRUE) print(local_file)
  file.copy(source_file, local_file, overwrite=TRUE)
  
  source_file = paste(district_maps_path, dname, "_yearly.mp4", sep="") 
  if(debug==TRUE) print(source_file)
  local_file = paste("../", ddir, "/", ddir, "_yearly_movie.mp4", sep="") 
  if(debug==TRUE) print(local_file)
  file.copy(source_file, local_file, overwrite=TRUE)
  
  return(invisible())
}

To update all the movies, set the path to the movies:

district_maps_path = paste(my_box_path, "data/pfpr_estimates/monthly/pixelated_maps/", sep="")

Then run update_district_movies

for(i in 1:146) update_district_movies(i)