def event2source(event, source_type='MT', rel_north_shift=0., rel_east_shift=0., **kwargs): ''' Convert pyrockos original event into seismosizer MT source. MT Source magnitude not scaled?! returns list of sources ''' rel_n_deg, rel_e_deg = du.lat_lon_relative_shift(event.lat, event.lon, rel_north_shift, rel_east_shift) if source_type=='MT': m = event.moment_tensor._m source_event = MTSource(lat=rel_n_deg, lon=rel_e_deg, depth=event.depth, time=event.time, mnn=float(m[0,0]), mee=float(m[1,1]), mdd=float(m[2,2]), mne=float(m[0,1]), mnd=float(m[0,2]), med=float(m[1,2])) elif source_type=='DC': try: s,d,r = kwargs['strike'], kwargs['dip'], kwargs['rake'] except KeyError: s,d,r = event.moment_tensor.both_strike_dip_rake()[0] m = event.moment_tensor.moment_magnitude source_event = DCSource(lat=rel_n_deg, lon=rel_e_deg, depth=event.depth, time=event.time, strike=s, dip=d, rake=r, magnitude=event.magnitude) elif source_type=='EX': m = event.moment_tensor.moment_magnitude source_event = ExplosionSource(lat=rel_n_deg, lon=rel_e_deg, depth=event.depth, time=event.time, magnitude=event.magnitude) else: raise Exception('invalid source type: %s'%source_type) source_event.regularize() return source_event
def __init__(self, markers, stations=None): # Targets================================================ store_id = 'castor' if store_id=='local1': phase_ids_start = 'p|P|Pv20p|Pv35p' phase_ids_end = 's|S|Sv20s|Sv35s' if store_id=='very_local': phase_ids_start = 'p|P|Pv3p|Pv8p|Pv20p|Pv35p' phase_ids_end = 's|S|Sv3s|Sv8s|Sv20s|Sv35s' if store_id=='very_local_20Hz': phase_ids_start = 'begin_fallback|p|P|Pv1p|Pv3p|Pv8p|Pv20p|Pv35p' phase_ids_end = 's|S|Sv1s|Sv3s|Sv8s|Sv20s|Sv35s' if store_id=='very_local_20Hz': phase_ids_start = 'begin_fallback|p|P|Pv1p|Pv3p|Pv8p|Pv20p|Pv35p' phase_ids_end = 's|S|Sv1s|Sv3s|Sv8s|Sv20s|Sv35s' if store_id=='castor': # bug?! bei Pv1.5p gibt's bei nahen Entfernungen ein index ot of # bounds phase_ids_start = 'p|P|Pv12.5p|Pv2.5p|Pv18.5p|Pv20p|Pv35p' phase_ids_end= 's|S|Sv12.5s|Sv2.5s|Sv18.5s|Sv20s|Sv35s' # Event================================================== event = filter(lambda x: isinstance(x, gui_util.EventMarker), markers) assert len(event) == 1 event = event[0].get_event() event.magnitude = 4.3 event.moment_tensor = moment_tensor.MomentTensor( m=num.array([[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])) # generate stations from olat, olon: if not stations: print 'Generating station distribution.' stations = du.station_distribution((event.lat,event.lon), [[10000., 4], [130000., 8]], rotate={3000.:45, 130000.:0}) targets = stations2targets(stations, store_id) derec_home = os.environ["DEREC_HOME"] store_dirs = [derec_home + '/fomostos'] engine = LocalEngine(store_superdirs=store_dirs) model = get_earthmodel_from_engine(engine, store_id) #TESTSOURCES=============================================== offset = 3*km zoffset= 1000. ref_source = event2source(event, 'DC', strike=37.3, dip=30, rake=-3) center_lat = ref_source.lat center_lon = ref_source.lon negative_lat_offset, negative_lon_offset = du.lat_lon_relative_shift( center_lat, center_lon, -offset, -offset) positive_lat_offset, positive_lon_offset = du.lat_lon_relative_shift( center_lat, center_lon, offset, offset) lats=num.linspace(negative_lat_offset, positive_lat_offset, 3) #lats = [ref_source.lat] lons=num.linspace(negative_lon_offset, positive_lon_offset, 3) #lons = [ref_source.lon] depths=num.linspace(ref_source.depth-zoffset, ref_source.depth+zoffset, 3) depths = [ref_source.depth] #strikes = num.linspace(ref_source.strike-90, ref_source.strike+90, 25) strikes = [ref_source.strike] #dips = num.linspace(ref_source.dip-45, ref_source.dip+45, 25) dips = [ref_source.dip] #rakes = num.linspace(ref_source.rake-180, ref_source.rake+180, 25) rakes = [ref_source.rake] print lats, '<- lats' print lons, '<- lons' print depths, '<- depths' print ref_source.lat, '<- event lat' print ref_source.lon, '<- event lon' print ref_source.depth, '<- event depth' print ref_source.strike, ref_source.dip, ref_source.rake, '<- event S D R' location_test_sources = [DCSource(lat=lat, lon=lon, depth=depth, time=event.time, strike=strike, dip=dip, rake=rake, magnitude=event.magnitude) for strike in strikes for dip in dips for rake in rakes for lat in lats for lon in lons for depth in depths] for s in location_test_sources: s.regularize() #========================================================== test_case = TestCase(location_test_sources, targets, engine, store_id, test_parameters={'lat':lats, 'lon':lons, 'depth':depths}) test_case.ref_source = ref_source test_case.request_data() print 'source location: ', test_case.ref_source reference_seismograms = make_reference_trace(test_case.ref_source, test_case.targets, engine) extended_ref_marker = du.chop_ranges(test_case.ref_source, test_case.targets, test_case.store, phase_ids_start, phase_ids_end) print('test data marker....') extended_test_marker = du.chop_ranges(test_case.sources, test_case.targets, test_case.store, phase_ids_start, phase_ids_end) test_case.test_markers = extended_test_marker test_case.ref_markers = extended_ref_marker print('chopping ref....') test_case.references = du.chop_using_markers( reference_seismograms.iter_results(), extended_ref_marker, t_shift_frac=0.1) print('chopping cand....') test_case.seismograms = du.chop_using_markers( test_case.response.iter_results(), extended_test_marker, t_shift_frac=0.1) norm = 2. #taper = trace.CosFader(xfade=4) # Seconds or samples? taper = trace.CosFader(xfrac=0.1) z, p, k = butter(4, (2.*num.pi*2. ,0.4*num.pi*2.) , 'bandpass', analog=True, output='zpk') z = num.array(z, dtype=complex) p = num.array(p, dtype=complex) k = num.complex(k) fresponse = trace.PoleZeroResponse(z,p,k) fresponse.regularize() setup = trace.MisfitSetup(norm=norm, taper=taper, domain='envelope', filter=fresponse) test_case.set_misfit_setup(setup) du.calculate_misfit(test_case) #test_case.yaml_dump() # Display results=================================================== #test_case.plot1d(order, event.lon) #test_case.contourf(xkey='lon', ykey='lat') test_case.check_plot({'lat':ref_source.lat, 'depth':ref_source.depth}) optics = OpticBase(test_case) #optics.plot_1d(fix_parameters={'lat':event.lat, 'lon':event.lon}) optics.gmt_map(stations=True, events=True)