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.

  1. The source code is shown below, which can be downloaded here.

Examples using AccSignal

  1. The source code is shown below, which can be downloaded here.

 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import matplotlib.pyplot as plt

from eqsig.single import AccSignal
from tests.conftest import TEST_DATA_DIR


def show_test_motion():
    record_path = TEST_DATA_DIR
    record_filename = 'test_motion_dt0p01.txt'
    motion_step = 0.01
    rec = np.loadtxt(record_path + record_filename)
    acc_signal = AccSignal(rec, motion_step)
    acc_signal.generate_displacement_and_velocity_series()
    bf, sp = plt.subplots(3)
    sp[0].plot(acc_signal.time, acc_signal.values)
    sp[1].plot(acc_signal.time, acc_signal.velocity)
    sp[2].plot(acc_signal.time, acc_signal.displacement)
    plt.show()


def show_response_spectra_at_high_frequencies():
    record_path = TEST_DATA_DIR
    test_filename = 'test_motion_true_spectra_acc.csv'
    data = np.loadtxt(record_path + test_filename, skiprows=1, delimiter=",")
    times = data[:40, 0]
    ss_s_a = data[:40, 1]

    record_filename = 'test_motion_dt0p01.txt'
    motion_step = 0.01
    rec = np.loadtxt(record_path + record_filename)
    acc_signal = AccSignal(rec, motion_step, response_times=times)
    s_a = acc_signal.s_a

    s_a_in_g = s_a / 9.81
    plt.plot(times, s_a_in_g, label="eqsig")
    plt.plot(times, ss_s_a, label="true-ish")
    plt.legend()
    plt.show()


def show_fourier_spectra_stable_against_aliasing():
    record_path = TEST_DATA_DIR

    record_filename = 'test_motion_dt0p01.txt'
    motion_step = 0.01
    rec = np.loadtxt(record_path + record_filename)
    rec2 = np.zeros(2 ** 13)
    rec2[:len(rec)] = rec
    org_signal = AccSignal(rec, motion_step)
    extended_signal = AccSignal(rec2, motion_step)

    rec_split = []
    for i in range(int(len(rec2) / 2)):
        rec_split.append(rec2[i * 2])

    acc_split = AccSignal(rec_split, motion_step * 2)

    bf, sp = plt.subplots(2)
    sp[0].plot(org_signal.time, org_signal.values)
    sp[0].plot(extended_signal.time, extended_signal.values)
    sp[0].plot(acc_split.time, acc_split.values)

    sp[1].plot(org_signal.fa_frequencies, abs(org_signal.fa_spectrum), lw=0.7, label="original")
    sp[1].plot(acc_split.fa_frequencies, abs(acc_split.fa_spectrum), lw=0.7, label="split")
    sp[1].plot(extended_signal.fa_frequencies, abs(extended_signal.fa_spectrum), lw=0.7, label="full")

    plt.legend()
    plt.show()