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
« prev ^ index » next coverage.py v7.6.0, created at 2025-12-04 10:41 +0000
1from __future__ import annotations
3from typing import Any, Generator
5from pyrocko.trace import Trace
7try:
8 import simpledas
9except ImportError:
10 simpledas = None
13def iload(
14 filename: str,
15 load_data: bool = True) -> Generator[Trace, Any, None]:
17 if simpledas is None:
18 raise ImportError(
19 'simpledas is not available. '
20 'Install ASN SimpleDAS to load ASN OptoDAS HDF5 data.')
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
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
33 for channel in trace_data:
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
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