# Contrived example
x <- rep(c(1,5,3,2,1),each=20)
p <- roll_stalta(x,3,6)
plot(x, pch=17, cex=0.8, ylim=c(0,max(x)),
main="Test of roll_stalta on artificial data")
points(p,cex=1.5,col='red',type='b')
legend('topleft',
legend=c('data','STA/LTA'),
pch=c(17,1),
col=c('black','red'))
# Real example requiring the 'seismic' package
if (FALSE) {
require(seismic)
# Create a new IrisClient
iris <- new("IrisClient")
# Seismic data with a large quake
starttime <- as.POSIXct("2010-02-27 06:30:00", tz="GMT")
endtime <- as.POSIXct("2010-02-27 07:00:00", tz="GMT")
st <- getDataselect(iris,"IU","ANMO","00","BHZ",starttime,endtime)
tr <- st@traces[[1]]
# Preprocess the data
x <- DDT(tr)@data
# Calculate the first break 'picker'
n_sta <- 3 * tr@stats@sampling_rate
n_lta <- 10 * n_sta
p <- roll_stalta(x^2,n_sta,n_lta)
first_break <- which(p == max(p,na.rm=TRUE))
plot(x,type='l',
main='Test of STA/LTA first break picker on raw seismic data')
abline(v=first_break,col='red')
}
Run the code above in your browser using DataLab