Skip to content

Commit

Permalink
work on adding neubrex
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Feb 27, 2025
1 parent 1dbb10e commit 557343b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
27 changes: 26 additions & 1 deletion dascore/io/neubrex/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import dascore.io.neubrex.utils_rfs as rfs_utils
from dascore.constants import SpoolType
from dascore.io import FiberIO
from dascore.utils.hdf5 import H5Reader
from dascore.utils.hdf5 import H5Reader, H5Writer


class NeubrexRFSPatchAttrs(dc.PatchAttrs):
Expand Down Expand Up @@ -84,6 +84,31 @@ def scan(self, resource: H5Reader, snap=True, **kwargs) -> list[dc.PatchAttrs]:
attrs["file_version"] = self.version
return [dc.PatchAttrs(**attrs)]

def write(
self,
spool: SpoolType,
resource: H5Writer,
extra_attrs: dict[str, float | int | str] | None = None,
**kwargs,
) -> None:
"""
Write a Neubrex Rayleigh Frequency Shift file.
Parameters
----------
spool
The spool to write.
resource
The H5file to write to.
extra_attrs
A dict of basic types to write to the Acoustic dataset's
attributes.
**kwargs
Un-used, only here for compat with other write methods.
"""
if len(spool) > 1:
raise ValueError("NeubrexRFS only supports writing a single patch.")


class NeubrexDASV1(FiberIO):
"""
Expand Down
29 changes: 29 additions & 0 deletions tests/test_io/test_neubrex/test_neubrex_rfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Tests for Rayleigh Frequency Shift format.
"""

import pytest

import dascore as dc


class TestWrite:
"""Tests for writing to the NeubrexRFS format."""

@pytest.fixture(scope="class")
def written_rfs(self, random_patch, tmp_path_factory):
"""Write the random patch, return path."""
path = tmp_path_factory.mktemp("rfs") / "random_rfs.h5"
random_patch.io.write(path, "NeubrexRFS")
return path

def test_multi_patch_raises(self, random_spool, tmp_path):
"""Trying to save multiple patch should raise."""
msg = "only supports writing a single patch"
with pytest.raises(ValueError, match=msg):
dc.write(random_spool, tmp_path / "bad_file.h5", "NeubrexRFS")

def test_format(self, written_rfs):
"""Ensure the returned format type is correct."""
format_name = dc.get_format(written_rfs)
assert "NeubrexRFS" in format_name

0 comments on commit 557343b

Please sign in to comment.