Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 419 #420

Merged
merged 4 commits into from
Aug 9, 2024
Merged
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 @@ -25,3 +25,4 @@ silixa_h5_1.hdf5 d3f1b92b17ae2d00f900426e80d48964fb5a33b9480ef9805721ac756acd4a2
deformation_rate_event_1.hdf5 be8574ae523de9b17d2a0f9e847f30301e1607e2076366e005cdb3a46b79f172 https://github.com/dasdae/test_data/raw/master/das/deformation_rate_event_1.hdf5
neubrex_dss_forge.h5 49e501e16d880b22c5d9d8997223f0c1aceb942386efb09aae938b9d97eb51ed https://github.com/dasdae/test_data/raw/master/dss/neubrex_dss_forge.h5
neubrex_dts_forge.h5 940f7bea6dd4c8a1340b4936b8eb7f9edc577cbcaf77c1f5ac295890f88c9ba5 https://github.com/dasdae/test_data/raw/master/dts/neubrex_dts_forge.h5
decimated_optodas.hdf5 48ce9c2ab4916d5536faeef0bd789f326ec4afc232729d32014d4d835a9fb74e https://github.com/dasdae/test_data/raw/master/das/decimated_optodas.hdf5
27 changes: 13 additions & 14 deletions dascore/io/optodas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ def _get_opto_das_version_str(hdf_fi) -> str:
return version_str


def _get_coord_manager(header):
def _get_coord_manager(fi):
"""Get the distance ranges and spacing."""
header = fi["header"]
dims = tuple(unbyte(x) for x in header["dimensionNames"])
units = tuple(unbyte(x) for x in header["dimensionUnits"])

coords = {}
for index, (dim, unit) in enumerate(zip(dims, units)):
crange = header["dimensionRanges"][f"dimension{index}"]
step = unpack_scalar_h5_dataset(crange["unitScale"])

# special case for time.
# Special case for time.
if dim == "time":
step = dc.to_timedelta64(step)
t1 = dc.to_datetime64(unpack_scalar_h5_dataset(header["time"]))
start = t1 + unpack_scalar_h5_dataset(crange["min"]) * step
stop = t1 + (unpack_scalar_h5_dataset(crange["max"]) + 1) * step
else:
# The min/max values appear to be int ranges so we need to
# multiply by step.
start = unpack_scalar_h5_dataset(crange["min"]) * step
stop = (unpack_scalar_h5_dataset(crange["max"]) + 1) * step

coords[dim] = get_coord(min=start, max=stop, step=step, units=unit)
return dascore.core.get_coord_manager(coords=coords, dims=dims)
coord = get_coord(min=start, max=stop, step=step, units=unit)
else: # and distance
# The channels are ints so we multiply by step to get distance.
distance = fi["/header/channels"][:] * step
coord = get_coord(values=distance)
coords[dim] = coord
out = dascore.core.get_coord_manager(coords=coords, dims=dims)
return out


def _get_attr_dict(header):
Expand All @@ -72,9 +72,8 @@ def _get_attr_dict(header):

def _get_opto_das_attrs(fi) -> dict:
"""Scan a OptoDAS file, return metadata."""
header = fi["header"]
cm = _get_coord_manager(header)
attrs = _get_attr_dict(header)
cm = _get_coord_manager(fi)
attrs = _get_attr_dict(fi["header"])
attrs["coords"] = cm
return attrs

Expand Down
24 changes: 24 additions & 0 deletions tests/test_io/test_optodas/test_optodas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Tests for optoDAS files.
"""

import dascore as dc
from dascore.io.optodas import OptoDASV8
from dascore.utils.downloader import fetch


class TestOptoDASIssues:
"""Test case related to issues in OptoDAS parser."""

def test_read_decimated_patch(self):
"""Tests for reading spatially decimated patch (#419)"""
path = fetch("decimated_optodas.hdf5")
fiber_io = OptoDASV8()

fmt_str, version_str = fiber_io.get_format(path)
assert (fmt_str, version_str) == (fiber_io.name, fiber_io.version)

spool = fiber_io.read(path)
patch = spool[0]
assert isinstance(patch, dc.Patch)
assert patch.data.shape
Loading