library(RSEIS)
data(GH, package='RSEIS')
g1 = GH$pickfile
data(VELMOD1D, package='RSEIS')
vel= VELMOD1D
w1 = which(!is.na(g1$STAS$lat))
sec = g1$STAS$sec[w1]
N = length(sec)
Ldat = list(
name = g1$STAS$name[w1],
sec = g1$STAS$sec[w1],
phase = g1$STAS$phase[w1],
lat=g1$STAS$lat[w1],
lon = g1$STAS$lon[w1],
z = g1$STAS$z[w1],
err= g1$STAS$err[w1],
yr = rep(g1$LOC$yr , times=N),
jd = rep(g1$LOC$jd, times=N),
mo = rep(g1$LOC$mo, times=N),
dom = rep(g1$LOC$dom, times=N),
hr =rep( g1$LOC$hr, times=N),
mi = rep(g1$LOC$mi, times=N) )
MLAT = median(Ldat$lat)
MLON = median(Ldat$lon)
proj = GEOmap::setPROJ(type=2, LAT0=MLAT, LON0=MLON)
#### get station X-Y values in km
XY = GEOmap::GLOB.XY(Ldat$lat, Ldat$lon, proj)
### add to Ldat list
Ldat$x = XY$x
Ldat$y = XY$y
wstart = which.min(Ldat$sec)
EQ = list(x=XY$x[wstart], y=XY$y[wstart], z=6, t=Ldat$sec[wstart] )
maxITER = 7
###print(EQ)
AQ = XYlocate(Ldat,EQ,vel,
maxITER = maxITER,
distwt = 1,
lambdareg =10 ,
FIXZ = FALSE,
REG = TRUE,
WTS = TRUE,
STOPPING = TRUE,
RESMAX = c(0.1,0.1),
tolx = 0.001,
toly = 0.001 ,
tolz = 0.5, PLOT=FALSE)
######## update the new location
AXY = GEOmap::XY.GLOB(AQ$EQ$x, AQ$EQ$y, proj)
AQ$EQ$lat = AXY$lat
AQ$EQ$lon = AXY$lon
if(AQ$EQ$lon>180) { AQ$EQ$lon = AQ$EQ$lon-360 }
plot(c(Ldat$x, AQ$EQ$x) , c(Ldat$y,AQ$EQ$y), type='n' , xlab="km",
ylab="km" )
points(Ldat$x, Ldat$y, pch=6)
points(AQ$EQ$x, AQ$EQ$y, pch=8, col='red')
points(EQ$x, EQ$y, pch=4, col='blue')
legend("topright", pch=c(8,4, 6), col=c("red", "blue", "black"),
legend=c("Final location", "Initial guess", "Station"))
print(AQ)
##### try a different case with an extremely wrong start
EQ$x = 10
EQ$y = 2
Run the code above in your browser using DataLab