In this exercise we follow the processing in the reference by David M. Boore: Effect of baseline corrections on displacements and response spectra for several recordings of the 1999 Chi-Chi, Taiwan, earthquake. The recording comes from the M 7.6 Chi-Chi, Taiwan earthquake of 9 September 1999, recorded by the CWB network operated by Taiwan's Central Weather Bureau. We process station TCU129 of the WBU network, which is close to the fault.
Accelerograms are very useful, for example to extract coseismic ground displacement by integrating the acceleration twice (Boore, 1999; Wu and Wu, 2007). However, hysteresis, tilting and instrument rocking cause a drift that makes the result unrealistic (Chao et al., 2010).
For the Chi-Chi earthquake, an offset of 8 m was observed, and GPS showed 340 cm of horizontal and 180 cm of vertical motion (Boore, 1999; RCEP DPRI Kyoto; Academia Sinica). The displacement from integrating the acceleration at TCU129 gives an unrealistic 15 m, which is attributed to baseline effects that need to be corrected or analysed.
In this notebook we run five analyses following Boore (1999) to compare the effect of different corrections on the displacement:
- Correction with the pre-event baseline
- Correction by fitting the event
- Correction with an acausal filter
- Correction with a causal filter
- Correction with the Iwan method, option I
The data need to be downloaded manually or automatically with:
!curl https://simpan.ugm.ac.id/s/N8DbowFH8ywgm2e/download > CWB.TCU129.Z
!curl https://simpan.ugm.ac.id/s/awgFsfM4sf3M0vw/download > CWB.TCU129.E
!curl https://simpan.ugm.ac.id/s/NHLCWCpcdHobFzq/download > CWB.TCU129.N
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 504k 100 504k 0 0 152k 0 0:00:03 0:00:03 --:--:-- 152k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 504k 100 504k 0 0 154k 0 0:00:03 0:00:03 --:--:-- 154k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 504k 100 504k 0 0 167k 0 0:00:03 0:00:03 --:--:-- 167k
1 Reading the data¶
The data are downloaded from strongmotioncenter.org in ASCII format. To process them with obspy, we parse them with pandas:
1.1 Defining the recording parameters¶
The recording parameters could be parsed automatically, but in this example we define them manually from the data file:
from obspy import UTCDateTime
delta=0.005 # sampling interval in seconds
station='TCU129' # station name
network='CWB' # network name
starttime=UTCDateTime('19990920T17:47:15.670') # recording start time
1.2 Reading the ASCII data¶
The ASCII data are read with the pandas fixed-width reader (pandas.fwf), starting at line 52 with a column width of 14:
from obspy import Trace, Stream
import pandas as pd
skiprow=51 # number of lines to skip
widths=[14] # column width (number of characters)
data_z = pd.read_fwf('/content/CWB.TCU129.Z', skiprows=51, widths=[14], names=['acc'])
data_n = pd.read_fwf('/content/CWB.TCU129.N', skiprows=51, widths=[14], names=['acc'])
data_e = pd.read_fwf('/content/CWB.TCU129.E', skiprows=51, widths=[14], names=['acc'])
data_z
| acc | |
|---|---|
| 0 | -0.119751 |
| 1 | 0.000000 |
| 2 | -0.059875 |
| 3 | 0.000000 |
| 4 | 0.000000 |
| ... | ... |
| 31995 | -1.856140 |
| 31996 | -1.437012 |
| 31997 | -0.778381 |
| 31998 | 0.000000 |
| 31999 | 0.359253 |
32000 rows × 1 columns
1.3 Converting the data to MSEED¶
We save the data as MSEED and read it again, to demonstrate saving data and creating obspy Stream and Trace objects. First we convert the data to a numpy.array with Pandas.Series.to_numpy, then use a loop to create a Trace for each component (Z, N, E) and save it as MSEED:
# convert the data to numpy.array
data_placeholder_fl_z = data_z['acc'].to_numpy()
data_placeholder_fl_n = data_n['acc'].to_numpy()
data_placeholder_fl_e = data_e['acc'].to_numpy()
# loop to create Trace objects and save them as MSEED
for data, channel in zip([data_placeholder_fl_z, data_placeholder_fl_n, data_placeholder_fl_e],['Z','N','E']):
trace = Trace(data=data) # fill the trace with the numpy.array data
trace.stats.delta=delta # set delta in stats
trace.stats.starttime = starttime # set starttime
trace.stats.network = network # set the network
trace.stats.station = station # set the station
trace.stats.channel = channel # set the channel for each component
trace.write(f"{network}.{station}.{channel}.{str(starttime)}.mseed") # save as an MSEED file
1.4 Reading the converted data¶
The data are now in the file explorer, so we can read them:
from obspy import read
sta = read('/content/CWB.TCU129.Z.1999-09-20T17:47:15.670000Z.mseed')
sta += read('/content/CWB.TCU129.N.1999-09-20T17:47:15.670000Z.mseed')
sta += read('/content/CWB.TCU129.E.1999-09-20T17:47:15.670000Z.mseed')
sta.plot()
/usr/local/lib/python3.7/dist-packages/obspy/imaging/util.py:266: UserWarning: AutoDateLocator was unable to pick an appropriate interval for this date range. It may be necessary to add an interval value to the AutoDateLocator's intervald dictionary. Defaulting to 30. plt.setp(ax.get_xticklabels(), fontsize='small') /usr/local/lib/python3.7/dist-packages/obspy/imaging/waveform.py:805: UserWarning: AutoDateLocator was unable to pick an appropriate interval for this date range. It may be necessary to add an interval value to the AutoDateLocator's intervald dictionary. Defaulting to 30. plt.setp(ax.get_xticklabels(), fontsize='small',
/usr/local/lib/python3.7/dist-packages/IPython/core/pylabtools.py:125: UserWarning: AutoDateLocator was unable to pick an appropriate interval for this date range. It may be necessary to add an interval value to the AutoDateLocator's intervald dictionary. Defaulting to 30. fig.canvas.print_figure(bytes_io, **kw)
1.5 Trimming the data¶
To process the same data as in the reference paper, we keep only the first 90 seconds:
starttime = sta[0].stats.starttime
endtime = starttime+90
sta.trim(starttime, endtime)
sta.plot()
1.6 Selecting the E component¶
In this example we first process the E component. A component is selected with Stream.select:
sta_e = sta.copy()
sta_e = sta_e.select(channel='E')
print(sta_e)
sta_e.plot()
1 Trace(s) in Stream: CW.TCU12..E | 1999-09-20T17:47:15.670000Z - 1999-09-20T17:48:45.670000Z | 200.0 Hz, 18001 samples
2 Integrating to velocity and displacement¶
As in the previous material, we integrate the acceleration to velocity and displacement.
2.1 Integrating to velocity¶
stv_e = sta_e.copy()
stv_e.integrate()
stv_e.plot()
The integrated waveform is unrealistic: the final velocity keeps increasing and does not return to zero.
2.2 Integrating to displacement¶
std_e = stv_e.copy()
std_e.integrate()
std_e.plot()
We can also combine the three Trace objects into one Stream:
from obspy import Stream
stc_e = Stream(traces=[sta_e[0], stv_e[0], std_e[0]])
stc_e.plot(equal_scale=False)
3 Simple baseline correction¶
We correct the baseline with the mean of the pre-event data in the first 18 seconds, processed with scipy. This matches Step 1 of the reference paper. The data have already been corrected this way; here we only demonstrate how to do it in Python:
3.1 Getting the data from the Stream¶
The times come from Trace.times() and the samples from Trace.data. The Trace is taken with the index sta_e[0]:
times = sta_e[0].times()
sta_e_data = sta_e[0].data
sta_e_data
array([-0.17962647, 0. , 0.05987549, ..., -1.73638916,
-1.07775879, -0.95800781]) Time and samples can be plotted with matplotlib:
import matplotlib.pyplot as plt
plt.plot(times, sta_e_data)
[<matplotlib.lines.Line2D at 0x7fed6ee9d7d0>]
3.2 Selecting the pre-event data¶
The pre-event data are taken from 0 to 18 s. For data in a numpy.array we can use np.where, which returns the indices where the values meet a given condition:
import numpy as np
pre_event_index=np.where((times>0) & (times<=18))
pre_event_index
(array([ 1, 2, 3, ..., 3598, 3599, 3600]),)
Then we take the data we want (0–18 s):
times_preev = times[pre_event_index]
sta_e_data_preev = sta_e_data[pre_event_index]
plt.plot(times, sta_e_data)
plt.plot(times_preev, sta_e_data_preev, label='Data pre-event')
plt.legend()
<matplotlib.legend.Legend at 0x7fed6c621390>
3.3 Computing the baseline correction from the pre-event data¶
The mean of the pre-event data is easily computed with numpy.array.mean:
simple_baseline_coeff=sta_e_data.mean()
print(simple_baseline_coeff)
-0.7634964629307261
The correction is a simple arithmetic operation:
sta_e_data = sta_e_data-simple_baseline_coeff
plt.plot(times, sta_e_data)
[<matplotlib.lines.Line2D at 0x7fed6c51c0d0>]
3.4 Integrating to velocity and displacement¶
First we convert the data to a Stream object:
sta_e_cor_simple = sta_e[0].copy()
sta_e_cor_simple.data = sta_e_data
sta_e_cor_simple.plot()
then integrate to velocity:
sta_e_cor_simple_vel = sta_e_cor_simple.copy()
sta_e_cor_simple_vel.integrate()
sta_e_cor_simple_vel.plot()
and displacement:
sta_e_cor_simple_disp = sta_e_cor_simple_vel.copy()
sta_e_cor_simple_disp.integrate()
sta_e_cor_simple_disp.plot()
4 Baseline correction by fitting the event data¶
In this correction we fit a line to the event data:
4.1 Selecting the data¶
The data are selected as in 3.1, with numpy.where:
event_index=np.where((times>18))
sta_e_data_event = sta_e_data[event_index]
times_event = times[event_index]
plt.plot(times, sta_e_data)
plt.plot(times_event, sta_e_data_event, label='Data Event')
plt.legend()
<matplotlib.legend.Legend at 0x7fed6c3a7dd0>
4.2 Computing the fitting parameters¶
The fitting parameters are obtained by regression with scipy.stats.linregress:
import scipy
regression = scipy.stats.linregress(times_event, sta_e_data_event)
slope = regression[0]
intercept = regression[1]
print(slope, intercept)
-0.020495715458913096 0.914237845788737
The regression line can be plotted:
trend_event = times_event*slope + intercept
plt.plot(times, sta_e_data)
plt.plot(times_event, sta_e_data_event)
plt.plot(times_event, trend_event, color='magenta', label="Garis regresi")
plt.legend()
<matplotlib.legend.Legend at 0x7fed6c2e87d0>
4.3 Applying the correction¶
The correction is a subtraction:
sta_e_data_event_cor_fit = sta_e_data_event - trend_event
sta_e_data_event_cor_fit
array([ 0.098533 , 0.21838645, 0.15861344, ..., -0.04272111,
0.61601174, 0.7358652 ]) The plot shows little difference, because the line is close to a straight line at 0:
plt.plot(times_event, sta_e_data_event)
plt.plot(times_event, sta_e_data_event_cor_fit)
plt.xlim(34,36)
(34.0, 36.0)
4.4 Replacing the event data with the corrected data¶
Since we already have the event indices, we can write the corrected values back into the data:
sta_e_data_cor_fit = sta_e_data.copy()
sta_e_data_cor_fit[event_index] = sta_e_data_event_cor_fit
plt.plot(times, sta_e_data_cor_fit)
[<matplotlib.lines.Line2D at 0x7fed6f056550>]
4.5 Integrating to velocity and displacement¶
First we convert the data to a Stream object:
sta_e_cor_fit = sta_e[0].copy()
sta_e_cor_fit.data = sta_e_data_cor_fit
sta_e_cor_fit.plot()
Integrating to velocity:
sta_e_cor_fit_vel = sta_e_cor_fit.copy()
sta_e_cor_fit_vel.integrate()
sta_e_cor_fit_vel.plot()
Integrating to displacement:
sta_e_cor_fit_disp = sta_e_cor_fit_vel.copy()
sta_e_cor_fit_disp.integrate()
sta_e_cor_fit_disp.plot()
5 Applying an acausal filter¶
After the correction in step (4), following the reference, we apply an acausal second-order Butterworth highpass filter at 0.05 Hz with obspy.
5.1 Converting the numpy.array to a Stream object¶
To process the data with obspy, we first create a Trace with the data from the previous step. We copy the original data and replace the samples with the corrected ones:
sta_e_cor_fit = sta_e[0].copy()
sta_e_cor_fit.data = sta_e_data_cor_fit
sta_e_cor_fit.plot()
5.2 Filtering¶
Next we apply the filter:
f=0.05
zerophase=True #acausal
corner=2
sta_e_cor_fit_filt1 = sta_e_cor_fit.copy()
sta_e_cor_fit_filt1.filter('highpass', freq=f, zerophase=zerophase, corners=corner)
sta_e_cor_fit_filt1.plot()
5.3 Integrating to ground velocity¶
After filtering, we integrate to get the ground motion as before:
sta_e_cor_fit_filt1_vel = sta_e_cor_fit_filt1.copy()
sta_e_cor_fit_filt1_vel.integrate()
sta_e_cor_fit_filt1_vel.plot()
The integrated result shows a transient signal before the event, which can reduce the peak value.
5.4 Integrating to ground displacement¶
sta_e_cor_fit_filt1_disp = sta_e_cor_fit_filt1_vel.copy()
sta_e_cor_fit_filt1_disp.integrate()
sta_e_cor_fit_filt1_disp.plot()
The transient signal is still visible and affects the result.
6 Applying a causal filter¶
The transient signal from filter (5) is avoided with a causal filter. The process is the same, except that the zerophase parameter is set to False:
6.1 Applying the causal filter¶
f=0.05
zerophase=False
corner=2
sta_e_cor_fit_filt2 = sta_e_cor_fit.copy()
sta_e_cor_fit_filt2.filter('highpass', freq=f, zerophase=zerophase, corners=corner)
sta_e_cor_fit_filt2.plot()
6.2 Integrating to ground velocity¶
sta_e_cor_fit_filt2_vel = sta_e_cor_fit_filt2.copy()
sta_e_cor_fit_filt2_vel.integrate()
sta_e_cor_fit_filt2_vel.plot()
With this filter, the transient signal of the acausal filter does not appear.
6.3 Integrating to ground displacement¶
sta_e_cor_fit_filt2_disp = sta_e_cor_fit_filt2_vel.copy()
sta_e_cor_fit_filt2_disp.integrate()
sta_e_cor_fit_filt2_disp.plot()
7 The method of Iwan et al. (1985), option 1¶
Iwan et al. (1985) introduced a somewhat more complex baseline correction. It is based on hysteresis in the transducer when the acceleration exceeds 50 cm/s². This causes step-like offsets in the acceleration, whose parameters can be found by fitting a straight line to the velocity.
7.1 Finding $t_1$ and $t_2$¶
The Iwan method, option 1, splits the analysis into three parts separated by $t_1$ and $t_2$. Data before $t_1$ are pre-event data, data between $t_1$ and $t_2$ contain the main ground acceleration, and data after $t_2$ are post-event data. $t_1$ is the first time the acceleration exceeds 50 cm/s², and $t_2$ is the time after which it stays below 50 cm/s², in line with the hysteresis described above. $t_1$ and $t_2$ can also be related to the period of strongest shaking. As before, the values are found with numpy.where:
import numpy as np
import matplotlib.pyplot as plt
sta_e_data = sta_e[0].data
sta_data_higher50_index = np.where((sta_e_data>50))
t1_index = sta_data_higher50_index[0][0]
t2_index = sta_data_higher50_index[0][-1] + 1
t1 = times[t1_index]
t2 = times[t2_index]
plt.plot(times, sta_e_data)
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
<matplotlib.lines.Line2D at 0x7fed6bd64e50>
In the velocity:
stv_e_data = stv_e[0].data
plt.plot(times, stv_e_data)
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
<matplotlib.lines.Line2D at 0x7fed6bcdfad0>
7.2 Computing $a_f$¶
$a_f$ is the gradient from $t_1$ to the end of the record, from the equation:
$$ v_f(t) = v_0 + a_f t $$
In practice we use index slicing and a regression with scipy.stats.linregress:
import scipy
times_after_50 = times[t2_index:]
stv_e_data_after_50 = stv_e_data[t2_index:]
plt.plot(times, stv_e_data)
plt.plot(times_after_50, stv_e_data_after_50)
plt.axvline(x=t2, color="green", label="$t_2$")
regression_iwan1_after_50 = scipy.stats.linregress(times_after_50, stv_e_data_after_50)
print("slope: ",regression_iwan1_after_50[0])
plt.legend()
slope: -1.156331846971815
<matplotlib.legend.Legend at 0x7fed6bcafdd0>
regression_iwan1_after_50 = scipy.stats.linregress(times_after_50, stv_e_data_after_50)
slope_iwan1_after_50 = regression_iwan1_after_50[0]
intercept_iwan1_after_50 = regression_iwan1_after_50[1]
print(slope_iwan1_after_50, intercept_iwan1_after_50)
line_fit_iwan1_after_50 = times_after_50*slope_iwan1_after_50 + intercept_iwan1_after_50
plt.plot(times, stv_e_data)
plt.plot(times_after_50, stv_e_data_after_50)
plt.plot(times_after_50, line_fit_iwan1_after_50, color="red")
plt.axvline(x=t2, color="green")
-1.156331846971815 36.24933248149239
<matplotlib.lines.Line2D at 0x7fed6bb51250>
The code above gives $a_f=-1.156$
7.3 Computing $a_m$¶
$a_m$ is used to correct the acceleration in the zone of strong shaking between $t_1$ and $t_2$. It is obtained by regression, or a simple gradient, of the data between $t_1$ and $t_2$ with $v_f(t_1)=0$: $$ a_m = \frac{v_f(t_2)}{t_2-t_1} $$
First we take the data between $t_1$ and $t_2$:
times_between_50 = times[t1_index:t2_index]
stv_e_data_between_50 = stv_e_data[t1_index:t2_index]
plt.plot(times, stv_e_data)
plt.plot(times_between_50, stv_e_data_between_50)
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
<matplotlib.lines.Line2D at 0x7fed6bac3b90>
then run a regression as before:
import scipy
times_between_50_bound = [times_between_50[0],times_between_50[-1]]
stv_e_data_between_50_bound = [stv_e_data_between_50[0],stv_e_data_between_50[-1]]
regression_iwan1_between_50 = scipy.stats.linregress(times_between_50_bound, stv_e_data_between_50_bound)
slope_iwan1_between_50 = regression_iwan1_between_50[0]
intercept_iwan1_between_50 = regression_iwan1_between_50[1]
print(slope_iwan1_between_50, intercept_iwan1_between_50)
line_fit_iwan1_between_50 = times_between_50*slope_iwan1_between_50 + intercept_iwan1_between_50
plt.plot(times, stv_e_data)
plt.plot(times_between_50, stv_e_data_between_50)
plt.plot(times_between_50, line_fit_iwan1_between_50, color="red")
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
print("slope: ",slope_iwan1_between_50)
-0.9154329987712069 19.646331011115382 slope: -0.9154329987712069
7.4 Building the acceleration correction¶
With $a_f$ and $a_m$ we can correct the acceleration data. First we create a placeholder for the correction: a vector of ones with the length of the data:
sta_e_iwan1_cor_coeff = np.ones(len(sta_e_data))
sta_e_iwan1_cor_coeff
array([1., 1., 1., ..., 1., 1., 1.])
Then each part is filled with its value:
sta_e_iwan1_cor_coeff[:t1_index] = 0
sta_e_iwan1_cor_coeff[t1_index:t2_index] = slope_iwan1_between_50
sta_e_iwan1_cor_coeff[t2_index:] = slope_iwan1_after_50
plt.plot(times, sta_e_iwan1_cor_coeff, zorder=110, linewidth=3, color="k", label="Koreksi")
plt.axvline(x=t1, label="$t_1$", color="red")
plt.axvline(x=t2, label="$t_2$", color="orange")
plt.axhline(y=slope_iwan1_between_50, color="green", label="$a_m$")
plt.axhline(y=slope_iwan1_after_50, color="blue", label="a_f")
plt.xlabel("waktu [s]")
plt.ylabel("akselerasi [cm/s/s]")
plt.legend()
<matplotlib.legend.Legend at 0x7fed6b9cea10>
7.5 Applying the correction¶
The correction is a simple arithmetic operation:
sta_e_iwan1_corrected = sta_e_data - sta_e_iwan1_cor_coeff
plt.plot(times, sta_e_data)
plt.plot(times, sta_e_iwan1_corrected)
[<matplotlib.lines.Line2D at 0x7fed6b96bed0>]
7.6 Integrating to velocity¶
The corrected data are converted to a Stream object and then to velocity:
sta_e_cor_iwan1 = sta_e[0].copy()
sta_e_cor_iwan1.data = sta_e_iwan1_corrected
sta_e_cor_iwan1.plot()
integration to velocity:
stv_e_cor_iwan1 = sta_e_cor_iwan1.copy()
stv_e_cor_iwan1.integrate()
stv_e_cor_iwan1.plot()
7.7 Integrating to ground displacement¶
The same for the displacement:
std_e_cor_iwan1 = stv_e_cor_iwan1.copy()
std_e_cor_iwan1.integrate()
std_e_cor_iwan1.plot()
8 Comparing the corrections¶
8.1 Acceleration¶
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,10))
# simple baseline correction
ax=fig.add_subplot(5,1,1)
ax.plot(times, sta_e_cor_simple.data, label='simple baseline', color="red")
# fitting correction
ax=fig.add_subplot(5,1,2)
ax.plot(times, sta_e_cor_fit.data, label='fitting', color="blue")
# acausal filter
ax=fig.add_subplot(5,1,3)
ax.plot(times, sta_e_cor_fit_filt1.data, label='filterakausal', color="green")
# causal filter
ax=fig.add_subplot(5,1,4)
ax.plot(times, sta_e_cor_fit_filt2.data,label='filter kausal', color="magenta")
# Iwan method 1
ax=fig.add_subplot(5,1,5)
ax.plot(times, sta_e_cor_iwan1.data, label='iwan 1', color="orange")
fig.legend(loc='upper center')
ax.set_title("Akselerasi")
Text(0.5, 1.0, 'Akselerasi')
8.2 Velocity¶
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,10))
# simple baseline correction
ax=fig.add_subplot(5,1,1)
ax.plot(times, sta_e_cor_simple_vel.data, label='simple baseline', color="red")
# fitting correction
ax=fig.add_subplot(5,1,2)
ax.plot(times, sta_e_cor_fit_vel.data, label='fitting', color="blue")
# acausal filter
ax=fig.add_subplot(5,1,3)
ax.plot(times, sta_e_cor_fit_filt1_vel.data, label='filterakausal', color="green")
# causal filter
ax=fig.add_subplot(5,1,4)
ax.plot(times, sta_e_cor_fit_filt2_vel.data,label='filter kausal', color="magenta")
# Iwan method 1
ax=fig.add_subplot(5,1,5)
ax.plot(times, stv_e_cor_iwan1.data, label='iwan 1', color="orange")
fig.legend(loc='upper center')
ax.set_title("Kecepatan")
Text(0.5, 1.0, 'Kecepatan')
8.3 Displacement¶
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15,10))
# simple baseline correction
ax=fig.add_subplot(5,1,1)
ax.plot(times, sta_e_cor_simple_disp.data, label='simple baseline', color="red")
# fitting correction
ax=fig.add_subplot(5,1,2)
ax.plot(times, sta_e_cor_fit_disp.data, label='fitting', color="blue")
# acausal filter
ax=fig.add_subplot(5,1,3)
ax.plot(times, sta_e_cor_fit_filt1_disp.data, label='filterakausal', color="green")
# causal filter
ax=fig.add_subplot(5,1,4)
ax.plot(times, sta_e_cor_fit_filt2_disp.data,label='filter kausal', color="magenta")
# Iwan method 1
ax=fig.add_subplot(5,1,5)
ax.plot(times, std_e_cor_iwan1.data, label='iwan 1', color="orange")
fig.legend(loc='upper center')
ax.set_title("Displacement")
Text(0.5, 1.0, 'Displacement')
9 Exercises¶
9.1 Find $t_1$ and $t_2$¶
import numpy as np
import matplotlib.pyplot as plt
sta_e_data = sta_e[0].data
sta_data_higher50_index = np.where(#isikan disini) <------------------------
t1_index = sta_data_higher50_index[0][0]
t2_index = sta_data_higher50_index[0][-1] + 1
t1 = times[t1_index]
t2 = times[t2_index]
plt.plot(times, sta_e_data)
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
<matplotlib.lines.Line2D at 0x7f17c8e777d0>
9.2 Compute $a_f$¶
import scipy
times_after_50 = times[#isi disini]
stv_e_data_after_50 = stv_e_data[#isi disini]
plt.plot(times, stv_e_data)
plt.plot(times_after_50, stv_e_data_after_50)
plt.axvline(x=t2, color="green", label="$t_2$")
regression_iwan1_after_50 = scipy.stats.linregress(#isi disini)
print("slope: ",regression_iwan1_after_50[0])
plt.legend()
slope: -1.156331846971815
<matplotlib.legend.Legend at 0x7f17c8e67b90>
9.3 Compute $a_m$¶
times_between_50 = times[#isi disini]
stv_e_data_between_50 = stv_e_data[#isi disini]
plt.plot(times, stv_e_data)
plt.plot(times_between_50, stv_e_data_between_50)
plt.axvline(x=t1, color="green")
plt.axvline(x=t2, color="green")
<matplotlib.lines.Line2D at 0x7f17c8de0b10>
9.4 Build the acceleration correction¶
sta_e_iwan1_cor_coeff = np.ones(#isi disini)
sta_e_iwan1_cor_coeff[#isi disini] = #fill in here
sta_e_iwan1_cor_coeff[#isi disini] = #fill in here
sta_e_iwan1_cor_coeff[#isi disini] = #fill in here
plt.plot(times, sta_e_iwan1_cor_coeff, zorder=110, linewidth=3, color="k", label="Koreksi")
plt.axvline(x=t1, label="$t_1$", color="red")
plt.axvline(x=t2, label="$t_2$", color="orange")
plt.axhline(y=slope_iwan1_between_50, color="green", label="$a_m$")
plt.axhline(y=slope_iwan1_after_50, color="blue", label="a_f")
plt.xlabel("waktu [s]")
plt.ylabel("akselerasi [cm/s/s]")
plt.legend()
<matplotlib.legend.Legend at 0x7f17c8d0cc10>
9.5 Apply the correction¶
sta_e_iwan1_corrected = #fill in here
plt.plot(times, sta_e_data)
plt.plot(times, sta_e_iwan1_corrected)
[<matplotlib.lines.Line2D at 0x7f17c8c2e9d0>]
9.6 Integrate to velocity¶
sta_e_cor_iwan1 = sta_e[0].copy()
sta_e_cor_iwan1.data = #fill in here
sta_e_cor_iwan1.plot()
stv_e_cor_iwan1 = sta_e_cor_iwan1.copy()
#fill in here
stv_e_cor_iwan1.plot()
%matplotlib inline
from obspy import *
from obspy.clients.fdsn import Client
import numpy as np
import matplotlib.pylab as plt
c = Client("IRIS")
tmp1 = UTCDateTime("1989-07-08T03:40:00.0")
tmp2 = UTCDateTime("1989-07-08T04:05:00.0")
dat = c.get_waveforms("CD", "WMQ", "", "BH*", tmp1, tmp2, attach_response = True)
dat.detrend('linear')
dat.detrend('demean')
dat.remove_response(output="VEL")
dat.detrend('linear')
dat.detrend('demean')
print(dat)
3 Trace(s) in Stream: CD.WMQ..BHE | 1989-07-08T03:48:37.790000Z - 1989-07-08T04:04:41.040000Z | 20.0 Hz, 19266 samples CD.WMQ..BHN | 1989-07-08T03:48:37.790000Z - 1989-07-08T04:04:41.040000Z | 20.0 Hz, 19266 samples CD.WMQ..BHZ | 1989-07-08T03:48:37.790000Z - 1989-07-08T04:04:41.040000Z | 20.0 Hz, 19266 samples
chanel = 2
tm = dat[chanel].times()
xmin = 0
xmax = 700
dat1 = dat[chanel].copy()
dat2 = dat[chanel].copy()
dat2.filter(type="bandpass", freqmin=0.01, freqmax=0.05)
dat3 = dat[chanel].copy()
dat3.filter(type="bandpass", freqmin=0.05, freqmax=0.1)
dat4 = dat[chanel].copy()
dat4.filter(type="bandpass", freqmin=0.1, freqmax=0.5)
dat5 = dat[chanel].copy()
dat5.filter(type="bandpass", freqmin=0.5, freqmax=1)
dat6 = dat[chanel].copy()
dat6.filter(type="bandpass", freqmin=1., freqmax=5.)
dat7 = dat[chanel].copy()
dat7.filter(type="bandpass", freqmin=5., freqmax=10.)
plt.rcParams['figure.figsize'] = 17, 21
fig = plt.figure()
ax1 = fig.add_subplot(7,1,1)
ax1.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat1.data, 'k')
plt.xlim(xmin, xmax)
plt.title('unfiltered')
plt.ylabel('amplitude \n [m/s]')
ax2 = fig.add_subplot(7,1,2)
ax2.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat2.data, 'k')
plt.xlim(xmin, xmax)
plt.title('0.01 - 0.05 Hz')
plt.ylabel('amplitude \n [m/s]')
ax3 = fig.add_subplot(7,1,3)
ax3.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat3.data, 'k')
plt.xlim(xmin, xmax)
plt.title('0.05 - 0.1 Hz')
plt.ylabel('amplitude \n [m/s]')
ax4 = fig.add_subplot(7,1,4)
ax4.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat4.data, 'k')
plt.xlim(xmin, xmax)
plt.title('0.1 - 0.5 Hz')
plt.ylabel('amplitude \n [m/s]')
ax5 = fig.add_subplot(7,1,5)
ax5.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat5.data, 'k')
plt.xlim(xmin, xmax)
plt.title('0.5 - 1.0 Hz')
plt.ylabel('amplitude \n [m/s]')
ax6 = fig.add_subplot(7,1,6)
ax6.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat6.data, 'k')
plt.xlim(xmin, xmax)
plt.title('1.0 - 5.0 Hz')
plt.ylabel('amplitude \n [m/s]')
ax7 = fig.add_subplot(7,1,7)
ax7.ticklabel_format(style='sci', axis='y', scilimits=(-1,1))
plt.plot(tm, dat7.data, 'k')
plt.xlim(xmin, xmax)
plt.title('5.0 - 10.0 Hz')
plt.xlabel('time [sec]')
plt.ylabel('amplitude \n [m/s]')
plt.subplots_adjust(hspace=0.3)
plt.show()
/usr/local/lib/python3.7/dist-packages/obspy/signal/filter.py:62: UserWarning: Selected high corner frequency (10.0) of bandpass is at or above Nyquist (10.0). Applying a high-pass instead. warnings.warn(msg)