def main(): # Read acceleration data. If you want velocity units='vel', # Cdisplacement units='disp' data_dir = '/Users/tnye/PROJECTS/Duration/data/ci3144585/ground_motion' files = [ '1994.c.017m30su.n0a', '1994.c.017m30su.n0b', '1994.c.017m30su.n0c' ] files = [os.path.join(data_dir, f) for f in files] stream = Stream() # Data for the trace we are working with # There are 3 traces (0, 1, 2), and i denotes trace we are working with for i in range(len(files)): cmp = processing.read_data(files[i], units='acc')[0] stream.append(cmp) durations = [(0.05, 0.75), (0.2, 0.8), (0.05, .95)] # Plots each boundary on the Norm Arias Intensity graph f, axes = plt.subplots(len(durations), 1, sharex=True, figsize=(6.5, 7.5)) for i, trace in enumerate(stream): # Convert acceleration to m/s/s acc = np.multiply(0.01, trace.data) channel = trace.stats['channel'] dt = trace.stats.delta Ia, NIa = arias_intensity.get_arias_intensity(acc, dt, 0) print("Arias Intensity (%s): %f" % (channel, np.amax(Ia))) if i == 2: xlab = True else: xlab = False arias_intensity.plot_durations(NIa, dt, durations, axes[i], xlab) axes[i].set_title(channel) plt.savefig('/Users/tnye/PROJECTS/Duration/figures/Afshari_Fig_1_tnye.png', dpi=300)
def get_RotComp_Arias(station, dt, starttime): """ Calculates the rotational independent components of Ia and CAV: geometric mean, arithmetic mean, and max of two horizontal components. Args: station (stream): Stream of 3 traces of acceleration data for a station. dt (flaot): Time in between each sample taken (s). starttime (float): Time in s, after start of record, to start integrating. Usually P-wave arrival time or 0 for full record. Returns: Ia_geom (float): Geometric mean of station's Arias intensity. Ia_arith (float): Arithmetic mean of station's Arias intensity. Ia_max (flaot): Max Arias intensity of the two horizontal components. """ # Calculate Arias intensity. for i in range(len(station)): trace = station[i] Ia, NIa = arias_intensity.get_arias_intensity( np.multiply(trace.data, 0.01), trace.stats.delta, starttime) trace.stats.Ia = np.amax(Ia) # Calculate geometric mean. Ia_geom = (math.sqrt(station[0].stats['Ia'] * station[2].stats['Ia'])) # Calculate arithmetic mean. Ia_arith = ((station[0].stats['Ia'] + station[2].stats['Ia']) / 2) # Calculate max horizontal component. for i in range(len(station)): if station[0].stats.Ia > station[2].stats.Ia: Ia_max = station[0].stats.Ia else: Ia_max = station[2].stats.Ia return (Ia_geom, Ia_arith, Ia_max)
event_id, date, mag, source_lat, source_lon, depth = calc_eq_data.get_earthquake_data( 'usp000fg9t', stations) # Add distance and P_wave arrival times to stats. calc_eq_data.get_dist_and_parrivals(stations, station_stats, source_lat, source_lon, depth) # Calc Arias intensity and add to stats. dt = 0.01 for sta in stations: for i in range(len(sta)): trace = sta[i] starttime = trace.stats.P_arriv acc = np.multiply(0.01, trace.data) Ia, NIa, = arias_intensity.get_arias_intensity(acc, 0.01, 0) newIa, newNIa = arias_intensity.get_arias_intensity(acc, 0.01, starttime) trace.stats.Ia = Ia trace.stats.NIa = NIa trace.stats.maxIa = np.amax(Ia) trace.stats.PIa = newIa trace.stats.PNIa = newNIa trace.stats.maxPIa = np.amax(newIa) time1 = arias_intensity.get_time_from_percent(NIa, 0.05, dt) time2 = arias_intensity.get_time_from_percent(NIa, 0.95, dt) trace.stats.arias5 = time1 trace.stats.arias95 = time2 # Gather all NS components into one stream and sort by dsit
""" Created on Wed Jun 27 16:36:52 2018 @author: tnye """ # Third party imports import numpy as np from amptools.io.dmg.core import read_dmg # Local imports import arias_intensity stream1 = read_dmg('/Users/tnye/PROJECTS/Duration/data/events/loma_prieta/GILROY1.V2') stream2 = read_dmg('/Users/tnye/PROJECTS/Duration/data/events/loma_prieta/GILROY2.V2') print("Arias Gilroy 1") for trace in stream1: acc = np.multiply(0.01, trace.data) channel = trace.stats.channel Ia, NIa = arias_intensity.get_arias_intensity(acc, trace.stats['delta'], 0) print(channel, np.amax(Ia)) print("Arias Gilroy 2") for trace in stream2: acc = np.multiply(0.01, trace.data) channel = trace.stats.channel Ia, NIa = arias_intensity.get_arias_intensity(acc, trace.stats['delta'], 0) print(channel, np.amax(Ia))
timelist = timevals.reshape(1, -1) times = [] for x in timelist: for y in x: times.append(y) hcomp = Stream() for sta in stations: newtrace = sta.select(channel='NS') hcomp += newtrace ratios = [] dist = [] for i in range(len(hcomp)): trace = hcomp[i] dt = trace.stats.delta acc = np.multiply(0.01, trace.data) Ia, NIa, = arias_intensity.get_arias_intensity(acc, dt, 0) newIa, newNIa = arias_intensity.get_arias_intensity(acc, dt, times[i]) trace.stats.Ia = np.amax(Ia) trace.stats.pIa = np.amax(newIa) ratio = (trace.stats.pIa / trace.stats.Ia) trace.stats.ratio = ratio ratios.append(ratio) dist.append(trace.stats.distkm) fig = plt.figure(figsize=(5, 4)) ax = fig.add_subplot(111) plt.ylim(0, 1.02) plt.scatter(dist, ratios, s=20, c='k') plt.ylabel('Arias w P-arriv : Arias') plt.xlabel('Dist km') plt.title('usp000a1b0') plt.savefig('/Users/tnye/PROJECTS/Duration/figures/small_quake_arias.png',