yzshi5 / GM-GANO

Codes for "Broadband Ground Motion Synthesis via Generative Adversarial Neural Operators: Development and Validation"s
4 stars 0 forks source link

question #4

Open mayang113 opened 5 months ago

mayang113 commented 5 months ago

屏幕截图 2024-04-19 191209 屏幕截图 2024-04-19 191235 屏幕截图 2024-04-19 191253 hello,is the issue occurring during baseline correction due to problems with my data?

yzshi5 commented 5 months ago

You can probably check the format of your data. Here is the pipeline for using the baseline correction

"""
given training waveforms : train_wfs after the preprocessing (bandpass filtered with the corner frequency) 
train_wfs (np.array): [N, 3, sampling_freq*duration], if there is only one record, the data shape should be [1, 3, sampling_freq*duration)
train_wfs should be the acceleration time history
"""

import numpy as np
import torch
from scipy.signal import detrend
import matplotlib.pyplot as plt
# load the baseline correction function
import pylib_gm_proc
from pylib_gm_proc import TaperingTH, NewmarkIntegation, FDDifferentiate, BaselineCorrection
from scipy.signal import detrend

# step 1: 

train_wfs = detrend(train_wfs, type='linear')
train_wfs = detrend(train_wfs, tpe='constant')

# step 2:
def baseline_correction(time,wfs_scen):
    """
    Baseline correction method, apply a 7-order polynominal function to fit the daa to forces the motion (acc, vel, disp) to stop at the end. 
    """
    wfs_scen_corrected = np.zeros_like(wfs_scen)

    for i in range(len(wfs_scen)):
        for j in range(3):
            _, _, vel_nm, disp_nm = NewmarkIntegation(time, wfs_scen[i,j,:], int_type='midle point')
            _, acc_bs, vel_bs, disp_bs = BaselineCorrection(time, vel_nm, disp_nm, n=7, f_taper_beg=0.05, f_taper_end=0.05)
            wfs_scen_corrected[i,j,:] = acc_bs

    return wfs_scen_corrected

# step 3:
ndim = 6000 # resolution of the time history
time_step = 0.01 # when sampling frequency is 100Hz
times = np.arange(ndim) * time_step

train_wfs_corrected = baseline_correction(times, train_wfs)