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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| import time import numpy as np import pandas as pd import matplotlib.pyplot as plt
import hvsrpy from hvsrpy import utils
data_h = np.loadtxt('x.txt') data_v = np.loadtxt('z.txt') dt = 1.e-3 sampling_rate = 1/dt
traceX = obspy.Trace(data=np.array(data_h[:]), header={'network': 'a', 'station': 'a', 'location': 'a', 'channel': 'BHE', 'sampling_rate': sampling_rate}) traceY = obspy.Trace(data=np.array(data_h[:]), header={'network': 'a', 'station': 'a', 'location': 'a', 'channel': 'BHN', 'sampling_rate': sampling_rate}) traceZ = obspy.Trace(data=np.array(data_v[:]), header={'network': 'a', 'station': 'a', 'location': 'a', 'channel': 'BHZ', 'sampling_rate': sampling_rate})
st = obspy.Stream([traceX, traceY, traceZ])
st.write('data_copy.mseed', format='MSEED')
file_name = 'data_copy.mseed' sensor = hvsrpy.Sensor3c.from_mseed(file_name)
file_name = 'data_copy.mseed'
windowlength = 60
filter_bool = False filter_flow = 0.1 filter_fhigh = 10 filter_order = 5
width = 0.1
bandwidth = 40
resample_fmin = 0.1
resample_fmax = 100
resample_fnum = 1000
resample_type = 'linear'
peak_f_lower = None peak_f_upper = None
method = "geometric-mean"
azimuth = 0
rejection_bool = True
n = 2
max_iterations = 50
distribution_f0 = "lognormal"
distribution_mc = "lognormal"
fig = plt.figure(figsize=(8, 4), dpi=150) ax = fig.add_subplot(1, 1, 1)
start = time.time() sensor = hvsrpy.Sensor3c.from_mseed(file_name) bp_filter = {"flag":filter_bool, "flow":filter_flow, "fhigh":filter_fhigh, "order":filter_order} resampling = {"minf":resample_fmin, "maxf":resample_fmax, "nf":resample_fnum, "res_type":resample_type} hv = sensor.hv(windowlength, bp_filter, width, bandwidth, resampling, method, f_low=peak_f_lower, f_high=peak_f_upper, azimuth=azimuth) end = time.time() print(f"Elapsed Time: {str(end-start)[0:4]} seconds")
individual_width = 0.3 median_width = 1.3 title="Before Rejection"
ax.plot(hv.frq, hv.mean_curve(distribution_mc), color='k', linewidth=median_width)
ax.set_xscale('log') ax.set_yscale('log')
ax.set_xlabel("Frequency (Hz)") ax.set_ylabel("HVSR Amplitude")
|