def __dayplot_set_x_ticks(ax, starttime, endtime, sol=False): """ Sets the xticks for the dayplot. """ # day_break = endtime - float(endtime) % 86400 # day_break -= float(day_break) % 1 hour_ticks = [] ticklabels = [] interval = endtime - starttime interval_h = interval / 3600. ts = utct(starttime) tick_start = utct(ts.year, ts.month, ts.day, ts.hour) if 0 < interval <= 60: step = 10 elif 60 < interval <= 300: step = 30 elif 300 < interval <= 900: step = 120 elif 900 < interval <= 3600: step = 300 elif 3600 < interval <= 18000: step = 1800 elif 18000 < interval <= 43200: step = 3600 elif 43200 < interval <= 86400: step = 4 * 3600 elif 86400 < interval: step = 12 * 3600 step_h = step / 3600. # for ihour in np.arange(0, interval_h + step_h * 2, step_h): for ihour in np.arange(0, interval_h + 2 + step_h, step_h): hour_tick = tick_start + ihour * 3600. hour_ticks.append(hour_tick) if sol: ticklabels.append(utct(hour_tick).strftime('%H:%M:%S%nSol %j')) else: ticklabels.append(utct(hour_tick).strftime('%H:%M:%S%n%Y-%m-%d')) hour_ticks_minor = [] for ihour in np.arange(0, interval_h, 1): hour_tick = tick_start + ihour * 3600. hour_ticks_minor.append(hour_tick) ax.set_xticks(hour_ticks) ax.set_xticks(hour_ticks_minor, minor=True) ax.set_xticklabels(ticklabels) ax.set_xlim(float(starttime), float(endtime))
def __init__( self, or_time: utct = utct("2020-3-10T12:00:00"), lat_src: float = 10.99032013, lon_src: float = 170, lat_rec: float = 4.502384, lon_rec: float = 135.623447, depth: float = 45.0, name: str = "Test_Event", ): """ Create a seismic event :param rec_lat: latitude receiver :param rec_lon: longitude receiver """ self.event = Event() self.event.latitude = lat_src self.event.longitude = lon_src self.event.depth = depth self.event.name = name self.lat_rec = lat_rec self.lon_rec = lon_rec epi, az, baz = EventObj.Get_location( self.event.latitude, self.event.longitude, self.lat_rec, self.lon_rec ) self.event.distance = epi print(self.event.distance) self.event.az = az self.event.baz = baz self.event.origin_time = or_time
def add_picks(self, taup_model: TauPyModel, depth: float, phases: [str] = ["P", "S"]): self.event.picks = {} for phase in phases: self.event.picks[phase] = utct( self.event.origin_time + PhaseTracer.get_traveltime( model=taup_model, phase=phase, depth=depth, distance=self.event.distance ) )
def select_and_add(st, db_HF, db_LF, M, dist): winlen_hours = 4 tstart_total = float(st[0].stats.starttime) + 3600 tend_total = float(st[0].stats.endtime) - 3600 * (winlen_hours + 1) tstart_win = tstart_total + (tend_total - tstart_total) * np.random.rand(1) tend_win = tstart_win + 3600 * winlen_hours t0 = tstart_win + 600 + (tend_win - 4200 - tstart_win) * np.random.rand(1) st_LF = st.slice(starttime=utct(tstart_win - 1800), endtime=utct(tend_win + 1800)) st_HF = st.slice(starttime=utct(tstart_win - 1800), endtime=utct(tend_win + 1800)) st_HF.filter('highpass', freq=0.9) st_LF.filter('bandpass', freqmin=1./60, freqmax=1.2) st_LF.trim(starttime=utct(tstart_win), endtime=utct(tend_win)) st_HF.trim(starttime=utct(tstart_win), endtime=utct(tend_win)) src = instaseis.Source(latitude=90.0-dist, longitude=0.0, depth_in_m=1e3 + np.random.rand(1) * 2.9e4, m_rr=instaseis.source.magnitude2moment(M)[0] * np.sqrt(2.), origin_time=utct(t0) ) rec = instaseis.Receiver(latitude=90.0, longitude=0.0, network='XB', station='ELYSE', location='58') for db, flims in zip([db_HF, db_LF], [(1./10, 4.), (1./100., 1./10.)]): st_inst = db.get_seismograms(source=src, receiver=rec, kind='velocity', components='Z', dt=0.1) st_inst.trim(endtime=st_HF[0].stats.endtime-2) st_inst[0].stats.channel = 'BZC' #st_inst.filter('lowpass', freq=fmin) st_inst.filter('highpass', freq=flims[0]) st_inst.filter('lowpass', freq=flims[1]) i0 = int((st_inst[0].stats.starttime - st_LF[0].stats.starttime) * 10) for s in (st_LF, st_HF): s[0].data[i0:i0+len(st_inst[0].data)] += st_inst[0].data return st_LF, st_HF, t0
remote_folder="/data/", save_file_name=pjoin(save_folder, "event.mseed"), ) """ Specify receiver """ lat_rec = 4.5 # 02384 lon_rec = 135.623447 rec = instaseis.Receiver(latitude=lat_rec, longitude=lon_rec) for event in events: st = event.waveforms_VBB.copy() # epi, az, baz = _PreProcess.Get_location( # la_s=event.latitude, lo_s=event.longitude, la_r=rec.latitude, lo_r=rec.longitude # ) # st = st.rotate("NE->RT", back_azimuth=baz) P_arr = utct(event.picks["P"]) - utct(event.origin_time) + P_shift S_arr = utct(event.picks["S"]) - utct(event.origin_time) + S_shift """ Plot the waveforms and spectra """ fig, ax = plt.subplots(nrows=3, ncols=2, sharex="col", sharey="col", figsize=(15, 15)) for i, comp in enumerate(components): tr = st[i].copy() o_time = event.origin_time - tr.stats.starttime """ Plot the origin time, P and S arrivals """ ax[i, 0].axvline(x=0, c="gold", ls="dashed", label="Origin time") ax[i, 0].axvline(x=P_arr, c="red", ls="dashed", label="P-arrival") ax[i, 0].axvline(x=S_arr, c="blue", ls="dashed", label="S-arrival") """ Plot the original data in time-domain """
print(f"{event.name}, S:") print(event.picks["S"]) print(f"lat: {event.latitude}") print(f"lon: {event.longitude}") # For plot 3a: # fmin = 1.0 / 5.0 # 1. / 10.#1./8. # fmax = 1.0 / 2.5 # 1. / 2.#1./5. fmin = 0.2 fmax = 0.4 nphase = 2 # len(phases) arrs_real = [] for iphase in range(0, nphase): arrs_real.append( utct(event.picks[phases[iphase]]) - event.origin_time + corrs[iphase]) normfac = np.zeros(nphase) st_real = obspy.Stream() st_real_orig = obspy.Stream() st_sigma = obspy.Stream() normfac_phase = {"P": None, "S": None} LQT_value = False for iphase in range(nphase): # if source == 2: # if iphase == 1 or iphase == 2 or iphase == 4: # continue if components[iphase] in ["Z", "N", "E"]: tr_orig = event.waveforms_VBB.select(channel="BH" +
event_input = {event_name: []} event = DataGetter.read_events_from_cat( event_params=event_input, cat=cat, inv=inv, local_folder="/mnt/marshost/", host_name="marshost.ethz.ch", user_name="sysop", remote_folder="/data/", save_file_name=pjoin(folder, "event.mseed"), )[0] obs_tt = [] for i, phase in enumerate(phases): obs_tt.append( utct(event.picks[phase]) - event.origin_time + phase_corrs[i]) st_obs_full, sigmas_noise = _PreProcess.prepare_event_data( event=event, phases=phases, components=components, slice=False, tts=obs_tt, filter=False, noise_level=True, ) S = utct(event.picks["S"]) + phase_corrs[1] - utct(event.picks["P"]) st_obs_filt = obspy.Stream() st_obs_raw = obspy.Stream() st_obs_pre_noise = obspy.Stream()
Create_Vmod.create_dat_file( src_depth=depth, focal_mech=focal_mech0, M0=None, epi_in_km=epi_in_km, baz=baz, dt=dt, save_path=f_start, bm_file_path=bm_file, ) """ Create observed data array (for the moment all synthetic)""" event.waveforms_VBB.resample((1 / dt)) obs_tt = [] for i, phase in enumerate(phases): obs_tt.append( utct(event.picks[phase]) - event.origin_time + phase_corrs[i]) st_obs_w, _ = _PreProcess.prepare_event_data( event=event, phases=phases, components=comps, slice=True, tts=obs_tt, t_pre=t_pres, t_post=t_posts, filter=True, fmin=fmin, fmax=fmax, zerophase=zerophase, noise_level=False, ) st_obs_full, sigmas_noise = _PreProcess.prepare_event_data(