Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/summon.py: 29%
34 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 06:59 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-06 06:59 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Implementation of :app:`squirrel summon`.
8'''
10import math
11import logging
13from pyrocko.squirrel.error import SquirrelError
14from pyrocko.progress import progress
16logger = logging.getLogger('psq.cli.summon')
18headline = 'Fill local cache.'
21def make_subparser(subparsers):
22 return subparsers.add_parser(
23 'summon',
24 help=headline,
25 description=headline)
28def setup(parser):
29 parser.add_squirrel_selection_arguments()
30 parser.add_squirrel_query_arguments()
31 parser.add_argument(
32 '--channel-priorities',
33 dest='channel_priorities',
34 metavar='CHA',
35 help='''
36List of 2-character band/instrument code combinations to try. For example,
37giving ```HH,BH``` would first try to get ```HH?``` channels and then fallback
38to ```BH?``` if these are not available. The first matching waveforms are
39returned. Use in combination with ``--sample-rate-min`` and
40``--sample-rate-max`` to constrain the sample rate.
41'''.strip())
43 parser.add_argument(
44 '--sample-rate-min',
45 dest='sample_rate_min',
46 metavar='FLOAT',
47 type=float,
48 help='Minimum sample rate [Hz] to consider.')
50 parser.add_argument(
51 '--sample-rate-max',
52 dest='sample_rate_max',
53 metavar='FLOAT',
54 type=float,
55 help='Maximum sample rate [Hz] to consider.')
58def run(parser, args):
59 d = args.squirrel_query
60 squirrel = args.make_squirrel()
62 if 'tmin' not in d or 'tmax' not in d:
63 raise SquirrelError('Time span required.')
65 tinc = 3600.
67 channel_priorities = None
68 if args.channel_priorities:
69 channel_priorities = [
70 cha.strip() for cha in args.channel_priorities.split(',')]
72 with progress.view():
73 nwindows = int(math.ceil((d['tmax'] - d['tmin']) / tinc))
74 task = progress.task('Summoning', nwindows)
75 iwindow = 0
76 for trs in squirrel.chopper_waveforms(
77 tinc=tinc,
78 load_data=False,
79 channel_priorities=channel_priorities,
80 sample_rate_min=args.sample_rate_min,
81 sample_rate_max=args.sample_rate_max,
82 **d):
84 iwindow += 1
85 task.update(iwindow)
87 task.done()
89 stats = str(squirrel)
90 stats = '\n'.join(' ' + s for s in stats.splitlines())
92 logger.info('Squirrel stats:\n%s' % stats)