2525if TYPE_CHECKING :
2626 from numpy .typing import NDArray
2727
28+ SAMPLES_PER_TRACE = 1501
2829
2930class TestDisasterRecoveryWrapper :
3031 """Test cases for disaster recovery wrapper functionality."""
@@ -123,8 +124,7 @@ def extract_header_bytes_from_file(
123124 header_offset = 3600
124125
125126 # Each trace: 240 byte header + samples
126- # trace_size = 240 + 1501 * 4 # Assuming 1501 samples, 4 bytes each
127- trace_size = 240 + 1 * 4 # Assuming 1 sample, 4 bytes each
127+ trace_size = 240 + SAMPLES_PER_TRACE * 4 # samples * 4 bytes each
128128 trace_offset = header_offset + trace_index * trace_size
129129
130130 f .seek (trace_offset + byte_start - 1 ) # SEGY is 1-based
@@ -144,8 +144,7 @@ def test_header_validation_configurations(
144144
145145 # Create test SEGY file
146146 num_traces = 10
147- # samples_per_trace = 1501
148- samples_per_trace = 1
147+ samples_per_trace = SAMPLES_PER_TRACE
149148
150149 spec = self .create_test_segy_file (
151150 spec = basic_segy_spec ,
@@ -178,21 +177,39 @@ def test_header_validation_configurations(
178177 segy_path , trace_idx , 193 , 4
179178 )
180179
181- def extract_bytes_vectorized (data , start_byte , end_byte ):
182- all_bytes = np .frombuffer (data .tobytes (), dtype = np .uint8 )
183- bytes_per_element = data .dtype .intemsize
184- reshaped = all_bytes .reshape (- 1 , bytes_per_element )
185- return reshaped [:, start_byte :end_byte ]
186-
187180 # Convert raw headers to bytes for comparison
188181 if raw_headers is not None :
189- # Extract inline and crossline from raw headers
190- raw_inline_bytes = extract_bytes_vectorized (
191- raw_headers , 189 , 193
192- )[:4 ]
193- raw_crossline_bytes = extract_bytes_vectorized (
194- raw_headers , 193 , 197
195- )[:4 ]
182+ # Extract from raw headers
183+ # Note: We need to extract bytes directly from the structured array to preserve endianness
184+ # Getting a scalar and calling .tobytes() loses endianness information
185+ if raw_headers .ndim == 0 :
186+ # Single trace case
187+ raw_data_bytes = raw_headers .tobytes ()
188+ inline_offset = raw_headers .dtype .fields ['inline' ][1 ]
189+ crossline_offset = raw_headers .dtype .fields ['crossline' ][1 ]
190+ inline_size = raw_headers .dtype .fields ['inline' ][0 ].itemsize
191+ crossline_size = raw_headers .dtype .fields ['crossline' ][0 ].itemsize
192+
193+ raw_inline_bytes = np .frombuffer (
194+ raw_data_bytes [inline_offset :inline_offset + inline_size ], dtype = np .uint8
195+ )
196+ raw_crossline_bytes = np .frombuffer (
197+ raw_data_bytes [crossline_offset :crossline_offset + crossline_size ], dtype = np .uint8
198+ )
199+ else :
200+ # Multiple traces case - this test uses single trace index, so extract that trace
201+ raw_data_bytes = raw_headers [0 :1 ].tobytes () # Extract first trace
202+ inline_offset = raw_headers .dtype .fields ['inline' ][1 ]
203+ crossline_offset = raw_headers .dtype .fields ['crossline' ][1 ]
204+ inline_size = raw_headers .dtype .fields ['inline' ][0 ].itemsize
205+ crossline_size = raw_headers .dtype .fields ['crossline' ][0 ].itemsize
206+
207+ raw_inline_bytes = np .frombuffer (
208+ raw_data_bytes [inline_offset :inline_offset + inline_size ], dtype = np .uint8
209+ )
210+ raw_crossline_bytes = np .frombuffer (
211+ raw_data_bytes [crossline_offset :crossline_offset + crossline_size ], dtype = np .uint8
212+ )
196213
197214 print (f"Transformed headers: { transformed_headers .tobytes ()} " )
198215 print (f"Raw headers: { raw_headers .tobytes ()} " )
@@ -217,8 +234,7 @@ def test_header_validation_no_transforms(
217234
218235 # Create test SEGY file
219236 num_traces = 5
220- # samples_per_trace = 1501
221- samples_per_trace = 1
237+ samples_per_trace = SAMPLES_PER_TRACE
222238
223239 spec = self .create_test_segy_file (
224240 spec = basic_segy_spec ,
@@ -266,8 +282,7 @@ def test_multiple_traces_validation(
266282
267283 # Create test SEGY file with more traces
268284 num_traces = 25 # 5x5 grid
269- # samples_per_trace = 1501
270- samples_per_trace = 1
285+ samples_per_trace = SAMPLES_PER_TRACE
271286
272287 spec = self .create_test_segy_file (
273288 spec = basic_segy_spec ,
@@ -367,8 +382,7 @@ def test_different_index_types(
367382
368383 # Create test SEGY file
369384 num_traces = 10
370- # samples_per_trace = 1501
371- samples_per_trace = 1
385+ samples_per_trace = SAMPLES_PER_TRACE
372386
373387 spec = self .create_test_segy_file (
374388 spec = basic_segy_spec ,
0 commit comments