Earthquakes around Japan in the past 7 Days
Data Source:U.S. Geological Survey http://earthquake.usgs.gov/earthquakes/feed/v1.0/csv.php
Sys.time()
[1] “2014-09-30 14:44:48 JST”
Package
library(knitr)
library(maps) # http://cran.r-project.org/web/packages/maps/maps.pdf
library(ggplot2) # http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf
library(googleVis) # http://cran.r-project.org/web/packages/googleVis/googleVis.pdf
library(Imap) # http://cran.r-project.org/web/packages/Imap/Imap.pdf
library(geosphere) # http://cran.r-project.org/web/packages/geosphere/geosphere.pdf
library(xts)
Read Data
data.location<-2 #1:local 2:web
data.file<-"all_week.csv"
if(data.location==1){
username<-Sys.info()['user']
path01<-paste("C:/Users/",username,"/Desktop/Earthquake_Data/",sep="")
setwd(path01)
dataset<-read.table(file=paste(path01,data.file,sep=""),sep=",",header=T,as.is=T,skip=0)
}else{
dataset<-read.csv(paste("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/",data.file,sep=""),header=T,as.is=T,skip=0)
}
dataset.j<-dataset[grep("Japan",dataset[,14]),]
googlevis
dataset.j$latlong<-paste(dataset.j$latitude,dataset.j$longitude,sep=":")
dataset.j$jst<-as.POSIXct(sub("Z","",sub("T"," ",dataset.j$time)))+3600*9 #UTC+9
dataset.j$info<-paste("Time(UTC)=",dataset.j$time," , UTC+9=",dataset.j$jst,", Depth(km)=",dataset.j$depth,", Mag=",dataset.j$mag," , MagType=",dataset.j$magType,", Place=",dataset.j$place,sep="")
gMap<-gvisMap(
dataset.j,"latlong","info",
options=list(
showTip=TRUE,
showLine=TRUE,
enableScrollWheel=TRUE,
mapType='terrain', #'hybrid','normal','terrain','satellite'
useMapTypeControl=TRUE
)
)
maps
for(mmm in 1:length(dataset.j[,1])){
tmp<-dataset.j$mag[mmm]+10^-3
if(round(tmp)==floor(tmp)){tmp<-floor(tmp)}else{tmp<-(round(tmp)-0.5)}
dataset.j$magMap[mmm]<-tmp
}
japan<-map(xlim=c(120,150),ylim=c(20,50))
# http://cran.r-project.org/web/packages/maps/maps.pdf#page=8
str(japan)
## List of 4
## $ x : num [1:635] 119 119 119 121 121 ...
## $ y : num [1:635] 50 50.3 50.4 52.2 52.5 ...
## $ range: num [1:4] 120 150 20 50
## $ names: chr [1:75] "USSR" "China" "North Korea" "South Korea" ...
## - attr(*, "class")= chr "map"
japan<-as.data.frame(japan[c("x","y")])
japan.map<-ggplot(japan,aes(x,y))
japan.map<-japan.map+geom_path()
# http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf#page=79
japan.map<-japan.map+geom_point(
data=dataset.j,
aes(
x=longitude,
y=latitude,
size=magMap
)
)
japan.map<-japan.map+scale_size_continuous(paste("Magnitude(M)","\n","M~(M+0.5)"))
Map
- maps
plot(japan.map)
- google map
print(gMap,tag="chart")
Latest Earthquake
print(dataset.j[,18][1])
## [1] "Time(UTC)=2014-09-29T14:55:57.850Z , UTC+9=2014-09-29 23:55:57, Depth(km)=40.84, Mag=4.8 , MagType=mb, Place=Izu Islands, Japan region"
Maximum Magnitude Earthquake in the past 7 days
row.id<-which(max(dataset.j[,5])==dataset.j[,5])
print(dataset.j[,18][row.id])
## [1] "Time(UTC)=2014-09-24T13:30:57.380Z , UTC+9=2014-09-24 22:30:57, Depth(km)=56.05, Mag=5.1 , MagType=mww, Place=30km ENE of Namie, Japan"
Eepicentral distance and hypocentral distance from max magnitude earthquake point
lon.2<-dataset.j[,3][row.id]
lat.2<-dataset.j[,2][row.id]
d<-dataset.j[,4][row.id]
####
lon.1<-139.744858 # e.g. national diet in Japan
lat.1<-35.675888
r.a<-6378.137 #radius km
r.b<-6356.7523142 #radius km
#epicentral distance
epi.dis<-gdist(lon.1,lat.1,lon.2,lat.2,units="km",a=r.a*1000,b=r.b*1000,verbose=FALSE)
# http://cran.r-project.org/web/packages/Imap/Imap.pdf#page=2
#geocentric latitude
eccentricity<-(r.a^2-r.b^2)^0.5/r.a
e2<-eccentricity^2
lat.1.gl<-atan((1-e2)*tan(lat.1*pi/180))
lat.2.gl<-atan((1-e2)*tan(lat.2*pi/180))
#hypocentral distance
phi.x<-lat.1.gl
phi.e<-lat.2.gl
lambda.x<-lon.1*pi/180
lambda.e<-lon.2*pi/180
AE<-cos(phi.e)*cos(lambda.e)*(r.a-d)/r.a
BE<-cos(phi.e)*sin(lambda.e)*(r.a-d)/r.a
CE<-sin(phi.e)*(r.a-d)/r.a
AX<-cos(phi.x)*cos(lambda.x)
BX<-cos(phi.x)*sin(lambda.x)
CX<-sin(phi.x)
delta.s<-((AE-AX)^2+(BE-BX)^2+(CE-CX)^2)^0.5
hyp.dis<-delta.s*r.a
cat("Epicentral distance(km)=",epi.dis)
## Epicentral distance(km)= 253
cat("Hypocentral Distance(km)",hyp.dis)
## Hypocentral Distance(km) 258.3
cat("Geocentric latitude(degree):point1=",lat.1.gl*180/pi,", point2=",point2=lat.2.gl*180/pi)
## Geocentric latitude(degree):point1= 35.49 , point2= 37.38
cat("Eccentricity=",eccentricity)
## Eccentricity= 0.08182
Data
kable(dataset.j[,c(17,5,6,14,2,3,4)])
##
##
## | |jst | mag|magType |place | latitude| longitude| depth|
## |:----|:-------------------|---:|:-------|:-------------------------------|--------:|---------:|-----:|
## |108 |2014-09-29 23:55:57 | 4.8|mb |Izu Islands, Japan region | 29.33| 140.4| 40.84|
## |234 |2014-09-29 10:05:40 | 4.9|mb |118km S of Kushiro, Japan | 41.91| 144.3| 38.07|
## |2043 |2014-09-24 22:30:57 | 5.1|mww |30km ENE of Namie, Japan | 37.56| 141.3| 56.05|
## |2047 |2014-09-24 21:45:46 | 5.0|mb |41km E of Namie, Japan | 37.55| 141.5| 44.72|
## |2329 |2014-09-23 23:54:16 | 4.1|mb |46km SE of Ofunato, Japan | 38.83| 142.2| 53.14|
## |2366 |2014-09-23 20:04:29 | 4.8|mb |261km SE of Hachijo-jima, Japan | 31.43| 141.8| 10.00|
Reference
See below link
- http://equations.am-consulting.co.jp/?p=1577