def _draw_basefeatures(self): gmt = self._gmt cres = self._coastline_resolution rivers = self._rivers minarea = self._minarea color_wet = self.color_wet color_dry = self.color_dry if self.show_rivers and rivers: rivers = ["-Ir/0.25p,%s" % gmtpy.color(self.color_wet)] else: rivers = [] fill = {} if not self._have_topo_land: fill["G"] = color_dry if not self._have_topo_ocean: fill["S"] = color_wet gmt.pscoast( D=cres, W="thinnest,%s" % gmtpy.color(darken(gmtpy.color_tup(color_dry))), A=minarea, *(rivers + self._jxyr), **fill )
def _draw_basefeatures(self): gmt = self._gmt cres = self._coastline_resolution rivers = self._rivers minarea = self._minarea color_wet = self.color_wet color_dry = self.color_dry if self.show_rivers and rivers: rivers = ['-Ir/0.25p,%s' % gmtpy.color(self.color_wet)] else: rivers = [] fill = {} if not self._have_topo_land: fill['G'] = color_dry if not self._have_topo_ocean: fill['S'] = color_wet gmt.pscoast(D=cres, W='thinnest,%s' % gmtpy.color(darken(gmtpy.color_tup(color_dry))), A=minarea, *(rivers + self._jxyr), **fill)
def test_simple(self): x = num.linspace(0., 2 * math.pi) y = num.sin(x) y2 = num.cos(x) for version in gmtpy.all_installed_gmt_versions(): for ymode in ['off', 'symmetric', 'min-max', 'min-0', '0-max']: plot = gmtpy.Simple(gmtversion=version, ymode=ymode) plot.plot((x, y), '-W1p,%s' % gmtpy.color('skyblue2')) plot.plot( (x, y2), '-W1p,%s' % gmtpy.color(gmtpy.color_tup('scarletred2'))) plot.text((3., 0.5, 'hello'), size=20.) fname = 'gmtpy_test_simple_%s.png' % ymode fpath = self.fpath(fname) plot.save(fpath) self.compare_with_ref(fname, 0.01, show=False)
# Load events from catalog file (generated using catalog.GlobalCMT() # download from www.globalcmt.org) # If no moment tensor is provided in the catalogue, the event is plotted # as a red circle. Symbol size relative to magnitude. events = model.load_events('deadsea_events_1976-2017.txt') beachball_symbol = 'd' factor_symbl_size = 5.0 for ev in events: mag = ev.magnitude if ev.moment_tensor is None: ev_symb = 'c' + str(mag * factor_symbl_size) + 'p' m.gmt.psxy(in_rows=[[ev.lon, ev.lat]], S=ev_symb, G=gmtpy.color('scarletred2'), W='1p,black', *m.jxyr) else: devi = ev.moment_tensor.deviatoric() beachball_size = mag * factor_symbl_size mt = devi.m_up_south_east() mt = mt / ev.moment_tensor.scalar_moment() \ * pmt.magnitude_to_moment(5.0) m6 = pmt.to6(mt) data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0) if m.gmt.is_gmt5(): kwargs = dict(M=True, S='%s%g' % (beachball_symbol[0], (beachball_size) / gmtpy.cm))
def main(args=None): if args is None: args = sys.argv[1:] parser = OptionParser( usage=usage, description=description) parser.add_option( '--width', dest='width', type='float', default=20.0, metavar='FLOAT', help='set width of output image [cm] (%default)') parser.add_option( '--height', dest='height', type='float', default=15.0, metavar='FLOAT', help='set height of output image [cm] (%default)') parser.add_option( '--topo-resolution-min', dest='topo_resolution_min', type='float', default=40.0, metavar='FLOAT', help='minimum resolution of topography [dpi] (%default)') parser.add_option( '--topo-resolution-max', dest='topo_resolution_max', type='float', default=200.0, metavar='FLOAT', help='maximum resolution of topography [dpi] (%default)') parser.add_option( '--no-grid', dest='show_grid', default=True, action='store_false', help='don\'t show grid lines') parser.add_option( '--no-topo', dest='show_topo', default=True, action='store_false', help='don\'t show topography') parser.add_option( '--no-cities', dest='show_cities', default=True, action='store_false', help='don\'t show cities') parser.add_option( '--no-illuminate', dest='illuminate', default=True, action='store_false', help='deactivate artificial illumination of topography') parser.add_option( '--illuminate-factor-land', dest='illuminate_factor_land', type='float', metavar='FLOAT', help='set factor for artificial illumination of land (0.5)') parser.add_option( '--illuminate-factor-ocean', dest='illuminate_factor_ocean', type='float', metavar='FLOAT', help='set factor for artificial illumination of ocean (0.25)') parser.add_option( '--theme', choices=['topo', 'soft'], default='topo', help='select color theme, available: topo, soft (topo)"') parser.add_option( '--download-etopo1', dest='download_etopo1', action='store_true', help='download full ETOPO1 topography dataset') parser.add_option( '--download-srtmgl3', dest='download_srtmgl3', action='store_true', help='download full SRTMGL3 topography dataset') parser.add_option( '--make-decimated-topo', dest='make_decimated', action='store_true', help='pre-make all decimated topography datasets') parser.add_option( '--stations', dest='stations_fn', metavar='FILENAME', help='load station coordinates from FILENAME') parser.add_option( '--events', dest='events_fn', metavar='FILENAME', help='load event coordinates from FILENAME') parser.add_option( '--debug', dest='debug', action='store_true', default=False, help='print debugging information to stderr') (options, args) = parser.parse_args(args) if options.debug: util.setup_logging(program_name, 'debug') else: util.setup_logging(program_name, 'info') if options.download_etopo1: import pyrocko.datasets.topo.etopo1 pyrocko.datasets.topo.etopo1.download() if options.download_srtmgl3: import pyrocko.datasets.topo.srtmgl3 pyrocko.datasets.topo.srtmgl3.download() if options.make_decimated: import pyrocko.datasets.topo pyrocko.datasets.topo.make_all_missing_decimated() if (options.download_etopo1 or options.download_srtmgl3 or options.make_decimated) and len(args) == 0: sys.exit(0) if options.theme == 'soft': color_kwargs = { 'illuminate_factor_land': options.illuminate_factor_land or 0.2, 'illuminate_factor_ocean': options.illuminate_factor_ocean or 0.15, 'color_wet': (216, 242, 254), 'color_dry': (238, 236, 230), 'topo_cpt_wet': 'light_sea_uniform', 'topo_cpt_dry': 'light_land_uniform'} elif options.theme == 'topo': color_kwargs = { 'illuminate_factor_land': options.illuminate_factor_land or 0.5, 'illuminate_factor_ocean': options.illuminate_factor_ocean or 0.25} events = [] if options.events_fn: events = model.load_events(options.events_fn) stations = [] if options.stations_fn: stations = model.load_stations(options.stations_fn) if not (len(args) == 4 or ( len(args) == 1 and (events or stations))): parser.print_help() sys.exit(1) if len(args) == 4: try: lat = float(args[0]) lon = float(args[1]) radius = float(args[2])*km except Exception: parser.print_help() sys.exit(1) else: lats, lons = latlon_arrays(stations+events) lat, lon = map(float, od.geographic_midpoint(lats, lons)) radius = float( num.max(od.distance_accurate50m_numpy(lat, lon, lats, lons))) radius *= 1.1 m = automap.Map( width=options.width, height=options.height, lat=lat, lon=lon, radius=radius, topo_resolution_max=options.topo_resolution_max, topo_resolution_min=options.topo_resolution_min, show_topo=options.show_topo, show_grid=options.show_grid, illuminate=options.illuminate, **color_kwargs) logger.debug('map configuration:\n%s' % str(m)) if options.show_cities: m.draw_cities() if stations: lats = [s.lat for s in stations] lons = [s.lon for s in stations] m.gmt.psxy( in_columns=(lons, lats), S='t8p', G='black', *m.jxyr) for s in stations: m.add_label(s.lat, s.lon, '%s' % '.'.join( x for x in s.nsl() if x)) if events: beachball_symbol = 'mt' beachball_size = 20.0 for ev in events: if ev.moment_tensor is None: m.gmt.psxy( in_rows=[[ev.lon, ev.lat]], S='c12p', G=gmtpy.color('scarletred2'), W='1p,black', *m.jxyr) else: devi = ev.moment_tensor.deviatoric() mt = devi.m_up_south_east() mt = mt / ev.moment_tensor.scalar_moment() \ * pmt.magnitude_to_moment(5.0) m6 = pmt.to6(mt) data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0) if m.gmt.is_gmt5(): kwargs = dict( M=True, S='%s%g' % ( beachball_symbol[0], beachball_size / gmtpy.cm)) else: kwargs = dict( S='%s%g' % ( beachball_symbol[0], beachball_size*2 / gmtpy.cm)) m.gmt.psmeca( in_rows=[data], G=gmtpy.color('chocolate1'), E='white', W='1p,%s' % gmtpy.color('chocolate3'), *m.jxyr, **kwargs) m.save(args[-1])
def bandpass(t): t.bandpass(4, 0.1, 5.) def lowpass_highpass(t): t.lowpass(4, 5.) t.highpass(4, 0.1) def bandpass_fft(t): t.bandpass_fft(0.1, 5.) tab = [] for n in range(1, 22): a = timeit(lambda: bandpass(mktrace(2**n))) b = timeit(lambda: lowpass_highpass(mktrace(2**n))) c = timeit(lambda: bandpass_fft(mktrace(2**n))) print(2**n, a, b, c) tab.append((2**n, a, b, c)) a = num.array(tab).T p = gmtpy.Simple() for i in range(1, 4): p.plot((a[0], a[i]), '-W1p,%s' % gmtpy.color(i)) p.save('speed_filtering.pdf')
def plot_map(stations, center, events=None, savename=None): from pyrocko.plot.automap import Map from pyrocko.example import get_example_data from pyrocko import model, gmtpy from pyrocko import moment_tensor as pmt gmtpy.check_have_gmt() # Generate the basic map m = Map(lat=center[0], lon=center[1], radius=150000., width=30., height=30., show_grid=False, show_topo=True, color_dry=(238, 236, 230), topo_cpt_wet='light_sea_uniform', topo_cpt_dry='light_land_uniform', illuminate=True, illuminate_factor_ocean=0.15, show_rivers=False, show_plates=False) # Draw some larger cities covered by the map area m.draw_cities() # Generate with latitute, longitude and labels of the stations lats = [s.lat for s in stations] lons = [s.lon for s in stations] labels = ['.'.join(s.nsl()) for s in stations] # Stations as black triangles. m.gmt.psxy(in_columns=(lons, lats), S='t20p', G='black', *m.jxyr) # Station labels for i in range(len(stations)): m.add_label(lats[i], lons[i], labels[i]) beachball_symbol = 'd' factor_symbl_size = 5.0 if events is not None: for ev in events: mag = ev.magnitude if ev.moment_tensor is None: ev_symb = 'c' + str(mag * factor_symbl_size) + 'p' m.gmt.psxy(in_rows=[[ev.lon, ev.lat]], S=ev_symb, G=gmtpy.color('scarletred2'), W='1p,black', *m.jxyr) else: devi = ev.moment_tensor.deviatoric() beachball_size = mag * factor_symbl_size mt = devi.m_up_south_east() mt = mt / ev.moment_tensor.scalar_moment() \ * pmt.magnitude_to_moment(5.0) m6 = pmt.to6(mt) data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0) if m.gmt.is_gmt5(): kwargs = dict(M=True, S='%s%g' % (beachball_symbol[0], (beachball_size) / gmtpy.cm)) else: kwargs = dict(S='%s%g' % (beachball_symbol[0], (beachball_size) * 2 / gmtpy.cm)) m.gmt.psmeca(in_rows=[data], G=gmtpy.color('chocolate1'), E='white', W='1p,%s' % gmtpy.color('chocolate3'), *m.jxyr, **kwargs) if savename is None: if events is None: m.save('pics/stations_ridgecrest.png') else: m.save('pics/mechanisms_scedc_ridgecrest.png') else: m.save(savename)
# Load events from catalog file (generated using catalog.GlobalCMT() to download from www.globalcmt.org) # If no moment tensor is provided in the catalogue, the event is plotted as a red circle. # Symbol size relative to magnitude. events = model.load_events('deadsea_events_1976-2017.txt') beachball_symbol = 'd' factor_symbl_size = 5.0 for ev in events: mag = ev.magnitude if ev.moment_tensor is None: ev_symb = 'c'+str(mag*factor_symbl_size)+'p' m.gmt.psxy( in_rows=[[ev.lon, ev.lat]], S=ev_symb, G=gmtpy.color('scarletred2'), W='1p,black', *m.jxyr) else: devi = ev.moment_tensor.deviatoric() beachball_size = mag*factor_symbl_size mt = devi.m_up_south_east() mt = mt / ev.moment_tensor.scalar_moment() \ * pmt.magnitude_to_moment(5.0) m6 = pmt.to6(mt) data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0)# if m.gmt.is_gmt5(): kwargs = dict( M=True, S='%s%g' % (beachball_symbol[0], (beachball_size) / gmtpy.cm))