1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6import math 

7import logging 

8 

9from pyrocko.squirrel.error import SquirrelError 

10from pyrocko.progress import progress 

11 

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

13 

14headline = 'Fill local cache.' 

15 

16 

17def make_subparser(subparsers): 

18 return subparsers.add_parser( 

19 'summon', 

20 help=headline, 

21 description=headline) 

22 

23 

24def setup(parser): 

25 parser.add_squirrel_selection_arguments() 

26 parser.add_squirrel_query_arguments() 

27 

28 

29def run(parser, args): 

30 d = args.squirrel_query 

31 squirrel = args.make_squirrel() 

32 

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

34 raise SquirrelError('Time span required.') 

35 

36 tinc = 3600. 

37 

38 with progress.view(): 

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

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

41 iwindow = 0 

42 for trs in squirrel.chopper_waveforms( 

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

44 

45 iwindow += 1 

46 task.update(iwindow) 

47 

48 task.done() 

49 

50 stats = str(squirrel) 

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

52 

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