WORK IN PROGRESS
The download function (fcn_download) itself it not a matter of this exercise.
It merely downloads from the service below the earth quake data from the years. I’ve done that already and so, I got all the data already - it takes quite a while to download it, be aware of that.
rm(list = ls()); cat("\014")
##---------------
## Download
##
## source: http://service.iris.edu/fdsnws/event/docs/1/builder/
## Data available since 1966
##---------------
source("./000_analysis/fcn_download.R")
fcn_download("./010_data/", 2016:2016) # the function first checks if the file 2016.txt already exists, or not. If yes, it won't start the download.
# fcn_download <- function(directory, id_year){
#
# directory <- "./010_data"
#
# start_url <- "http://service.iris.edu/fdsnws/event/1/query?starttime=1966-01-01T00:00:00&endtime=1966-12-31T23:59:59&orderby=time-asc&format=text&nodata=404"
#
# for (i in id_year){
#
# destfile <- paste(directory, "/", i, ".txt", sep = "")
# url_i <- gsub(as.character("1966"), as.character(i), start_url)
#
# if (!file.exists(destfile)) {
# download.file(url_i, destfile, method = "auto")
# }
# }
# }Let’s explore the data from the years 2011 to 2016:
##---------------
## Loading Data
##---------------
files_loc <- list.files("./010_data/", full.names = TRUE)
# specify the year
# loading year data
source("./000_analysis/fcn_loading.R")
years <- 2012:2016
tdat <- fcn_loading("./010_data/", years)
# fcn_loading <- function(directory, id_year){
#
# files_loc <- list.files(directory, full.names = TRUE)
#
# data <- data.frame()
# for (i in id_year){
# data <- rbind(data, read.table(paste(directory, i, ".txt", sep = "") # "/",
# , sep = "|"
# , header = TRUE
# , comment.char = ""
# , quote = ""
# )
# )
# }
# data
# }
dim(tdat)
#> [1] 1151446 13We have over 1.1 million data points here.
require(lubridate)
require(dplyr)
require(RColorBrewer)tdat$Time <- ymd_hms(tdat$Time)
source("http://blog.revolutionanalytics.com/downloads/calendarHeat.R")
# Plot the calendar graph to view the missing data pattern
green_color_ramp = brewer.pal(20, "YlGnBu") #OrRd #YlGnBu #Greens #PuRd
calendarHeat(tdat$Time, tdat$Magnitude,
varname=paste("Magnitude.....", min(years), "-", max(years)), color="green_color_ramp")This heat map gives quite a good overview. However, the size of this map in this report isn’t optimal. To be updated.
We can nicely see the tectonic plates, respectively the earthquake’s distribution is highly correlated to the plate’s boundaries.
plot(tdat$Longitude, tdat$Latitude)WORK IN PROGRESS