Commit 8145c9b9 authored by Jim King's avatar Jim King Committed by Jørgen Lind
Browse files

refactor tests to avoid code duplication; add check for traces with duplicate offset

parent 45e69785
......@@ -33,20 +33,6 @@ def prestack_segy() -> str:
"3D_Prestack", "ST0202R08_Gather_Time.segy")
@pytest.fixture
def default_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuard]:
"""Setup an ImportExecutor with no arg for respacing"""
ex = construct_respace_executor(output_vds, prestack_segy, None)
return ex, output_vds
@pytest.fixture
def auto_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuard]:
"""Setup an ImportExecutor with respacing set to Auto"""
ex = construct_respace_executor(output_vds, prestack_segy, "Auto")
return ex, output_vds
@pytest.fixture
def off_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuard]:
"""Setup an ImportExecutor with respacing set to Off"""
......@@ -54,13 +40,6 @@ def off_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuar
return ex, output_vds
@pytest.fixture
def on_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuard]:
"""Setup an ImportExecutor with respacing set to On"""
ex = construct_respace_executor(output_vds, prestack_segy, "On")
return ex, output_vds
@pytest.fixture
def invalid_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDSGuard]:
"""Setup an ImportExecutor with respacing set to an invalid value"""
......@@ -68,7 +47,7 @@ def invalid_executor(prestack_segy, output_vds) -> Tuple[ImportExecutor, TempVDS
return ex, output_vds
def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int]:
def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int, int]:
"""
Read all the gathers in a single inline and return stats on how many gathers have dead traces in various
regions of the gather.
......@@ -80,6 +59,7 @@ def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int]:
number of gathers with dead traces only at end of gather,
number of gathers with dead traces in multiple places,
number of gathers with no dead traces
number of consecutive duplicate offset values within a gather
)
"""
with openvds.open(vds_filename, "") as handle:
......@@ -89,6 +69,9 @@ def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int]:
trace_channel = layout.getChannelIndex("Trace")
assert trace_channel > 0, "Trace channel not found"
offset_channel = layout.getChannelIndex("Offset")
assert offset_channel > 0, "Offset channel not found"
# only read one inline; make it the middle inline
inline_index = layout.getDimensionNumSamples(3) // 2
dim2_size = layout.getDimensionNumSamples(2)
......@@ -100,18 +83,27 @@ def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int]:
end_only = 0
mixed = 0
no_dead = 0
duplicate_offsets = 0
for crossline_index in range(dim2_size):
trace_flag_request = access_manager.requestVolumeSubset((0, 0, crossline_index, inline_index, 0, 0),
(1, dim1_size, crossline_index + 1, inline_index + 1, 1,
1),
(1, dim1_size, crossline_index + 1,
inline_index + 1, 1, 1),
channel=trace_channel,
format=openvds.VolumeDataChannelDescriptor.Format.Format_U8,
dimensionsND=openvds.DimensionsND.Dimensions_012)
offset_request = access_manager.requestVolumeSubset((0, 0, crossline_index, inline_index, 0, 0),
(1, dim1_size, crossline_index + 1, inline_index + 1, 1,
1),
channel=offset_channel,
format=openvds.VolumeDataChannelDescriptor.Format.Format_U8,
dimensionsND=openvds.DimensionsND.Dimensions_012)
assert dim1_size == trace_flag_request.data.shape[0]
assert dim1_size == offset_request.data.shape[0]
# analyze trace_flag_request.data to figure out which stats counter to bump
# analyze trace flag and offset data to figure out which stats counters to bump
dead_trace_ranges = []
i = 0
......@@ -133,14 +125,19 @@ def get_gathers_stats(vds_filename: str) -> Tuple[int, int, int, int, int, int]:
start, stop = dead_trace_ranges[0]
if start == 0:
front_only += 1
elif stop == 0:
elif stop == trace_flag_request.data.shape[0] - 1:
end_only += 1
else:
middle_only += 1
else:
mixed += 1
return dim2_size, front_only, middle_only, end_only, mixed, no_dead
# Find any traces with duplicate offset values within the gather
for i in range(1, offset_request.data.shape[0]):
if offset_request.data[i] == offset_request.data[i - 1]:
duplicate_offsets += 1
return dim2_size, front_only, middle_only, end_only, mixed, no_dead, duplicate_offsets
def test_gather_spacing_invalid_arg(invalid_executor):
......@@ -152,58 +149,31 @@ def test_gather_spacing_invalid_arg(invalid_executor):
assert "unknown --respace-gathers option" in ex.output().lower()
def test_gather_spacing_default(default_executor):
ex, output_vds = default_executor
result = ex.run()
assert result == 0, ex.output()
assert Path(output_vds.filename).exists()
total, leading_only, middle_only, trailing_only, mixed, no_dead = get_gathers_stats(output_vds.filename)
assert total == 71
assert middle_only > 0
assert mixed > 0
assert trailing_only == 0
assert leading_only > 0
assert no_dead == 0
def test_gather_spacing_auto(auto_executor):
ex, output_vds = auto_executor
@pytest.mark.parametrize("respace_option", [None, "Auto", "On"])
def test_gather_spacing_with_on_variations(prestack_segy, output_vds, respace_option):
"""
Parameterized test for the different ways to execute the importer that all result in having gather
respacing turned On.
"""
ex = construct_respace_executor(output_vds, prestack_segy, respace_option)
result = ex.run()
assert result == 0, ex.output()
assert Path(output_vds.filename).exists()
total, leading_only, middle_only, trailing_only, mixed, no_dead = get_gathers_stats(output_vds.filename)
total, leading_only, middle_only, trailing_only, mixed, no_dead, duplicate_offsets =\
get_gathers_stats(output_vds.filename)
assert total == 71
assert middle_only > 0
assert mixed > 0
assert middle_only == 23
assert mixed == 0
assert trailing_only == 0
assert leading_only > 0
assert no_dead == 0
def test_gather_spacing_on(on_executor):
ex, output_vds = on_executor
result = ex.run()
assert result == 0, ex.output()
assert Path(output_vds.filename).exists()
assert leading_only == 0
assert no_dead == 48
total, leading_only, middle_only, trailing_only, mixed, no_dead = get_gathers_stats(output_vds.filename)
assert total == 71
assert middle_only > 0
assert mixed > 0
assert trailing_only == 0
assert leading_only > 0
assert no_dead == 0
# There traces with duplicate offsets in this data, and the importer must preserve all those traces
assert duplicate_offsets == 40
def test_gather_spacing_off(off_executor):
......@@ -214,11 +184,15 @@ def test_gather_spacing_off(off_executor):
assert result == 0, ex.output()
assert Path(output_vds.filename).exists()
total, leading_only, middle_only, trailing_only, mixed, no_dead = get_gathers_stats(output_vds.filename)
total, leading_only, middle_only, trailing_only, mixed, no_dead, duplicate_offsets =\
get_gathers_stats(output_vds.filename)
assert total == 71
assert trailing_only == total
assert middle_only == 0
assert mixed == 0
assert trailing_only == 23
assert leading_only == 0
assert no_dead == 0
assert no_dead == 48
# There traces with duplicate offsets in this data, and the importer must preserve all those traces
assert duplicate_offsets == 40
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment