-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6610b4c
commit 2f179ce
Showing
10 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Support for Neubrex H5 DSS/DTS files. | ||
This module was written to read the DSS/DTS files created by Neubrex for | ||
the Forge dataset: https://gdr.openei.org/submissions/1565 | ||
The citation for the dataset is: | ||
Energy and Geoscience Institute at the University of Utah. (2023). | ||
Utah FORGE: Well 16B(78)-32 2023 Neubrex Energy Services Circulation | ||
Test Period with Fiber Optics Monitoring [data set]. | ||
Retrieved from https://dx.doi.org/10.15121/2222469. | ||
""" | ||
from __future__ import annotations | ||
|
||
from .core import NeubrexV1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
Core modules for reading Neubrex (Forge) dss/dts data. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import dascore as dc | ||
from dascore.constants import SpoolType | ||
from dascore.io import FiberIO | ||
from dascore.utils.hdf5 import H5Reader | ||
|
||
from .utils import _get_attrs_coords_and_data, _is_neubrex, _maybe_trim_data | ||
|
||
|
||
class NeubrexPatchAttrs(dc.PatchAttrs): | ||
"""Patch attrs for Neubrex files.""" | ||
|
||
api: str | None = None | ||
filed_name: str = "" | ||
well_id: str = "" | ||
well_name: str = "" | ||
well_bore_id: str = "" | ||
|
||
|
||
class NeubrexV1(FiberIO): | ||
"""Support for bare-bones h5 format.""" | ||
|
||
name = "Neubrex" | ||
preferred_extensions = ("hdf5", "h5") | ||
version = "1" | ||
|
||
def get_format(self, resource: H5Reader, **kwargs) -> tuple[str, str] | bool: | ||
"""Determine if is simple h5 format.""" | ||
if _is_neubrex(resource): | ||
return self.name, self.version | ||
return False | ||
|
||
def read(self, resource: H5Reader, snap=True, **kwargs) -> SpoolType: | ||
""" | ||
Read a simple h5 file. | ||
Parameters | ||
---------- | ||
resource | ||
The open h5 object. | ||
snap | ||
If True, snap each coordinate to be evenly sampled. | ||
**kwargs | ||
Passed to filtering coordinates. | ||
""" | ||
attr_dict, cm, data = _get_attrs_coords_and_data(resource, snap) | ||
if kwargs: | ||
cm, data = _maybe_trim_data(cm, data, **kwargs) | ||
attrs = NeubrexPatchAttrs(**attr_dict) | ||
patch = dc.Patch(coords=cm, data=data[:], attrs=attrs) | ||
return dc.spool([patch]) | ||
|
||
def scan(self, resource: H5Reader, snap=True, **kwargs) -> list[dc.PatchAttrs]: | ||
"""Get the attributes of a h5simple file.""" | ||
attrs, cm, data = _get_attrs_coords_and_data(resource, snap) | ||
attrs["coords"] = cm.to_summary_dict() | ||
attrs["path"] = resource.filename | ||
attrs["file_format"] = self.name | ||
attrs["file_version"] = self.version | ||
return [dc.PatchAttrs(**attrs)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Utilities functions for Neubrex IO support""" | ||
|
||
import dascore as dc | ||
from dascore.utils.misc import maybe_get_items | ||
|
||
|
||
def _is_neubrex(h5fi): | ||
"""Determine if the file is of Neubrex origin.""" | ||
expected_keys = {"data", "depth", "stamps"} | ||
keys = set(h5fi.keys()) | ||
if not expected_keys.issubset(keys): | ||
return False | ||
expected_attrs = {"DataUnitLabel", "StartDateTime", "EndDateTime"} | ||
data_attrs = set(h5fi["data"].attrs) | ||
if expected_attrs.issubset(data_attrs): | ||
return True | ||
|
||
|
||
def _get_coord_manager(h5fi, snap=True): | ||
"""Get a coordinate manager from the file.""" | ||
|
||
def _get_time_coord(h5fi, snap): | ||
"""Get the time coordinate.""" | ||
# Unix stamps are in us for test files, not sure if always true. | ||
unix_stamps = dc.to_datetime64(h5fi["stamps_unix"][:] / 1_000_000) | ||
time_coord = dc.get_coord(values=unix_stamps) | ||
if snap: | ||
time_coord = time_coord.snap() | ||
return time_coord | ||
|
||
def _get_dist_coord(h5fi): | ||
"""Get the distance (depth) coordinate.""" | ||
depth = h5fi["depth"][:] | ||
return dc.get_coord(values=depth) | ||
|
||
coords = { | ||
"time": _get_time_coord(h5fi, snap=snap), | ||
"distance": _get_dist_coord(h5fi), | ||
} | ||
return dc.get_coord_manager(coords=coords, dims=("time", "distance")) | ||
|
||
|
||
def _get_data_units_and_type(data_unit_label): | ||
"""Get the units from contained string.""" | ||
quantity = dc.get_quantity(data_unit_label.replace("-", "")) | ||
return quantity | ||
|
||
|
||
def _get_attr_dict(h5fi): | ||
"""Get a dict of neubrex attributes.""" | ||
mapping = { | ||
"API": "api", | ||
# "DataUnitLabel": "data_unit_label", | ||
"FieldName": "field_name", | ||
"WellID": "well_id", | ||
"WellName": "well_name", | ||
"WellBoreID": "well_bore_id", | ||
} | ||
data_attrs = dict(h5fi["data"].attrs) | ||
out = maybe_get_items(data_attrs, mapping) | ||
out["data_units"] = _get_data_units_and_type(data_attrs["DataUnitLabel"]) | ||
return out | ||
|
||
|
||
def _maybe_trim_data(cm, data, time=None, distance=None, **kwargs): | ||
"""Maybe trim the data.""" | ||
if time is not None or distance is not None: | ||
cm, data = cm.select(time=time, distance=distance, array=data) | ||
return cm, data | ||
|
||
|
||
def _get_attrs_coords_and_data(h5fi, snap=True): | ||
"""Return the attributes, coordinates, and data array.""" | ||
cm = _get_coord_manager(h5fi, snap) | ||
attrs = _get_attr_dict(h5fi) | ||
data = h5fi["data"] | ||
return attrs, cm, data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters