Skip to content

Instantly share code, notes, and snippets.

@terjehaukaas
Last active April 2, 2024 02:25
Show Gist options
  • Save terjehaukaas/b64d9e957620c9f327541ea0b2c5f330 to your computer and use it in GitHub Desktop.
Save terjehaukaas/b64d9e957620c9f327541ea0b2c5f330 to your computer and use it in GitHub Desktop.
Read PEER Record
import numpy as np
import os
def readPEERrecord(f):
rawGroundMotion = []
dt = 0
file = open(f, "r")
lines = file.readlines()
lineNumber = 0
for oneline in lines:
lineNumber += 1
if lineNumber == 1:
pass
elif lineNumber == 2:
record = oneline
elif lineNumber == 3:
splitline = oneline.split()
for j in range(len(splitline)):
if splitline[j] == 'UNITS':
unit = str(splitline[j+2])
if unit != 'G':
print("Error: This ground motion record is not in units of G")
import sys
sys.exit()
elif lineNumber == 4:
splitline = oneline.split()
for j in range(len(splitline)):
if splitline[j] == 'DT=':
dt = float(splitline[j+1])
else:
splitline = oneline.split()
for j in range(len(splitline)):
value = float(splitline[j])
rawGroundMotion.append(value)
recordName = record.strip()
print('\n'"%s has duration=%.2f, dt=%.4f, PGA=%.2f%s" % (recordName, dt*len(rawGroundMotion), dt, np.max(np.abs(rawGroundMotion)), unit))
return dt, rawGroundMotion, recordName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment