Skip to content

Instantly share code, notes, and snippets.

@ojessen
Created April 13, 2017 23:08
Show Gist options
  • Save ojessen/f52da1f29b17df8a14766f59e3153073 to your computer and use it in GitHub Desktop.
Save ojessen/f52da1f29b17df8a14766f59e3153073 to your computer and use it in GitHub Desktop.
MOAB at home
# Based on the Gist by @hrbrmstr https://gist.github.com/hrbrmstr/b91752d32a07ee8595db33babe735b6b
library(httr)
library(leaflet)
GET("https://ipinfo.io/json") %>% # get IP geolocated coordinates
content() %>%
.$loc %>%
strsplit(",") %>%
.[[1]] %>%
as.numeric() -> lat_lng
# Formula according to https://www.metabunk.org/attachments/blast-effect-calculation-1-pdf.2578/
# Sadorvsky formula for blast wave from TNT explosion on earth surface, overpressure in freedom units (PSI)
tnt_function = function(m_tnt, dist_m){
(0.95*(m_tnt^(1/3))/dist_m + 3.9*((m_tnt^2)^(1/3))/(dist_m^2) + 13.0*((m_tnt))/(dist_m^3))*14.6959
}
overpressure = tnt_function(11000,10:10000)
plot(overpressure[overpressure < 50 & overpressure>0.15], type = "l")
# Destruction levels according to http://response.restoration.noaa.gov/oil-and-chemical-spills/chemical-spills/resources/overpressure-levels-concern.html
lvl_destruction = c(1,3.5,8)
labels_destruct = c("shatters glass", "serious injury likely", "destruction of buildings")
idx_break = c()
for(iter in 1:length(lvl_destruction)){
idx_break = c(idx_break, max(which(overpressure>lvl_destruction[iter])))
}
distances = 10:10000
distances[idx_break]
leaflet() %>%
addTiles() %>%
setView(lat_lng[2], lat_lng[1], zoom=16) %>%
addCircles(lat_lng[2], lat_lng[1], radius=distances[idx_break[1]], opacity=1/10) %>% # shatters glass
addCircles(lat_lng[2], lat_lng[1], radius=distances[idx_break[2]], opacity=1/10) %>% # serious injury likely
addCircles(lat_lng[2], lat_lng[1], radius=distances[idx_break[3]], opacity=1/10) # destruction of buildings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment