Skip to content

Commit 3849dd4

Browse files
authored
Add verification to ingestion tests with procedural SEG-Y files (TGSAI#594)
* add more informative error for missing dimension * add test to verify ingestion before export * update invalid dimension name test
1 parent bf6202a commit 3849dd4

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/mdio/core/grid.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def __setitem__(self, key: int, value: Dimension) -> None:
7676

7777
def select_dim(self, name: str) -> Dimension:
7878
"""Get a dimension by name."""
79+
if name not in self.dim_names:
80+
msg = f"Invalid dimension name '{name}'. Available dimensions: {self.dim_names}."
81+
raise ValueError(msg)
7982
index = self.dim_names.index(name)
8083
return self.dims[index]
8184

tests/integration/test_segy_import_export_masked.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,38 @@ def test_import(self, test_conf: MaskedExportConfig, export_masked_path: Path) -
261261
overwrite=True,
262262
)
263263

264+
def test_ingested_mdio(self, test_conf: MaskedExportConfig, export_masked_path: Path) -> None:
265+
"""Verify if ingested data is correct."""
266+
grid_conf, segy_factory_conf, segy_to_mdio_conf, _ = test_conf
267+
mdio_path = export_masked_path / f"{grid_conf.name}.mdio"
268+
269+
ndim = len(segy_to_mdio_conf.chunks)
270+
access_pattern = "".join(map(str, range(ndim)))
271+
actual_reader = MDIOReader(mdio_path, access_pattern=access_pattern, return_metadata=True)
272+
273+
# Test dimensions and ingested dimension headers
274+
expected_dims = grid_conf.dims
275+
for expected_dim in expected_dims:
276+
actual_dim = actual_reader.grid.select_dim(expected_dim.name)
277+
assert expected_dim.name == actual_dim.name
278+
assert expected_dim.size == actual_dim.coords.size
279+
assert expected_dim.start == actual_dim.coords[0]
280+
281+
num_traces = np.prod(actual_reader.live_mask.shape)
282+
283+
# Read all the data into memory
284+
live, headers, traces = actual_reader[..., 0]
285+
286+
# Ensure live mask is full
287+
np.testing.assert_equal(live, True)
288+
289+
# TODO(Altay): Check if all dimension headers are correct
290+
# https://github.com/TGSAI/mdio-python/issues/593
291+
292+
# Check if all trace values are correct (e.g. == sequential 1 to N)
293+
np.testing.assert_array_equal(traces.ravel(), np.arange(1, num_traces + 1))
294+
295+
264296
def test_export(self, test_conf: MaskedExportConfig, export_masked_path: Path) -> None:
265297
"""Test export of an n-D MDIO file back to SEG-Y."""
266298
grid_conf, segy_factory_conf, segy_to_mdio_conf, _ = test_conf

tests/unit/test_accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_wrong_size_index(self, mock_reader: MDIOReader) -> None:
133133

134134
def test_wrong_index(self, mock_reader: MDIOReader) -> None:
135135
"""If user asks for an index that doesn't exist."""
136-
with pytest.raises(ValueError, match="not in tuple"):
136+
with pytest.raises(ValueError, match="Invalid dimension name"):
137137
mock_reader.coord_to_index(0, dimensions="non_existent")
138138

139139
def test_mdio_exists(self, mock_reader: MDIOReader) -> None:

0 commit comments

Comments
 (0)