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

20 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-06 15:01 +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.datacube`. 

8''' 

9 

10 

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

12from ... import model 

13 

14 

15def provided_formats(): 

16 return ['datacube'] 

17 

18 

19def detect(first512): 

20 from pyrocko.io import datacube 

21 

22 if datacube.detect(first512): 

23 return 'datacube' 

24 else: 

25 return None 

26 

27 

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

29 assert format == 'datacube' 

30 

31 from pyrocko.io import datacube 

32 

33 load_data = 'waveform' in content 

34 

35 for itr, tr in enumerate(datacube.iload(file_path, load_data=load_data)): 

36 

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

38 

39 nut = model.make_waveform_nut( 

40 file_segment=0, 

41 file_element=itr, 

42 codes=tr.codes, 

43 tmin=tr.tmin, 

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

45 deltat=tr.deltat) 

46 

47 if 'waveform' in content: 

48 nut.content = tr 

49 

50 yield nut