When dealing with seismic data, a critical step in understanding the potential impact on structures is analyzing the response to ground motion, often represented as a response spectrum. This Python script by QuakeLogic enables engineers and researchers to compute the response spectrum of seismic time-series data (in .tcl format), plot the results, compute Peak Ground Acceleration (PGA), Peak Ground Velocity (PGV), Peak Ground Displacement (PGD), and save them for further analysis.
In this blog post, we will explain how to use this Python code, its features, and provide an example of how to compute the response spectrum and key seismic parameters (PGA, PGV, PGD) for a given ground motion.
Key Features of the Script
Input and Output:
The script processes input acceleration time-series data stored in .tcl format. The input files should contain acceleration data in units of in/s², which the script converts to g (gravitational acceleration).
Fourier Transform-Based Method:
The response spectrum is calculated using a Fourier transform-based approach, ensuring accuracy across a range of frequencies and damping ratios.
Peak Ground Parameters:
The script computes PGA, PGV, and PGD to offer a complete picture of the seismic intensity. PGA represents the highest acceleration during the event, PGV corresponds to the highest velocity, and PGD reflects the largest displacement.
Plots and Data Files:
The script generates plots of the input acceleration time series, response spectrum, and computed PGA, PGV, and PGD values, saving them in specified directories. It also exports the computed response spectrum and seismic parameters into output files.
Step-by-Step Guide to Use the Script
Installation and Requirements
Before running the script, ensure you have the necessary Python packages installed. Run the following command to install the required libraries:
pip install numpy matplotlib tqdm
Create a Config File
The script reads parameters from a configuration file (config.json). This file specifies the input directory, response spectrum periods, damping ratio, and other critical parameters. Here’s an example of what the config.json should look like:
{
"sampling_rate": 50,
"damping_ratio": 0.05,
"min_period": 0.01,
"max_period": 5.0,
"num_periods": 100,
"input_dir": "input_data/"
}
Run the Script
After preparing the input files (in .tcl format) and the config file, you can run the script using the following command:
python seismic_response_spectrum_analysis.py
The script processes all .tcl files in the specified input directory (input_data/), computes the response spectrum, and outputs the results, including PGA, PGV, and PGD.
Computation of PGA, PGV, and PGD
- PGA (Peak Ground Acceleration):
The highest absolute value of the acceleration time series, representing the strongest shaking the ground experiences. - PGV (Peak Ground Velocity):
Computed by integrating the acceleration time series over time to derive velocity and extracting the maximum value. - PGD (Peak Ground Displacement):
Derived by further integrating the velocity time series to calculate displacement, with the peak displacement indicating the largest ground movement.
These values provide critical insights into the severity of ground motion and are vital for structural response analyses.
Generated Outputs
The script generates three key outputs:
- Plots:
The input acceleration time series, response spectrum, and seismic parameters (PGA, PGV, PGD) are plotted and saved as PNG files in thefigures/directory. - Response Spectrum Data:
The computed response spectrum is saved in.datformat in theoutput_data/directory. - Seismic Parameters:
PGA, PGV, and PGD are computed and saved in an output file for further reference.
How the Code Works
1. Loading Acceleration Data
The script reads acceleration data from .tcl files, which are expected to contain acceleration in in/s². The values are converted to g using a conversion factor.
2. Calculating the Response Spectrum
The script uses the Fourier transform method to compute the response spectrum for each oscillator frequency and damping ratio.
3. Computing PGA, PGV, and PGD
The script integrates the acceleration time series to compute velocity and displacement, identifying the peak values for PGA, PGV, and PGD.
4. Plotting and Saving Results
Once the response spectrum and seismic parameters are calculated, the script plots both the input acceleration time series and the response spectrum. The PGA, PGV, and PGD values are also printed for reference.
Example Code
import os
import glob
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
import json
IN_S2_TO_G = 386.0886 # Conversion factor: 1 g = 386.0886 in/s²
def calc_sdf_resp(freq, fourier_amp, osc_damping, osc_freq, max_freq_ratio=5., peak_resp_only=False):
h = (-np.power(osc_freq, 2.) / ((np.power(freq, 2.) - np.power(osc_freq, 2.)) - 2.j * osc_damping * osc_freq * freq))
n = len(fourier_amp)
m = max(n, int(max_freq_ratio * osc_freq / freq[1]))
scale = float(m) / float(n)
resp = scale * np.fft.irfft(fourier_amp * h, 2 * (m - 1))
if peak_resp_only:
return np.abs(resp).max()
return resp
def calc_spec_accels(time_step, accel_ts, osc_freqs, osc_damping=0.05):
fourier_amp = np.fft.rfft(accel_ts)
freq = np.linspace(0, 1. / (2 * time_step), num=fourier_amp.size)
spec_accels = [calc_sdf_resp(freq, fourier_amp, osc_damping, of, peak_resp_only=True)
for of in osc_freqs]
return np.rec.fromarrays([osc_freqs, spec_accels], names='osc_freq,spec_accel')
def load_acceleration_file(filepath):
acc_data_in_in_s2 = np.loadtxt(filepath)
return acc_data_in_in_s2 / IN_S2_TO_G # Convert from in/s² to g
def compute_pgv(acc, time_step):
vel = np.cumsum(acc) * time_step
return np.max(np.abs(vel))
def compute_pgd(vel, time_step):
disp = np.cumsum(vel) * time_step
return np.max(np.abs(disp))
def gen_rsa(file_to_use, config, figures_dir):
data = load_acceleration_file(file_to_use)
osc_damping = config['damping_ratio']
osc_freqs = np.logspace(np.log10(1.0 / config['max_period']), np.log10(1.0 / config['min_period']), config['num_periods'])
time_step = 1.0 / config['sampling_rate']
pga = np.max(np.abs(data))
pgv = compute_pgv(data, time_step)
pgd = compute_pgd(pgv, time_step)
resp_spec = calc_spec_accels(time_step, data, osc_freqs, osc_damping)
# Plotting and saving code...
# (skipped for brevity, similar to original script)
# Save PGA, PGV, PGD
with open(f'{figures_dir}/seismic_parameters.txt', 'w') as file:
file.write(f'PGA: {pga}nPGV: {pgv}nPGD: {pgd}n')
Contact and Versioning
Version: 1.1
Last Update: October 23, 2024
This code was developed by QuakeLogic Inc. to assist with seismic data analysis. For support, contact us at: support@quakelogic.net.
We hope this tool is helpful for your seismic analysis. Let us know if you have any feedback!
Last reviewed: 2026-07-04
Executive Summary
Earthquake engineering connects ground motion, structural response, performance objectives, instrumentation, and post-event decision support. This article has been expanded as an engineering resource for readers evaluating earthquake engineering concepts, instrumentation choices, and monitoring workflows. The discussion is educational and should be paired with project-specific review by qualified engineers, applicable codes, owner requirements, and equipment documentation.
Key Takeaways
- Define the engineering objective before selecting sensors, test equipment, trigger thresholds, or reporting workflows.
- Use calibrated instrumentation, documented installation practices, time synchronization, and traceable data handling where measurement quality matters.
- Interpret measured data in context: site conditions, structure type, noise environment, sampling rate, bandwidth, and boundary conditions all affect conclusions.
- Use authoritative references and project-specific criteria rather than relying on generic thresholds or unsupported performance claims.
Technical Explanation
In practical earthquake engineering work, the engineering system is more than a sensor or a test platform. A credible workflow includes the measurement objective, instrument selection, mounting or boundary conditions, sampling and timing strategy, data validation, event or response detection, engineering review, and reporting. Weakness in any part of that chain can reduce confidence in the final interpretation.
For monitoring applications, engineers should document sensor orientation, coupling, environmental exposure, dynamic range, frequency bandwidth, data logger configuration, clock synchronization, communications, and maintenance procedures. For testing applications, engineers should document input motion, fixture design, payload properties, control limits, safety interlocks, acceptance criteria, and post-test data review.
Engineering Applications
| Application | Engineering Question | Typical Evidence Needed |
|---|---|---|
| Research and education | How does a structure, component, or sensor respond under controlled conditions? | Test plan, calibrated data, input motion, boundary conditions, and repeatable observations. |
| Critical infrastructure | Is the asset response normal, changing, or potentially unsafe after an event? | Baseline data, event records, thresholds, inspection workflow, and engineering sign-off. |
| Industrial facilities | Can monitoring support operational continuity and response decisions? | Site-specific criteria, reliable telemetry, alarm logic, maintenance records, and documented procedures. |
People Also Ask
What should be specified before buying equipment?
Specify the measurement objective, frequency range, amplitude range, environment, data format, timing needs, installation constraints, reporting requirements, and applicable standards or owner criteria.
Why do references and standards matter?
They provide terminology, acceptance criteria, test methods, and documentation expectations. They do not replace engineering judgment, but they reduce ambiguity and make results easier to review.
How should data quality be checked?
Review calibration status, timing, clipping, sensor orientation, signal-to-noise ratio, environmental artifacts, data completeness, and whether the record supports the engineering decision being made.
Related QuakeLogic Resources
- Safe Operation and Maintenance Guidelines for Shake Tables
- MOTIONMASTER-6 Stewart Platform for Advanced 6-DOF Testing Across Industries
- Why You Need a Hybrid Earthquake Early Warning System
- Transforming Indoor Golf with QL-GolfSim
- Related QuakeLogic products and technologies
- QuakeLogic Engineering Blog topic resources
References
Recommended Diagram or Download
Media placeholder: Add an original diagram showing the measurement chain from sensor or test platform to data acquisition, analysis, engineering interpretation, and reporting. Where this article becomes a buyer guide or application note, create a downloadable PDF version after engineering review.
Discuss a Monitoring or Testing Application
QuakeLogic supports seismic monitoring, earthquake early warning, structural health monitoring, infrasound monitoring, vibration monitoring, data acquisition, and shake table testing applications. For project-specific guidance, contact QuakeLogic with the asset type, measurement objective, site constraints, and required deliverables.


