FK & CAP Installation Guide
These instructions are adapted from:
https://seiswave.cn/oh-my-cap/install/
https://cuseistut.readthedocs.io/en/latest/gcap/index.html#/
The test systems are macOS 15.6.1 and Ubuntu 18.04.6
If you have any questions, please contact qilidai@cuhk.edu.hk
1. Package required
Compilers & build tools: gcc, gfortran, make
Seismic tools: rdseed, SAC, TauP, FK, gCAP
Plotting: GMT6
2. Installation
2.1 Compile tools
2.1.1 MacOS
Install Homebrew
1$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2$ brew install gcc gfortran make
2.1.2 Linux
1$ sudo apt-get install gcc gfortran
2.2 rdseed
rdseed rdseedv5.3.1.tar.gz is used to convert SEED files to SAC format
Reference: https://blog.seisman.info/rdseed-install/
1$ tar -xvf rdseedv5.3.1.tar.gz
2$ mkdir ~/opt
3$ mv rdseedv5.3.1 ~/opt
4$ cd ~/opt/rdseedv5.3.1
5
6#For MacOS, run following lines
7$ ./rdseed.mac.x86_64
8$ xattr -d com.apple.quarantine rdseed.mac.x86_64
9$ mv rdseed.mac.x86_64 rdseed
10$ echo 'export PATH=${HOME}/opt/rdseedv5.3.1:${PATH}'>> ~/.zshrc
11
12#For Linux, run following lines
13$ ./rdseed.rh6.linux_64
14$ mv rdseed.rh6.linux_64 rdseed
15$ echo 'export PATH=${HOME}/opt/rdseedv5.3.1:${PATH}'>> ~/.bashrc
2.3 SAC
SAC is used to process sac file
Reference:
https://seisman.github.io/SAC_Docs_zh/install/
You need to download the package by yourself using following link:
http://ds.iris.edu/ds/nodes/dmc/forms/sac/
2.3.1 MacOS
1$ xcode-select --install
2$ brew install --cask xquartz
3$ tar -xvf sac-102.0-mac.tar.gz
4$ sudo mv sac /usr/local
5#Add environment variables:
6$ echo 'export SACHOME=/usr/local/sac' >> ~/.zshrc
7$ echo 'export SACAUX=${SACHOME}/aux' >> ~/.zshrc
8$ echo 'export PATH=${SACHOME}/bin:${PATH}' >> ~/.zshrc
9$ echo 'export SAC_DISPLAY_COPYRIGHT=1' >> ~/.zshrc
10$ echo 'export SAC_PPK_LARGE_CROSSHAIRS=1' >> ~/.zshrc
11$ echo 'export SAC_USE_DATABASE=0' >> ~/.zshrc
12$ source ~/.zshrc
13$ sac
2.3.2 Linux
1$ sudo apt update
2$ sudo apt install libc6 libsm6 libice6 libxpm4 libx11-6
3$ sudo apt install zlib1g libncurses6
4$ tar -xvf sac-102.0-linux_x86_64.tar.gz
5$ sudo mv sac /usr/local
6#Add environment variables:
7$ echo 'export SACHOME=/usr/local/sac' >> ~/.bashrc
8$ echo 'export SACAUX=${SACHOME}/aux' >> ~/.bashrc
9$ echo 'export PATH=${SACHOME}/bin:${PATH}' >> ~/.bashrc
10$ echo 'export SAC_DISPLAY_COPYRIGHT=1' >> ~/.bashrc
11$ echo 'export SAC_PPK_LARGE_CROSSHAIRS=1' >> ~/.bashrc
12$ echo 'export SAC_USE_DATABASE=0' >> ~/.bashrc
13$ source ~/.bashrc
14$ sac
2.4 GMT6
GMT is used for high-quality plotting
Reference: https://docs.gmt-china.org/latest/install/
2.4.1 MacOS
1$ brew update && brew upgrade
2$ brew install gmt
3$ brew install ghostscript
4$ brew install graphicsmagick
5$ brew install ffmpeg
6$ gmt --version
2.4.2 Linux
1$ sudo apt update
2$ sudo apt install gmt gmt-dcw gmt-gshhg
3$ sudo apt install xdg-utils
4$ sudo apt install gdal-bin
5$ sudo apt install ghostscript
6$ sudo apt install graphicsmagick
7$ sudo apt install ffmpeg
8$ gmt --version
If the version is not GMT6, see: https://docs.gmt-china.org/latest/install/conda/
2.5 TauP
TauP TauP-2.6.1.tgz is used to calculate theoretical ray paths and arrival times
Reference: https://seismo-learn.org/software/taup/install/
For MacOS, run following lines to install JAVA
1$ brew install openjdk
2$ sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
For Linux, run following lines to install JAVA
1$ sudo apt install default-jdk
2$ java -version
1$ wget http://www.seis.sc.edu/downloads/TauP/TauP-2.6.1.tgz
2$ tar -xvf TauP-2.6.1.tgz
3$ mkdir -p ~/opt/
4$ mv TauP-2.6.1 ~/opt/
For MacOS, run following lines
1$ echo 'export PATH=${HOME}/opt/TauP-2.6.1/bin:${PATH}' >> ~/.zshrc
2$ source ~/.zshrc
3$ taup
For Linux, run following lines
1$ echo 'export PATH=${HOME}/opt/TauP-2.6.1/bin:${PATH}' >> ~/.bashrc
2$ source ~/.bashrc
3$ taup
2.6 FK
FK computes synthetic Green’s functions for layered velocity models written by Prof. Lupei ZHU
Source:
http://www.eas.slu.edu/People/LZhu/downloads/fk3.3.tar/
https://seismo-learn.org/software/fk/install/
We recommend using oh-my-cap (simpler on macOS):
https://seiswave.cn/oh-my-cap/install/
1$ wget https://github.com/wangliang1989/oh-my-cap/archive/v2.0.0.tar.gz
2$ tar -zxvf v2.0.0.tar.gz
3$ mv oh-my-cap-2.0.0 ~/opt/
4$ cd ~/opt/oh-my-cap/src/fk
5$ make
For MacOS, run following lines
1$ echo 'export PATH=${HOME}/opt/oh-my-cap-2.0.0/src/fk:${PATH}' >> ~/.zshrc
2$ source ~/.zshrc
3$ fk.pl
For Linux, run following lines
1$ echo 'export PATH=${HOME}/opt/oh-my-cap-2.0.0/src/fk:${PATH}' >> ~/.bashrc
2$ source ~/.bashrc
3$ fk.pl
2.7 CAP
CAP is a focal-mechanism inversion method developed by Prof. Lupei ZHU.
Source:
http://www.eas.slu.edu/People/LZhu/downloads/gcap1.0.tar/
https://blog.seisman.info/gcap-install/
We recommend using oh-my-cap (simpler on macOS):
https://seiswave.cn/oh-my-cap/install/
1$ cd ~/opt/oh-my-cap/src/gcap
2$ make
For MacOS, run following lines
1$ echo 'export OH_MY_CAP=${HOME}/opt/oh-my-cap-2.0.0' >> ~/.zshrc
2$ echo 'export PATH=${HOME}/opt/oh-my-cap-2.0.0/src/gcap:${PATH}' >> ~/.zshrc
3$ source ~/.zshrc
4$ cap.pl
For Linux, run following lines
1$ echo 'export OH_MY_CAP=${HOME}/opt/oh-my-cap-2.0.0' >> ~/.bashrc
2$ echo 'export PATH=${HOME}/opt/oh-my-cap-2.0.0/src/gcap:${PATH}' >> ~/.bashrc
3$ source ~/.bashrc
4$ cap.pl
3. Run an example
3.1 Calculate Green’s function (FK)
1$ cd ~/opt/oh-my-cap Glib
2$ perl run_fk.pl model.fk
3.2 Data pre-processing
1$ cd ../example/
2$ perl process.pl 20080418093658
3.3 Inversion (CAP)
1$ perl weight.pl 20080418093658
2$ perl inversion.pl 20080418093658
3$ perl gmt6depth.pl 20080418093658
4$ perl depth.pl 20080418093658
4. Optional: Install pyfk
Reference: https://github.com/ziyixi/pyfk/blob/master/docs/introduction/install.rst/
1$ conda create -n fk python=3.9 -y
2$ conda activate fk
3$ conda install -c conda-forge -y numpy=1.26 "cython<3" setuptools wheel scipy make notebook
For MacOS, run following lines
1$ pip install cysignals pyfk --no-build-isolation
2$ jupyter notebook
For Linux, run following lines
1$ pip install cysignals pyfk
2$ jupyter notebook
Open and run pyfk.ipynb ./pyfk.ipynb
This notebook was written by Khalil and revised by Qili
5. Exercises
The displacement in a uniform whole-space produced by a single force \(F_p\) at the origin is
where \(\gamma_i=\dfrac{x_i}{r}\) is the \(i\)-th component of the unit vector \(\hat{\mathbf r}\). This is one of the most important solutions in seismology and was first given by Stokes in 1849. The first term on the RHS is called the near field because it decays rapidly with distance. The other two terms are called the far-field \(P\) and \(S\) wavefields, respectively. When the source time function is an impulse, the far-field \(P\) and \(S\) waveforms are impulsive, but the near-field waveform is a ramp starting at the \(P\) arrival time and ending at the \(S\) arrival time.
A sample Matlab program for computing displacement generated by a single force in a whole space is given below:
1clear all;close all
2% model parameters of the whole-space
3vp = 6.3;
4vs = 3.6;
5% sampling rate
6dt = 0.01;
7% force vector
8F = [0; 0; 1];
9% receiver location
10r = [3; 0; 10];
11% compute the amplitudes of the nearfield and far-fields
12dist = norm(r);
13gamma = r/dist;
14gammaDotF = gamma'*F;
15AnearField = (3*gammaDotF*gamma-F)/(dist*dist*dist);
16AfarP = gamma*(gammaDotF/(vp*vp*dist));
17AfarS = (F-gammaDotF*gamma)/(vs*vs*dist);
18% construct the time functions of the nearfield and far-fields
19tp = dist/vp;
20itp = round(tp/dt);
21ts = dist/vs;
22its = round(ts/dt);
23nt = its + 100;
24t = (0:nt-1)*dt;
25nearField = zeros(3,nt);
26farP = zeros(3,nt);
27farS = zeros(3,nt);
28nearField(:,itp:its) = AnearField*t(itp:its);
29farP(:,itp) = AfarP/dt;
30farS(:,its) = AfarS/dt;
31disp = nearField + farP + farS;
32subplot(4,1,1),plot(t,nearField(3,:))
33subplot(4,1,2),plot(t,farP(3,:))
34subplot(4,1,3),plot(t,farS(3,:))
35subplot(4,1,4),plot(t,disp(3,:))
1. Following the above equation and the provided MATLAB code, write a Python function to calculate the displacement \(\mathbf{u}(\mathbf{r},t)\) produced by a single force \(\mathbf{F}\) in a homogeneous whole-space with velocities \(V_p\), \(V_s\), and density \(\rho\), assuming that the source time history is a step function.
2. Use the FK package to compute synthetic seismograms for the same single-force source using identical model parameters. Plot the resulting waveforms and compare them with those obtained from the analytical solution.
3. Select a study region of your interest. Download a representative 1-D velocity model for that region (e.g., CRUST1.0 or another published regional model). Then visit https://www.globalcmt.org/ to identify one or more earthquake events located within the selected region.
Extract the source parameters (location, focal mechanism, and centroid depth) from the Global CMT catalog.
Using a double-couple source representation, compute synthetic seismograms with the FK package for the catalog depth.
Repeat the calculations for several hypothetical source depths (e.g., ±10–20 km relative to the catalog depth) while keeping the focal mechanism unchanged.
Compare the resulting waveforms and discuss how source depth influences P-, S-, and surface-wave amplitudes and arrival characteristics in the selected region.