Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/io/backends/mseed.py: 100%

32 statements  

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

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Squirrel IO adaptor to :py:mod:`pyrocko.io.mseed`. 

8''' 

9 

10from pyrocko.io.io_common import get_stats, touch # noqa 

11from ... import model 

12 

13SEGMENT_SIZE = 1024*1024 

14 

15 

16def provided_formats(): 

17 return ['mseed'] 

18 

19 

20def detect(first512): 

21 from pyrocko.io import mseed 

22 

23 if mseed.detect(first512): 

24 return 'mseed' 

25 else: 

26 return None 

27 

28 

29def iload(format, file_path, segment, content): 

30 assert format == 'mseed' 

31 from pyrocko.io import mseed 

32 

33 load_data = 'waveform' in content 

34 

35 if segment is None: 

36 offset = 0 

37 nsegments = 0 

38 else: 

39 offset = segment 

40 nsegments = 1 

41 

42 file_segment = None 

43 itr = 0 

44 for tr in mseed.iload( 

45 file_path, load_data=load_data, 

46 offset=offset, segment_size=SEGMENT_SIZE, nsegments=nsegments): 

47 

48 if file_segment != tr.meta['offset_start']: 

49 itr = 0 

50 file_segment = tr.meta['offset_start'] 

51 

52 nsamples = int(round((tr.tmax - tr.tmin) / tr.deltat)) + 1 

53 nut = model.make_waveform_nut( 

54 file_segment=file_segment, 

55 file_element=itr, 

56 codes=tr.codes, 

57 tmin=tr.tmin, 

58 tmax=tr.tmin + tr.deltat * nsamples, 

59 deltat=tr.deltat) 

60 

61 if 'waveform' in content: 

62 nut.content = tr 

63 

64 yield nut 

65 itr += 1