worldbank / DECAT_Space2Stats

https://worldbank.github.io/DECAT_Space2Stats/
Other
1 stars 1 forks source link

Port demo notebook to R #31

Closed zacharyDez closed 1 week ago

zacharyDez commented 3 weeks ago

What I Changed

How to Test it

Other Notes

wildintellect commented 3 weeks ago

@zacharyDez I couldn't verify that the notebook worked all the way, my computer hung on the do.call that combines all the dataframes together.

So I jumped down a rabbit whole of doing it a different way, which I think is much faster, though not as pretty to read. Note: I also tried using httr2 instead which I think is a little more user friendly for building API requests.

library(httr2)
# Request the summary data
req <- request(base_url) |>
  req_url_path("/summary") |>
  req_body_json(request_payload)

resp <- req |> req_perform()
resp
#Turn response into a geodataframe (aka sf object)
df <- resp |> resp_body_string() |> fromJSON(flatten = TRUE)

df$x <- sapply(df$geometry.coordinates, function(x){unlist(x)[1]} )
df$y <- sapply(df$geometry.coordinates, function(x){unlist(x)[2]} )
# convert to sf, drop extra geometry fields
gdf <- st_as_sf(df, coords = c("x", "y"), crs = 4326)[,c(1,2,5)]

Only other note, is that the bins on the plot are very uniform, and I'm wondering if the linear scaled applied it the best given the data. Is this Population or Population Change? the lowest value for population is 0, and that should probably be a very different color than 1-200,000

zacharyDez commented 3 weeks ago

@wildintellect, thanks for your detailed and precise feedback. It makes a huge difference in the geodata frame creation, and your pointer on the bins makes the map more adapted to the population variable.

zacharyDez commented 3 weeks ago

@bpstewar @andresfchamorro, could you provide some feedback on the R notebook, or would someone else at the Bank be better positioned? This is more on the user-facing side. Alex has already provided feedback on industry best practices, but it would be useful to hear from you.

zacharyDez commented 2 weeks ago

@andresfchamorro, please keep me updated on feedback from Chevron and Brian. I'd love to merge this soon! It brings a nicer classification for the Python notebook also.

andresfchamorro commented 1 week ago

@zacharyDez this works great. good to see the performance improvement and the syntax makes sense to me