1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6from __future__ import absolute_import, print_function 

7 

8import math 

9import logging 

10 

11from pyrocko.squirrel.error import SquirrelError 

12from pyrocko.progress import progress 

13 

14logger = logging.getLogger('psq.cli.summon') 

15 

16 

17def make_subparser(subparsers): 

18 return subparsers.add_parser( 

19 'summon', 

20 help='Fill local cache.') 

21 

22 

23def setup(parser): 

24 parser.add_squirrel_selection_arguments() 

25 parser.add_squirrel_query_arguments() 

26 

27 

28def run(parser, args): 

29 d = args.squirrel_query 

30 squirrel = args.make_squirrel() 

31 

32 if 'tmin' not in d or 'tmax' not in d: 

33 raise SquirrelError('Time span required.') 

34 

35 tinc = 3600. 

36 

37 with progress.view(): 

38 nwindows = int(math.ceil((d['tmax'] - d['tmin']) / tinc)) 

39 task = progress.task('Summoning', nwindows) 

40 iwindow = 0 

41 for trs in squirrel.chopper_waveforms( 

42 tinc=tinc, load_data=False, **d): 

43 

44 iwindow += 1 

45 task.update(iwindow) 

46 

47 task.done() 

48 

49 stats = str(squirrel) 

50 stats = '\n'.join(' ' + s for s in stats.splitlines()) 

51 

52 logger.info('Squirrel stats:\n%s' % stats)