Skip to content

Commit 360e086

Browse files
committed
Push for debugging
1 parent accb5e8 commit 360e086

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

src/mdio/segy/_disaster_recovery_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def header(self):
2828

2929
@property
3030
def raw_header(self):
31-
return np.ascontiguousarray(self.traces.header).view("|V240")
31+
return np.ascontiguousarray(self.traces.header.copy()).view("|V240")
3232

3333
@property
3434
def sample(self):

src/mdio/segy/_workers.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,19 @@ def trace_worker( # noqa: PLR0913
139139
# For that reason, we have wrapped the accessors to provide an interface that can be removed
140140
# and not require additional changes to the below code.
141141
# NOTE: The `raw_header_key` code block should be removed in full as it will become dead code.
142-
traces = SegyFileTraceDataWrapper(segy_file, live_trace_indexes)
142+
# traces = SegyFileTraceDataWrapper(segy_file, live_trace_indexes)
143+
from copy import deepcopy
144+
header_pipeline = deepcopy(segy_file.accessors.header_decode_pipeline)
145+
segy_file.accessors.header_decode_pipeline.transforms = []
146+
traces = segy_file.trace[live_trace_indexes]
147+
143148
ds_to_write = dataset[worker_variables]
144149

145150
if header_key in worker_variables:
146151
# Create temporary array for headers with the correct shape
147152
tmp_headers = np.zeros_like(dataset[header_key])
148-
tmp_headers[not_null] = traces.header
153+
# tmp_headers[not_null] = traces.header
154+
tmp_headers[not_null] = header_pipeline.apply(traces.header.copy())
149155
# Create a new Variable object to avoid copying the temporary array
150156
# The ideal solution is to use `ds_to_write[header_key][:] = tmp_headers`
151157
# but Xarray appears to be copying memory instead of doing direct assignment.
@@ -158,7 +164,15 @@ def trace_worker( # noqa: PLR0913
158164
)
159165
if raw_header_key in worker_variables:
160166
tmp_raw_headers = np.zeros_like(dataset[raw_header_key])
161-
tmp_raw_headers[not_null] = traces.raw_header
167+
# tmp_raw_headers = np.zeros((traces.header.shape[0], 240), dtype=np.)
168+
# tmp_raw_headers[not_null] = traces.raw_header
169+
np.set_printoptions(threshold=np.inf)
170+
# print(traces.header.copy().view("|V240"))
171+
# print(len(traces.header.view("|V240")))
172+
print(len(traces.header))
173+
tmp_raw_headers[not_null] = np.ascontiguousarray(traces.header.copy()).view("|V240")
174+
# tmp_raw_headers[not_null] = traces.header.view("|V240")
175+
# tmp_raw_headers[not_null] = np.ascontiguousarray(traces.header.copy()).view("|V240")
162176

163177
ds_to_write[raw_header_key] = Variable(
164178
ds_to_write[raw_header_key].dims,

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
DEBUG_MODE = False
11+
DEBUG_MODE = True
1212

1313
# Suppress Dask's chunk balancing warning
1414
warnings.filterwarnings(

tests/integration/test_segy_import_export_masked.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,13 @@ def read_segy_trace_header(trace_index: int) -> bytes:
547547
segy_trace_idx = 0
548548
flat_mask = trace_mask.ravel()
549549
flat_raw_headers = raw_headers_data.ravel() # Flatten to 1D array of 240-byte header records
550+
print(f"Flat mask shape: {flat_mask.shape}")
551+
552+
operation = 'w'
550553

551554
for grid_idx in range(flat_mask.size):
552555
if not flat_mask[grid_idx]:
556+
print(f"Skipping trace {grid_idx} because it is masked")
553557
continue
554558

555559
# Get MDIO header as bytes - convert single header record to bytes
@@ -561,5 +565,58 @@ def read_segy_trace_header(trace_index: int) -> bytes:
561565
segy_header_bytes = np.frombuffer(segy_raw_header_bytes, dtype=np.uint8)
562566

563567
# Compare byte-by-byte
564-
assert_array_equal(mdio_header_bytes, segy_header_bytes)
568+
# Write hexdumps to separate files for analysis
569+
def hexdump_to_string(data: bytes, title: str) -> str:
570+
"""Create hexdump string."""
571+
lines = [f"{title}", "=" * len(title), ""]
572+
573+
for i in range(0, len(data), 16):
574+
# Address
575+
addr = i
576+
hex_part = ""
577+
ascii_part = ""
578+
579+
# Process 16 bytes at a time
580+
for j in range(16):
581+
if i + j < len(data):
582+
byte_val = data[i + j]
583+
hex_part += f"{byte_val:02x} "
584+
ascii_part += chr(byte_val) if 32 <= byte_val <= 126 else "."
585+
else:
586+
hex_part += " "
587+
ascii_part += " "
588+
589+
lines.append(f"{addr:08x}: {hex_part} |{ascii_part}|")
590+
591+
return "\n".join(lines)
592+
593+
# Generate filenames for this test case
594+
segy_filename = f"segy_headers_{grid_conf.name}.txt"
595+
mdio_filename = f"mdio_headers_{grid_conf.name}.txt"
596+
597+
# Append SEG-Y hexdump to file
598+
with open(segy_filename, operation) as f:
599+
if segy_trace_idx == 0:
600+
f.write("") # Start fresh for first trace
601+
else:
602+
f.write("\n\n") # Add spacing between traces
603+
f.write(hexdump_to_string(segy_header_bytes,
604+
f"SEG-Y Header - {grid_conf.name} Trace {segy_trace_idx} (240 bytes)"))
605+
606+
# Append MDIO hexdump to file
607+
with open(mdio_filename, operation) as f:
608+
if segy_trace_idx == 0:
609+
f.write("") # Start fresh for first trace
610+
else:
611+
f.write("\n\n") # Add spacing between traces
612+
f.write(hexdump_to_string(mdio_header_bytes,
613+
f"MDIO Raw Header - {grid_conf.name} Trace {segy_trace_idx} (240 bytes)"))
614+
operation = 'a'
615+
616+
if segy_trace_idx == 0:
617+
print(f"\nHeader hexdumps being written for {grid_conf.name}:")
618+
print(f" SEG-Y: {segy_filename}")
619+
print(f" MDIO: {mdio_filename}")
620+
621+
565622
segy_trace_idx += 1

0 commit comments

Comments
 (0)