# http://pyrocko.org - GPLv3
#
# The Pyrocko Developers, 21st Century
# ---|P------/S----------~Lg----------
'''
Reader for `Silixia iDAS
<https://silixa.com/technology/idas-intelligent-distributed-acoustic-sensor/>`_
HDF5 files.
'''
from __future__ import annotations
from datetime import datetime
from typing import Any, Iterator
from pyrocko import trace
META_KEYS = {
'measure_length': 'MeasureLength',
'start_position': 'StartPosition',
'spatial_resolution': 'SpatialResolution',
'fibre_index': 'FibreIndex',
'fibre_length_multiplier': 'FibreLengthMultiplier',
# 'unit_calibration': 'Unit Calibration (nm)',
'start_distance': 'StartDistance',
'stop_distance': 'StopDistance',
'normalization': 'Normalization',
'decimation_filter': 'DecimationFilter',
'gauge_length': 'GaugeLength',
'norm_offset': 'NormOffset',
'source_mode': 'SourceMode',
'time_decimation': 'TimeDecimation',
'zero_offset': 'ZeroOffset',
'p_parameter': 'P',
'p_coefficients': 'P_Coefficients',
'idas_version': 'Version',
'precice_sampling_freq': 'PreciseSamplingFrequency',
'receiver_gain': 'ReceiverGain',
# 'continuous_mode': 'Continuous Mode',
'geo_lat': 'Latitude',
'geo_lon': 'Longitude',
'geo_elevation': 'Altitude',
'unit': 'RawDataUnit'
}
def iload(filename, load_data=True) -> Iterator[trace.Trace]:
# prevent hard dependency on h5py
try:
import h5py
except ImportError as exc:
raise ImportError(
"Please install 'h5py' to proceed,"
"e.g. by running 'pip install h5py'") from exc
with h5py.File(filename, 'r') as file:
# get the meta data
meta = get_meta(file)
# get the actual time series if load_data
data = file['Acquisition/Raw[0]/RawData'][:] if load_data else None
# get the sampling rate, starttime, number of samples in space and time
deltat = 1.0 / file['Acquisition/Raw[0]'].attrs['OutputDataRate']
tmin = datetime.fromisoformat(
file['Acquisition/Raw[0]/RawData'].attrs['PartStartTime']
.decode('ascii')).timestamp()
nchannels = int(file['Acquisition/Raw[0]'].attrs['NumberOfLoci'])
nsamples = int(file['Acquisition/Raw[0]/RawDataTime'].attrs['Count'])
for icha in range(nchannels):
station = '%05i' % icha
meta_icha = meta.copy()
meta_icha['channel'] = icha
tr = trace.Trace(
network='DA',
station=station,
ydata=None,
deltat=deltat,
tmin=tmin,
tmax=tmin + (nsamples - 1) * deltat,
meta=meta_icha)
if data:
tr.set_ydata(data[:, icha])
yield tr
def detect(first512) -> bool:
return first512.startswith(b'\x89HDF')