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 .. import common 

12from pyrocko.squirrel.error import SquirrelError 

13from pyrocko.progress import progress 

14 

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

16 

17 

18def setup(subparsers): 

19 p = common.add_parser( 

20 subparsers, 'summon', 

21 help='Fill local cache.') 

22 

23 common.add_selection_arguments(p) 

24 common.add_query_arguments(p) 

25 return p 

26 

27 

28def call(parser, args): 

29 d = common.squirrel_query_from_arguments(args) 

30 squirrel = common.squirrel_from_selection_arguments(args) 

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)