1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from __future__ import absolute_import, print_function 

7 

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

9from ... import model 

10 

11 

12def provided_formats(): 

13 return ['datacube'] 

14 

15 

16def detect(first512): 

17 from pyrocko.io import datacube 

18 

19 if datacube.detect(first512): 

20 return 'datacube' 

21 else: 

22 return None 

23 

24 

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

26 assert format == 'datacube' 

27 

28 from pyrocko.io import datacube 

29 

30 load_data = 'waveform' in content 

31 

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

33 

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

35 

36 nut = model.make_waveform_nut( 

37 file_segment=0, 

38 file_element=itr, 

39 agency='', 

40 network=tr.network, 

41 station=tr.station, 

42 location=tr.location, 

43 channel=tr.channel, 

44 tmin=tr.tmin, 

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

46 deltat=tr.deltat) 

47 

48 if 'waveform' in content: 

49 nut.content = tr 

50 

51 yield nut