Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dascore/data_registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ febus_2.h5 c118960a94e37fbff0eb5c33856d34cdfe81609902c4feaedab9949498d31c23 http
febg1_C1_2023-05-10T12.25.03+0000.bsl e1a8ff72f3ec1805129267df916f41419bf7fa3a4993602e2b85e721cad922ae https://github.com/dasdae/test_data/raw/master/dss/febg1_C1_2023-05-10T12.25.03+0000.bsl
febg1_C1_2023-05-10T12.27.33+0000.bsl 233df0c184796944442ae19beddcf962aba1c9fab337fd1c74971f0c4d513a36 https://github.com/dasdae/test_data/raw/master/dss/febg1_C1_2023-05-10T12.27.33+0000.bsl
xdas_netcdf.nc 9e53fa1ce8395fedbb195048b3eb2832b87cb6883867cdff30be93078e8027f7 https://github.com/dasdae/test_data/raw/master/das/xdas_netcdf.nc
sintela_protobuf_1.pb cafa038c033cb5e4cf4aa90bab203eb1e10dc05a6052c0576dc80d6a5b3b42dc https://github.com/dasdae/test_data/raw/master/das/sintela_protobuf_1.pb
9 changes: 9 additions & 0 deletions dascore/io/sintela_protobuf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Sintela protobuf reader.
This module supports Sintela's MTLV-wrapped protobuf recordings. Format
detection only inspects the MTLV envelope and does not require protobuf to be
installed. Reading and scanning lazily import protobuf support when needed.
"""

from .core import SintelaProtobufV1
42 changes: 42 additions & 0 deletions dascore/io/sintela_protobuf/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Core module for reading Sintela protobuf format.
"""

from __future__ import annotations

from typing import Any

import numpy as np

import dascore as dc
from dascore.io import FiberIO
from dascore.utils.io import BinaryReader

from .utils import get_supported_family_tag, read_payload, scan_payload


class SintelaProtobufV1(FiberIO):
"""IO class for Sintela protobuf MTLV recordings."""

name = "Sintela_Protobuf"
preferred_extensions = ("pb",)
version = "1"

def get_format(self, resource: BinaryReader, **kwargs) -> tuple[str, str] | bool:
"""Return the format/version tuple if the file is Sintela protobuf."""
tag = get_supported_family_tag(resource)
return (self.name, self.version) if tag else False

def scan(self, resource: BinaryReader, **kwargs) -> list[dict[str, Any]]:
"""Scan a Sintela protobuf recording."""
return scan_payload(resource)

def read(self, resource: BinaryReader, **kwargs) -> dc.BaseSpool:
"""Read a Sintela protobuf recording into a spool."""
data, coords, attrs = read_payload(resource)
selectors = {name: kwargs[name] for name in coords.dims if name in kwargs}
if selectors:
coords, data = coords.select(data, **selectors)
if not np.size(data):
return dc.spool([])
return dc.spool([dc.Patch(data=data, coords=coords, attrs=attrs)])
Loading
Loading