1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8import math
9import logging
11from pyrocko.squirrel.error import SquirrelError
12from pyrocko.progress import progress
14logger = logging.getLogger('psq.cli.summon')
16headline = 'Fill local cache.'
19def make_subparser(subparsers):
20 return subparsers.add_parser(
21 'summon',
22 help=headline,
23 description=headline)
26def setup(parser):
27 parser.add_squirrel_selection_arguments()
28 parser.add_squirrel_query_arguments()
31def run(parser, args):
32 d = args.squirrel_query
33 squirrel = args.make_squirrel()
35 if 'tmin' not in d or 'tmax' not in d:
36 raise SquirrelError('Time span required.')
38 tinc = 3600.
40 with progress.view():
41 nwindows = int(math.ceil((d['tmax'] - d['tmin']) / tinc))
42 task = progress.task('Summoning', nwindows)
43 iwindow = 0
44 for trs in squirrel.chopper_waveforms(
45 tinc=tinc, load_data=False, **d):
47 iwindow += 1
48 task.update(iwindow)
50 task.done()
52 stats = str(squirrel)
53 stats = '\n'.join(' ' + s for s in stats.splitlines())
55 logger.info('Squirrel stats:\n%s' % stats)