过渡循规蹈矩,只会在既有的泥潭中越陷越深。就像写文章一样,如果总是想一气呵成或是一蹴而就如行云流水般写就,那结局必定是寸步难行,特别是对于我这样的新手难说更是如此。因此,我可以尝试老师说的方式,文章的结论部分不要一次写完,每一次写一点。用在这种学习笔记中便是:不能总想着一次就把第一部分完成,然后开始第二部分,可以先把“菜”下锅,等需要放什么的时候再来。


非原创

一、Julia基本操作及快捷键

Ctrl+? ,出现help?>,寻求帮助

],英文模式下输入,进入Pkg模式,我不太了解,尝试两次后的初步感觉是,它可以通过以给定链接的方式下载库并安装。

例如,进入Pkg模式后,添加模块的命令格式应为:

1
pkg>add url

例如:

1
pkg>add https://github.com/anowacki/SeisRequests.jl

当需要从Pkg模式下退出时,直接使用Backspace按键即可。

二、SeisRequests

准备工作

1.安装SAC.jl,可能需要编译SpecialFunctions

1
2
pkg> add https://github.com/anowacki/SAC.jl
julia> build Special Functions

2.安装SACPlot

1
pkg> add https://github.com/anowacki/SACPlot.jl

3.安装Plots

1
julia> import Pkg; Pkg.add("Plots")

使用说明

1.使用FDSN服务标准:

1
2
3
FDSNEvent:查询事件
FDSNStation: 查询台站
FDSNDataSelect: 请求波形数据

2.使用IRIS服务标准:

1
IRISTimeSeries: 请求波形数据

3.REPL

​ 待添加。。。。。。

4.所有请求由get_request函数发出,它会自动返回HTTP.message.Response,包含有服务器返回的信息。

示例

参考:https://github.com/anowacki/SeisRequests.jl

以获取2007年南威尔士地震数据为例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
julia> using SeisRequests  # 启动SeisRequests

julia> req = FDSNStation(station="JSA", network="GB", channel="?H?", level="channel, format="text")
FDSNStation
starttime: Missing missing
endtime: Missing missing
startbefore: Missing missing
startafter: Missing missing
endbefore: Missing missing
endafter: Missing missing
network: String "GB"
station: String "JSY"

matchtimeseries: Missing missing
format: String "text"
nodata: Int64 204

julia> get_request(req)
[ Info: Request status: Successful request, results follow
HTTP.Messages.Response:
"""
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
access-control-allow-origin: *
content-disposition: inline; filename="fdsnws-station_2018-08-23T13:37:35Z.txt"
Content-Type: text/plain
Content-Length: 176
Date: Thu, 23 Aug 2018 13:37:35 GMT
Connection: close

#Network | Station | Latitude | Longitude | Elevation | SiteName | StartTime | EndTime
GB|JSA|49.1878|-2.171698|39.0|ST AUBINS, JERSEY|2007-09-06T00:00:00|2599-12-31T23:59:59
"""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
julia> using Dates, SAC # `using Base.Dates` if still on Julia v1.0

julia> otime = DateTime(2018, 02, 17, 14, 31, 6) # Cymllynfell event, South Wales
2018-02-17T14:31:06

julia> response = get_request(IRISTimeSeries(network="GB", station="JSA", location="--", channel="BHZ", starttime=otime, endtime=otime+Minute(5), output="sacbb"));
[ Info: Request status: Successful request, results follow

julia> trace = SACtr(response.body)
SAC.SACtr:
delta: 0.02
depmin: -9348.0
depmax: 9834.0
b: 0.0
e: 299.97998
depmen: 1.023
nzyear: 2018
nzjday: 48
nzhour: 14
nzmin: 31
nzsec: 6
nzmsec: 5
nvhdr: 6
npts: 15000
iftype: 1
leven: true
lpspol: true
lovrok: true
lcalda: true
unused18: true
kstnm: JSA
kcmpnm: BHZ
knetwk: GB

julia> using SACPlot; plot1(trace)

结果:

trace_Jelsy

三、关于SACPlot

1.plot1画单道

1
2
julia> t=SAC.sample()
julia> plot1(t)

结果:

2.plot1画多道

1
2
3
4
5
6
7
8
9
10
11
12
13
julia> A = [SAC.sample() for i in 1:5]  |> rtrend! |> taper!
5-element Array{SACtr,1}:
SAC.SACtr(delta=0.01, b=9.459999, npts=1000, kstnm=CDV, gcarc=3.357463, az=88.14708, baz=271.8529)
SAC.SACtr(delta=0.01, b=9.459999, npts=1000, kstnm=CDV, gcarc=3.357463, az=88.14708, baz=271.8529)
SAC.SACtr(delta=0.01, b=9.459999, npts=1000, kstnm=CDV, gcarc=3.357463, az=88.14708, baz=271.8529)
SAC.SACtr(delta=0.01, b=9.459999, npts=1000, kstnm=CDV, gcarc=3.357463, az=88.14708, baz=271.8529)
SAC.SACtr(delta=0.01, b=9.459999, npts=1000, kstnm=CDV, gcarc=3.357463, az=88.14708, baz=271.8529)

julia> freqs = [1/3, 1, 3, 6, 10];

julia> A[:user0] = freqs;

julia> lowpass!.(A, freqs);

做低通滤波后:

最后一步成图:

1
julia> pl(A)

  1. plotrs,添加标签

    1
    2
    3
    4
    5
    julia> B = SAC.sample(:array); # Load sample data
    julia> B = cut(B, :a, -30, :a, 30); # Cut traces
    julia> import Pkg; Pkg.add("Plots"); # This allows us to call Plots directly below
    julia> import Plots; Plots.default(size=(600,1000), margin=4Plots.mm) # Change the default figure size and margin
    julia> plotrs(B, :a, qdp=false, label=:kstnm, xlabel="Time rel. PKIKP / s", ylabel="Distance / °")

    plotrs

4.example plotrs

1
julia> plotrs(A, y=:user0, xlabel="Time / s", ylabel="Lowpass frequency / Hz")

example_plotrs

参考:https://github.com/anowacki/SeisRequests.jl

修改历史:

  • 2018-11-06,翻译初稿,后续想继续学习SAC在Julia中的使用,也借此绕开SAC对系统的限制,使用更快的Julia语言重新理解SAC。另外,必须清楚一条,程序语言的本质是解决问题,千万不要掉进去理解程序语言的每一个细节的这种“贪婪者”的陷阱。既然是在地震学中使用,那么只需要能解决问题便是王道。