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

34 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1import os 

2import logging 

3import shutil 

4from pyrocko import gf, guts, util 

5 

6 

7logger = logging.getLogger('main') 

8 

9 

10def elastic10_fd_to_elastic10( 

11 source_store_dir, 

12 dest_store_dir, 

13 show_progress=True): 

14 

15 def _raise(message): 

16 raise gf.StoreError('elastic10_fd_to_elastic10: %s' % message) 

17 

18 source = gf.Store(source_store_dir) 

19 

20 if source.config.component_scheme != 'elastic10_fd': 

21 _raise( 

22 'Only `elastic10_fd` component scheme supported for input store.') 

23 

24 if source.config.short_type != 'A': 

25 _raise( 

26 'Only type A stores supported for input store.') 

27 

28 if not os.path.exists(dest_store_dir): 

29 config = guts.clone(source.config) 

30 config.id += '_from_fd' 

31 config.__dict__['ncomponents'] = 10 

32 config.__dict__['component_scheme'] = 'elastic10' 

33 config.fd_distance_delta = None 

34 

35 util.ensuredirs(dest_store_dir) 

36 gf.Store.create(dest_store_dir, config=config) 

37 shutil.copytree( 

38 os.path.join(source_store_dir, 'phases'), 

39 os.path.join(dest_store_dir, 'phases')) 

40 

41 try: 

42 gf.store.Store.create_dependants(dest_store_dir) 

43 except gf.StoreError: 

44 pass 

45 

46 dest = gf.Store(dest_store_dir, 'w') 

47 

48 if show_progress: 

49 pbar = util.progressbar( 

50 'elastic10_fd_to_elastic10', 

51 source.config.nrecords/source.config.ncomponents) 

52 

53 try: 

54 for i, args in enumerate(dest.config.iter_nodes(level=-1)): 

55 for ig in range(10): 

56 tr = source.get(args + (ig+10,)) 

57 dest.put(args + (ig,), tr) 

58 

59 if show_progress: 

60 pbar.update(i+1) 

61 

62 finally: 

63 if show_progress: 

64 pbar.finish()