eqsig examples¶
Calculation of response spectrum¶
Array based input example:
The majority of eqsig’s functions have been implemented using the eqsig.Signal
and eqsig.AccSignal
,
however, many have also been implemented using numpy arrays. While it is recommended to
use the AccSignal
object as an input, you can also use the array-based version of the function.
The source code is shown below, which can be downloaded
here
.
Examples using AccSignal¶
The source code is shown below, which can be downloaded
here
.
1import numpy as np
2import matplotlib.pyplot as plt
3
4from eqsig.single import AccSignal
5from tests.conftest import TEST_DATA_DIR
6
7
8def show_test_motion():
9 record_path = TEST_DATA_DIR
10 record_filename = 'test_motion_dt0p01.txt'
11 motion_step = 0.01
12 rec = np.loadtxt(record_path + record_filename)
13 acc_signal = AccSignal(rec, motion_step)
14 acc_signal.generate_displacement_and_velocity_series()
15 bf, sp = plt.subplots(3)
16 sp[0].plot(acc_signal.time, acc_signal.values)
17 sp[1].plot(acc_signal.time, acc_signal.velocity)
18 sp[2].plot(acc_signal.time, acc_signal.displacement)
19 plt.show()
20
21
22def show_response_spectra_at_high_frequencies():
23 record_path = TEST_DATA_DIR
24 test_filename = 'test_motion_true_spectra_acc.csv'
25 data = np.loadtxt(record_path + test_filename, skiprows=1, delimiter=",")
26 times = data[:40, 0]
27 ss_s_a = data[:40, 1]
28
29 record_filename = 'test_motion_dt0p01.txt'
30 motion_step = 0.01
31 rec = np.loadtxt(record_path + record_filename)
32 acc_signal = AccSignal(rec, motion_step, response_times=times)
33 s_a = acc_signal.s_a
34
35 s_a_in_g = s_a / 9.81
36 plt.plot(times, s_a_in_g, label="eqsig")
37 plt.plot(times, ss_s_a, label="true-ish")
38 plt.legend()
39 plt.show()
40
41
42def show_fourier_spectra_stable_against_aliasing():
43 record_path = TEST_DATA_DIR
44
45 record_filename = 'test_motion_dt0p01.txt'
46 motion_step = 0.01
47 rec = np.loadtxt(record_path + record_filename, skiprows=2)
48 rec2 = np.zeros(2 ** 13)
49 rec2[:len(rec)] = rec
50 org_signal = AccSignal(rec, motion_step)
51 extended_signal = AccSignal(rec2, motion_step)
52
53 rec_split = []
54 for i in range(int(len(rec2) / 2)):
55 rec_split.append(rec2[i * 2])
56
57 acc_split = AccSignal(rec_split, motion_step * 2)
58
59 bf, sp = plt.subplots(2)
60 sp[0].plot(org_signal.time, org_signal.values)
61 sp[0].plot(extended_signal.time, extended_signal.values)
62 sp[0].plot(acc_split.time, acc_split.values)
63
64 sp[1].plot(org_signal.fa_frequencies, abs(org_signal.fa_spectrum), lw=0.7, label="original")
65 sp[1].plot(acc_split.fa_frequencies, abs(acc_split.fa_spectrum), lw=0.7, label="split")
66 sp[1].plot(extended_signal.fa_frequencies, abs(extended_signal.fa_spectrum), lw=0.7, label="full")
67
68 plt.legend()
69 plt.show()
70
71
72if __name__ == '__main__':
73 show_fourier_spectra_stable_against_aliasing()