def command_download(args): from pyrocko.gf import ws def setup(parser): parser.add_option('--force', dest='force', action='store_true', help='overwrite existing files') parser, options, args = cl_parse('download', args, setup=setup) if not len(args) in (1, 2): parser.print_help() sys.exit(1) if len(args) == 2: site, store_id = args if not re.match(gf.meta.StringID.pattern, store_id): die('invalid store ID') else: site, store_id = args[0], None if site not in gf.ws.g_site_abbr: if -1 == site.find('://'): site = 'http://' + site try: ws.download_gf_store(site=site, store_id=store_id, force=options.force) except ws.DownloadError as e: die(str(e))
def test_local_server(self): class ServerThread(threading.Thread): def __init__(self, serve_dir): threading.Thread.__init__(self) self.engine = LocalEngine(store_dirs=[serve_dir]) self.s = server.Server('localhost', 32483, server.SeismosizerHandler, self.engine) def run(self): asyncore.loop(1., use_poll=True) t_ws = ServerThread(self.serve_dir) t_ws.start() try: ws.download_gf_store(site='http://localhost:32483', store_id=self.store_id, quiet=False) gfstore = store.Store(self.store_id) gfstore.check() finally: # import time # time.sleep(100) t_ws.s.close() t_ws.join(1.)
def command_download(args): from pyrocko.gf import ws def setup(parser): parser.add_option( '--force', dest='force', action='store_true', help='overwrite existing files') parser, options, args = cl_parse('download', args, setup=setup) if not len(args) in (1, 2): parser.print_help() sys.exit(1) if len(args) == 2: site, store_id = args if not re.match(gf.meta.StringID.pattern, store_id): die('invalid store ID') else: site, store_id = args[0], None if site not in gf.ws.g_site_abbr: if -1 == site.find('://'): site = 'http://' + site try: ws.download_gf_store(site=site, store_id=store_id, force=options.force) except ws.DownloadError as e: die(str(e))
def test_local_server(self): class ServerThread(threading.Thread): def __init__(self, serve_dir): threading.Thread.__init__(self) self.engine = LocalEngine( store_dirs=[serve_dir]) self.s = server.Server( 'localhost', 32483, server.SeismosizerHandler, self.engine) def run(self): asyncore.loop(1., use_poll=True) t_ws = ServerThread(self.serve_dir) t_ws.start() try: ws.download_gf_store( site='http://localhost:32483', store_id=self.store_id, quiet=False) gfstore = store.Store(self.store_id) gfstore.check() finally: # import time # time.sleep(100) t_ws.s.close() t_ws.join(1.)
def ensure_gfstores(self, interactive=False, gf_store_superdirs_extra=[]): if not self.stores_missing: return from pyrocko.gf import ws cfg = config.config() if len(cfg.gf_store_superdirs) == 0: store_dir = op.expanduser( op.join(config.pyrocko_dir_tmpl, 'gf_stores')) logger.debug('Creating default gf_store_superdirs: %s' % store_dir) util.ensuredir(store_dir) cfg.gf_store_superdirs = [store_dir] config.write_config(cfg) gf_store_superdirs = cfg.gf_store_superdirs + gf_store_superdirs_extra if interactive: print('We could not find the following Green\'s function stores:\n' ' %s\n' 'We can try to download the stores from ' 'http://kinherd.org into one of the following ' 'directories.' % '\n'.join(self.stores_missing)) for idr, dr in enumerate(gf_store_superdirs): print(' %d. %s' % ((idr+1), dr)) s = input('\nInto which directory should we download the GF ' 'store(s)?\nDefault 1, (C)ancel: ') if s in ['c', 'C']: print('Canceled!') sys.exit(1) elif s == '': s = 0 try: s = int(s) if s > len(gf_store_superdirs): raise ValueError except ValueError: print('Invalid selection: %s' % s) sys.exit(1) else: s = 1 download_dir = gf_store_superdirs[s-1] logger.info('Downloading Green\'s functions stores to %s' % download_dir) oldwd = os.getcwd() for store in self.stores_missing: os.chdir(download_dir) ws.download_gf_store(site='kinherd', store_id=store) os.chdir(oldwd)
def ensure_gfstores(self, interactive=False): if not self.stores_missing: return from pyrocko.gf import ws cfg = config.config() engine = self.get_engine() gf_store_superdirs = engine.store_superdirs if interactive: print('We could not find the following Green\'s function stores:\n' '%s\n' 'We can try to download the stores from ' 'http://kinherd.org into one of the following ' 'directories.' % '\n'.join(' ' + s for s in self.stores_missing)) for idr, dr in enumerate(gf_store_superdirs): print(' %d. %s' % ((idr + 1), dr)) s = input('\nInto which directory should we download the GF ' 'store(s)?\nDefault 1, (C)ancel: ') if s in ['c', 'C']: print('Canceled!') sys.exit(1) elif s == '': s = 0 try: s = int(s) if s > len(gf_store_superdirs): raise ValueError except ValueError: print('Invalid selection: %s' % s) sys.exit(1) else: s = 1 download_dir = gf_store_superdirs[s - 1] util.ensuredir(download_dir) logger.info('Downloading Green\'s functions stores to %s' % download_dir) oldwd = os.getcwd() for store in self.stores_missing: os.chdir(download_dir) ws.download_gf_store(site='kinherd', store_id=store) os.chdir(oldwd)
def ensure_gfstores(self, interactive=False): if not self.stores_missing: return from pyrocko.gf import ws cfg = config.config() engine = self.get_engine() gf_store_superdirs = engine.store_superdirs if interactive: print('We could not find the following Green\'s function stores:\n' '%s\n' 'We can try to download the stores from ' 'http://kinherd.org into one of the following ' 'directories.' % '\n'.join(' ' + s for s in self.stores_missing)) for idr, dr in enumerate(gf_store_superdirs): print(' %d. %s' % ((idr+1), dr)) s = input('\nInto which directory should we download the GF ' 'store(s)?\nDefault 1, (C)ancel: ') if s in ['c', 'C']: print('Canceled!') sys.exit(1) elif s == '': s = 0 try: s = int(s) if s > len(gf_store_superdirs): raise ValueError except ValueError: print('Invalid selection: %s' % s) sys.exit(1) else: s = 1 download_dir = gf_store_superdirs[s-1] util.ensuredir(download_dir) logger.info('Downloading Green\'s functions stores to %s' % download_dir) oldwd = os.getcwd() for store in self.stores_missing: os.chdir(download_dir) ws.download_gf_store(site='kinherd', store_id=store) os.chdir(oldwd)
def command_download(args): from pyrocko.gf import ws details = ''' Browse pre-calculated Green's function stores online: https://greens-mill.pyrocko.org ''' def setup(parser): parser.add_option('--force', dest='force', action='store_true', help='overwrite existing files') parser, options, args = cl_parse('download', args, setup=setup, details=details) if not len(args) in (1, 2): sys.exit(parser.format_help()) if len(args) == 2: site, store_id = args if not re.match(gf.meta.StringID.pattern, store_id): die('invalid store ID') else: site, store_id = args[0], None if site not in gf.ws.g_site_abbr: if -1 == site.find('://'): site = 'http://' + site try: ws.download_gf_store(site=site, store_id=store_id, force=options.force) except ws.DownloadError as e: die(str(e))
import os from pyrocko.plot.directivity import plot_directivity from pyrocko.gf import LocalEngine, RectangularSource, ws km = 1e3 # The store we are going extract data from: store_id = 'iceland_reg_v2' # First, download a Greens Functions store. If you already have one that you # would like to use, you can skip this step and point the *store_superdirs* in # the next step to that directory. if not os.path.exists(store_id): ws.download_gf_store(site='kinherd', store_id=store_id) # We need a pyrocko.gf.Engine object which provides us with the traces # extracted from the store. engine = LocalEngine(store_superdirs=['.']) # Create a RectangularSource with uniform fit. rect_source = RectangularSource(depth=1.6 * km, strike=240., dip=76.6, rake=-.4, anchor='top', nucleation_x=-.57, nucleation_y=-.59, velocity=2070., length=27 * km, width=9.4 * km, slip=1.4)
import os from pyrocko.gf import LocalEngine, Target, DCSource, ws from pyrocko import trace from pyrocko.marker import PhaseMarker # The store we are going extract data from: store_id = 'iceland_reg_v2' # First, download a Greens Functions store. If you already have one that you # would like to use, you can skip this step and point the *store_superdirs* in # the next step to that directory. if not os.path.exists(store_id): ws.download_gf_store(site='kinherd', store_id=store_id) # We need a pyrocko.gf.Engine object which provides us with the traces # extracted from the store. In this case we are going to use a local # engine since we are going to query a local store. engine = LocalEngine(store_superdirs=['.']) # Define a list of pyrocko.gf.Target objects, representing the recording # devices. In this case one station with a three component sensor will # serve fine for demonstation. channel_codes = 'ENZ' targets = [ Target( lat=10., lon=10., store_id=store_id, codes=('', 'STA', '', channel_code))