diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index 94dc7c3..cf969ad 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -29,6 +29,7 @@ Here below the list of formats that are currently implemented. All HDF5 based fo | OPTASENSE | `"optasense"` | ✅︎ | | SILIXA | `"silixa"` | ❌ | | SINTELA | `"sintela"` | ✅︎ | +| TERRA15 | `"terra15"` | ✅︎ | ```{warning} File formats that do not support virtualization will be loaded in memory. We are working on a solution for non-HDF5 based file formats. diff --git a/xdas/io/__init__.py b/xdas/io/__init__.py index d734af0..b571101 100644 --- a/xdas/io/__init__.py +++ b/xdas/io/__init__.py @@ -1,2 +1,2 @@ -from . import asn, febus, miniseed, optasense, silixa, sintela +from . import asn, febus, miniseed, optasense, silixa, sintela, terra15 from .core import get_free_port diff --git a/xdas/io/terra15.py b/xdas/io/terra15.py new file mode 100644 index 0000000..7c969ac --- /dev/null +++ b/xdas/io/terra15.py @@ -0,0 +1,24 @@ +from datetime import datetime, timezone + +import h5py +import numpy as np + +from ..core.dataarray import DataArray +from ..virtual import VirtualSource + + +def read(fname, tz=timezone.utc): + with h5py.File(fname, "r") as file: + ti = np.datetime64( + datetime.fromtimestamp(file["data_product"]["gps_time"][0], tz=tz) + ).astype("datetime64[ms]") + tf = np.datetime64( + datetime.fromtimestamp(file["data_product"]["gps_time"][-1], tz=tz) + ).astype("datetime64[ms]") + d0 = file.attrs["sensing_range_start"] + dx = file.attrs["dx"] + data = VirtualSource(file["data_product"]["data"]) + nt, nd = data.shape + t = {"tie_indices": [0, nt - 1], "tie_values": [ti, tf]} + d = {"tie_indices": [0, nd - 1], "tie_values": [d0, d0 + (nd - 1) * dx]} + return DataArray(data, {"time": t, "distance": d})