Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/fomosto/dummy.py: 0%

49 statements  

« 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---------- 

5 

6import logging 

7import os 

8import signal 

9 

10import numpy as num 

11 

12from pyrocko import trace, gf 

13 

14guts_prefix = 'pf' 

15 

16logger = logging.getLogger('pyrocko.fomosto.dummy') 

17 

18 

19class Interrupted(gf.store.StoreError): 

20 def __str__(self): 

21 return 'Interrupted.' 

22 

23 

24class DummyGFBuilder(gf.builder.Builder): 

25 def __init__(self, store_dir, step, shared, force=False): 

26 self.store = gf.store.Store(store_dir, 'w') 

27 gf.builder.Builder.__init__( 

28 self, self.store.config, step, block_size=(1, 51), force=force) 

29 

30 def cleanup(self): 

31 self.store.close() 

32 

33 def work_block(self, index): 

34 (sz, firstx), (sz, lastx), (ns, nx) = \ 

35 self.get_block_extents(index) 

36 

37 logger.info( 

38 'Starting block %i / %i' % (index+1, self.nblocks)) 

39 

40 interrupted = [] 

41 

42 def signal_handler(signum, frame): 

43 interrupted.append(True) 

44 

45 original = signal.signal(signal.SIGINT, signal_handler) 

46 self.store.lock() 

47 duplicate_inserts = 0 

48 try: 

49 for x in num.linspace(firstx, lastx, nx): 

50 for ig in range(self.store.config.ncomponents): 

51 args = (sz, x, ig) 

52 irec = self.store.config.irecord(*args) 

53 tr = trace.Trace( 

54 deltat=self.store.config.deltat, 

55 ydata=num.zeros(10000)+float(irec)) 

56 

57 gf_tr = gf.store.GFTrace.from_trace(tr) 

58 

59 try: 

60 self.store.put(args, gf_tr) 

61 except gf.store.DuplicateInsert: 

62 duplicate_inserts += 1 

63 

64 finally: 

65 if duplicate_inserts: 

66 logger.warning( 

67 '%i insertions skipped (duplicates)' % duplicate_inserts) 

68 

69 self.store.unlock() 

70 signal.signal(signal.SIGINT, original) 

71 

72 if interrupted: 

73 raise KeyboardInterrupt() 

74 

75 logger.info('Done with block %i / %i' % (index+1, self.nblocks)) 

76 

77 

78km = 1000. 

79 

80 

81def init(store_dir, variant): 

82 if variant is not None: 

83 raise gf.store.StoreError('unsupported variant: %s' % variant) 

84 

85 store_id = os.path.basename(os.path.realpath(store_dir)) 

86 

87 config = gf.meta.ConfigTypeA( 

88 id=store_id, 

89 ncomponents=2, 

90 sample_rate=1.0, 

91 receiver_depth=0*km, 

92 source_depth_min=0*km, 

93 source_depth_max=400*km, 

94 source_depth_delta=4*km, 

95 distance_min=4*km, 

96 distance_max=400*km, 

97 distance_delta=4*km, 

98 modelling_code_id='dummy') 

99 

100 config.validate() 

101 return gf.store.Store.create_editables(store_dir, config=config) 

102 

103 

104def build( 

105 store_dir, 

106 force=False, 

107 nworkers=None, 

108 continue_=False, 

109 step=None, 

110 iblock=None): 

111 

112 return DummyGFBuilder.build( 

113 store_dir, force=force, nworkers=nworkers, continue_=continue_, 

114 step=step, iblock=iblock)