Coverage for /usr/local/lib/python3.13/dist-packages/pyrocko/io/hdf5_optodas.py: 41%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2025-12-04 10:41 +0000

1from __future__ import annotations 

2 

3from typing import Any, Generator 

4 

5from pyrocko.trace import Trace 

6 

7try: 

8 import simpledas 

9except ImportError: 

10 simpledas = None 

11 

12 

13def iload( 

14 filename: str, 

15 load_data: bool = True) -> Generator[Trace, Any, None]: 

16 

17 if simpledas is None: 

18 raise ImportError( 

19 'simpledas is not available. ' 

20 'Install ASN SimpleDAS to load ASN OptoDAS HDF5 data.') 

21 

22 trace_data = simpledas.load_DAS_files( 

23 filename, samples=None if load_data else 0, integrate=False) 

24 if not load_data: 

25 time_data = simpledas.load_DAS_files(filename, chIndex=[0]) 

26 else: 

27 time_data = trace_data 

28 

29 deltat = (time_data.index[1] - time_data.index[0]).total_seconds() 

30 tmin = time_data.index[0].timestamp() 

31 nsamples = time_data.index.size 

32 

33 for channel in trace_data: 

34 

35 trace = Trace( 

36 network='OD', 

37 station='%05d' % channel, 

38 ydata=None, 

39 deltat=deltat, 

40 tmin=tmin, 

41 tmax=tmin + (nsamples - 1) * deltat, 

42 ) 

43 if load_data: 

44 data = trace_data[channel].values 

45 trace.ydata = data 

46 yield trace 

47 

48 

49def detect(first512: bytes) -> bool: 

50 if simpledas is None: 

51 return False 

52 ret = first512.startswith(b'\x89HDF') and b'TREE' in first512 

53 return ret