def __init__(self, ses3d_seismogram): #inherit information from instance of ses3d_seismogram() self.ses3d_seismogram = ses3d_seismogram self.eq_depth = ses3d_seismogram.sz/1000.0 #initialize receiver function specific information dist_az = gps2dist_azimuth((90.0-self.ses3d_seismogram.rx), self.ses3d_seismogram.ry, (90.0-self.ses3d_seismogram.sx), self.ses3d_seismogram.sy, a = 6371000.0, f = 0.0) self.back_az = dist_az[1] self.az = dist_az[2] self.delta_deg = kilometer2degrees(dist_az[0]/1000.0) self.time = np.zeros(100) self.prf = np.zeros(100) self.srf = np.zeros(100) self.r = np.zeros(100) self.t = np.zeros(100) self.z = np.zeros(100) self.slowness = 0.0 self.pierce_dict = [] self.window_start = 0.0 self.window_end = 0.0
def __init__(self, ses3d_seismogram): #inherit information from instance of ses3d_seismogram() self.ses3d_seismogram = ses3d_seismogram self.eq_depth = ses3d_seismogram.sz / 1000.0 #initialize receiver function specific information dist_az = gps2dist_azimuth((90.0 - self.ses3d_seismogram.rx), self.ses3d_seismogram.ry, (90.0 - self.ses3d_seismogram.sx), self.ses3d_seismogram.sy, a=6371000.0, f=0.0) self.back_az = dist_az[1] self.az = dist_az[2] self.delta_deg = kilometer2degrees(dist_az[0] / 1000.0) self.time = np.zeros(100) self.prf = np.zeros(100) self.srf = np.zeros(100) self.r = np.zeros(100) self.t = np.zeros(100) self.z = np.zeros(100) self.slowness = 0.0 self.pierce_dict = [] self.window_start = 0.0 self.window_end = 0.0
def get_event_params(eq_lat, eq_lon): dist_az = gps2dist_azimuth(eq_lat, eq_lon, 0, 0, a=6371000.0, f=0.0) dist_km = dist_az[0] / 1000.0 dist_deg = kilometer2degrees(dist_km) az = dist_az[1] baz = dist_az[2] rotation_angle = -1.0 * ((baz - 180) - 90.0) #rotation_angle = -1.0*(az-90.0) return dist_deg, rotation_angle
#plot experiment geometry-------------------------------------------------------- ff_tomo.plot_geo_config(stations=stations, events=events) #write input files--------------------------------------------------------------- ievt = 1 #event number nP = 0 #number of P observations nS = 0 #number of S observations nSKS = 0 #number of SKS observations for event in events: ievt = event[0] eq_lon = event[1] eq_lat = event[2] eq_dep = event[3] dist_az = gps2dist_azimuth(eq_lat, eq_lon, 0, 0, a=6371000.0, f=0.0) event_dist_deg = kilometer2degrees((dist_az[0] / 1000.0)) for phase in param_dict['phases_list']: if phase == 'SKS': if event_dist_deg < 70.0 or event_dist_deg > 120.0: print 'skipping event for phase SKS at distance', event_dist_deg continue else: nSKS += 1 filename = '{}_{}'.format(param_dict['run_name'] + '.SKS', nSKS) elif phase == 'S': if event_dist_deg < 30.0 or event_dist_deg > 90.0: print 'skipping event for phase ', phase, 'at distance', event_dist_deg
def make_earthquake_list(param_dict, **kwargs): ''' Generate earthquakes to be used in tomographic inversion. Earthquake locations can be generated randomly within the distance range (deltamin, deltamax), or alternatively a ring of earthquakes at a fixed distance from the point (0,0) can be generated. In the futures, events may be given as an obspy event catalog. args-------------------------------------------------------------------------- param_dict: parameter dictionary (read from file 'inparam_tomo') kwargs------------------------------------------------------------------------ nevents: number of earthquakes (only use if geometry is 'random') deltamin = minimum earthquake distance from (0,0) (only if geometry is 'random') deltamax = maximum earthquake distance from (0,0) (only if geometry is 'random') ringdist = distance of ring from (0,0). Can be tuple for multiple rings. (only if geometry is 'ring') dtheta = spacing between earthquakes in ring, given in degrees. Default = 30. ''' geometry = param_dict['event_geometry'] nevents = param_dict['nevents'] depth = param_dict['depth'] deltamin = param_dict['deltamin'] deltamax = param_dict['deltamax'] ringdist = param_dict['ringdist'] dtheta = param_dict['dtheta'] lat0 = kwargs.get('lat0', 0.0) lon0 = kwargs.get('lon0', 0.0) eq_list = [] n = 1 if geometry == 'random': while len(eq_list) < nevents: lon = (2.0 * deltamax * np.random.random(1)) - deltamax lat = (2.0 * deltamax * np.random.random(1)) - deltamax dist_az = gps2dist_azimuth(lat, lon, lat0, lon0, a=6371000.0, f=0.0) dist_km = dist_az[0] / 1000.0 dist_deg = kilometer2degrees(dist_km) if dist_deg >= deltamin and dist_deg <= deltamax: eq_list.append((n, lon[0], lat[0], depth)) n += 1 elif geometry == 'ring': theta = np.arange(0, 360, dtheta) origin = geopy.Point(0, 0) eq_list = [] if type(ringdist) == int or type(ringdist) == float: d_km = ringdist * ((6371.0 * 2 * np.pi) / 360.0) for i in range(0, len(theta)): bearing = theta[i] destination = VincentyDistance(kilometers=d_km).destination( origin, bearing) lat = destination[0] lon = destination[1] eq_list.append((n, lon, lat, depth)) n += 1 elif type(ringdist == tuple): for r in ringdist: d_km = r * ((6371.0 * 2 * np.pi) / 360.0) for i in range(0, len(theta)): bearing = theta[i] destination = VincentyDistance( kilometers=d_km).destination(origin, bearing) lat = destination[0] lon = destination[1] eq_list.append((n, lon, lat, depth)) n += 1 np.savetxt('earthquake_list', eq_list, fmt=['%d', '%5.5f', '%5.5f', '%5.5f']) return eq_list
def write_input(eq_lat, eq_lon, eq_dep, ievt, stations, phase, delays_file, Tmin, taup_model, filename, raytheory=False, tt_from_raydata=True, **kwargs): ''' write an input file for globalseis finite frequency tomography software. each earthquake and datatype (P,S,etc...) has it's own input file args-------------------------------------------------------------------------- eq_lat: earthquake latitude (deg) eq_lon: earthquake longitude (deg) eq_dep: earthquake depth (km) stations: stations array (lons,lats) delays_file: h5py datafile containing cross correlation delay times Tmin: minimum period at which cross correlation measurements were made taup_model: name of TauPyModel used to calculate 1D travel times filename: raytheory: True or False tt_from_raydata: If True, writes cross correlation times to 'xcor*', which will then be added to 1D travel times from raydata kwargs------------------------------------------------------------------------ plot_figure: plot a figure showing source receiver geometry and delay map t_sig: estimated standard error in cross correlation measurement. add_noise: add gaussian noise to traveltime measurements of magnitude t_sig fake_SKS_header: test the SKS header ''' #define variables used in finite frequency tomography (kwargs)---------------- idate = kwargs.get( 'idate', '15001') #event date YYDDD where DDD is between 1 and 365 iotime = kwargs.get('iotime', '010101') #vent origin time (HHMMSS) kluster = kwargs.get('kluster', '0') #0 if no clustering used stationcode = kwargs.get('stationcode', 'XXXX') #station code (no more than 16 chars) netw = kwargs.get('netw', 'PLUMENET ') #network code nobst = kwargs.get('nobst', '1') #number of travel time measurements nobsa = kwargs.get('nobsa', '0') #number of amplitude measurements kpole = kwargs.get('kpole', '0') #number of polar crossings (0 for P and S) sampling_rate = kwargs.get('sampling_rate', 20.0) n_bands = kwargs.get('n_bands', 1) # spectral bands used (TODO setup more than one) kunit = kwargs.get('kunit', 1) #unit of noise (1 = nm) rms0 = kwargs.get('rms0', 0) #don't know what this is plot_figure = kwargs.get('plot_figure', False) dist_min = kwargs.get('dist_min', 30.0) dist_max = kwargs.get('dist_max', 90.0) t_sig = kwargs.get('t_sig', 0.0) add_noise = kwargs.get('add_noise', False) fake_SKS_header = kwargs.get('fake_SKS_header', False) ievt = int( ievt ) #double check ievt is an integer (in case it was read from a file) debug = False #create taup model------------------------------------------------------------ tt_model = TauPyModel(taup_model) #get filter parameters-------------------------------------------------------- print 'Tmin = ', Tmin filter_type, freqmin, freqmax, window = get_filter_params( delays_file, phase, Tmin) omega, amp = get_filter_freqs(filter_type, freqmin, freqmax, sampling_rate) window_len = window[1] - window[0] #write header----------------------------------------------------------------- f = open(filename, 'w') f.write('{}'.format(filename) + '\n') f.write('{}'.format('None' + '\n')) fdelays = open('xcor_{}'.format(filename), 'w') #ray information-------------------------------------------------------------- if phase == 'P': gm_component = 'BHZ ' #ground motion component f.write('P' + '\n') f.write('P' + '\n') f.write('6371 1 1' + '\n') f.write('3482 2 1' + '\n') f.write('6371 5 0' + '\n') elif phase == 'S' and fake_SKS_header == False: gm_component = 'BHT ' #ground motion component f.write('S' + '\n') f.write('S' + '\n') f.write('6371 1 2' + '\n') f.write('3482 2 2' + '\n') f.write('6371 5 0' + '\n') elif phase == 'SKS' or fake_SKS_header == True: gm_component = 'BHR ' #ground motion component f.write('SKS' + '\n') f.write('SKS' + '\n') f.write('6371 1 2' + '\n') f.write('3482 4 1' + '\n') f.write('1217.1 2 1' + '\n') f.write('3482 4 2' + '\n') f.write('6371 5 0' + '\n') #this is hardwired for now (based on range of rays found with ray tracing software) #TODO make distance range more adaptable if phase == 'P': dist_min = 30.0 #dist_max = 98.3859100 dist_max = 97.0 elif phase == 'S': dist_min = 30.0 #dist_max = 99.0557175 dist_max = 97.0 elif phase == 'SKS': #dist_min = 66.0320663 #dist_max = 144.349365 dist_min = 68.0 dist_max = 142.0 #write spectral band information----------------------------------------------- if raytheory: n_bands = 0 f.write('{}'.format(n_bands) + '\n') else: f.write('{}'.format(n_bands) + '\n') f.write('{}'.format(len(omega)) + '\n') for i in range(0, len(omega)): f.write('{} {}'.format(omega[i], amp[i]) + '\n') #event delay map-------------------------------------------------------------- #lats_i = np.arange(-30.0,30.0,0.1) #lons_i = np.arange(-30.0,30.0,0.1) lats_i = np.arange(-45.0, 45.0, 0.1) lons_i = np.arange(-45.0, 45.0, 0.1) if plot_figure: event_map, figure_axis = make_event_delay_map(eq_lat, eq_lon, phase, delays_file, Tmin, lats_i=lats_i, lons_i=lons_i, plot=True, return_axis=False, nevent=ievt) else: if debug: print 'func:write_input- making event delay map for', phase #print 'eq_lat,eq_lon,phase,Tmin lats_i,lons_i',eq_lat,eq_lon,phase,Tmin,lats_i,lons_i event_map = make_event_delay_map(eq_lat, eq_lon, phase, delays_file, Tmin, lats_i=lats_i, lons_i=lons_i, return_axis=False, plot=True, nevent=ievt) #find delays at stations------------------------------------------------------ if plot_figure: station_delays = get_station_delays(event_map, stations, lats_i, lons_i, pass_figure_axis=True, figure_axis=figure_axis) else: station_delays = get_station_delays(event_map, stations, lats_i, lons_i) #add noise (optional)--------------------------------------------------------- if t_sig != 0: noise = np.random.normal(0, t_sig, len(station_delays)) if add_noise: station_delays += noise station_lons = stations[0, :] station_lats = stations[1, :] n_stations = len(station_lats) station_elevation = 0.0 for i in range(0, n_stations): dist_deg, rotation_angle = get_event_params(eq_lat, eq_lon) #find event distance event_distaz = gps2dist_azimuth(eq_lat, eq_lon, station_lats[i], station_lons[i], a=6371000.0, f=0.0) event_dist_deg = kilometer2degrees((event_distaz[0] / 1000.0)) #skip station if too close or too far from source if event_dist_deg <= dist_min or event_dist_deg >= dist_max: continue #get ray theoretical travel time #if phase == 'S': # phase_list = ['s','S','Sdiff'] #elif phase == 'P': # phase_list = ['p','P','Pdiff'] ray_theory_arr = tt_model.get_travel_times(eq_dep, event_dist_deg, phase_list=[phase]) if debug: print '_________________________________________________________________________________' print 'arrivals from taup_get_travel_time for event parameters [depth,delta(deg),phase]:' print '[{},{},{}]'.format(eq_dep, event_dist_deg, phase), ray_theory_arr print '_________________________________________________________________________________' ray_theory_travel_time = ray_theory_arr[0].time delay_time = station_delays[i] tobs = ray_theory_travel_time - delay_time if debug: print 'distance, phase, raytheory travel time, observed delay:', event_dist_deg, phase, ray_theory_travel_time, delay_time print 'the travel time observation is ', tobs fdelays.write('{}'.format(delay_time) + '\n') if raytheory: n_bands = 0 nbt = 0 #spectral band number (must be 0 if ray theory) window_len = 0 kunit = 0 corcoeft = 0 else: nbt = 1 #spectral band number #write line 1-------------------------------------------------------------- f.write('{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}'.format( idate, iotime, ievt, kluster, stationcode, netw, gm_component, eq_lat, eq_lon, eq_dep, station_lats[i], station_lons[i], station_elevation, nobst, nobsa, kpole) + '\n') #write line 2-------------------------------------------------------------- f.write('{} {} '.format(kunit, rms0)) for j in range(0, n_bands + 1): f.write('0') #used to be 0.0 f.write('\n') #write line 3--------------------------------------------------------------- if raytheory: f.write('{}'.format(1) + '\n') else: f.write('{}'.format(n_bands) + '\n') #write line 4--------------------------------------------------------------- corcoeft = 1.0 # cross correlation coefficient f.write( '{} {} {} {} {} {}'.format(tobs, t_sig, corcoeft, nbt, window_len, '#tobs,tsig,corcoeft,nbt,window') + '\n') #write line 5-------------------------------------------------------------- f.write('{}'.format(0) + '\n')