11"""End to end testing for SEG-Y to MDIO conversion and back."""
22
3- import os
43from os .path import getsize
5- from typing import List
64
75import dask
86import numpy as np
1917dask .config .set (scheduler = "synchronous" )
2018
2119
22- def create_4d_segy (
23- file_path : str ,
24- num_samples : int ,
25- fldrs : List ,
26- cables : List ,
27- num_traces : List ,
28- chan_header_type : str = "a" ,
29- ):
30- """Dummy 4D segy file for use in tests."""
31- import segyio
32-
33- spec = segyio .spec ()
34- d = os .path .join (file_path , "data" )
35- os .makedirs (d , exist_ok = True )
36- segy_file = os .path .join (d , f"4d_type_{ chan_header_type } .sgy" )
37- spec .format = 1
38- spec .samples = range (num_samples )
39-
40- trace_count = len (fldrs ) * np .sum (num_traces )
41- spec .tracecount = trace_count
42- spec .endian = "big"
43-
44- with segyio .create (segy_file , spec ) as f :
45- trno = 0
46-
47- tracf = 0
48- for fldr in fldrs :
49- if chan_header_type == "b" :
50- tracf = 1
51- # TODO: Add strict=True and remove noqa when min supported Python is 3.10
52- for cable , length in zip (cables , num_traces ): # noqa: B905
53- if chan_header_type == "a" :
54- tracf = 1
55- for _i in range (length ):
56- # segyio names and byte locations for headers can be found at:
57- # https://segyio.readthedocs.io/en/latest/segyio.html
58- # fldr is byte location 9 - shot 4 byte
59- # ep is byte location 17 - shot 4 byte
60- # stae is byte location 137 - cable 2 byte
61- # tracf is byte location 13 - channel 4 byte
62-
63- f .header [trno ].update (
64- offset = 1 ,
65- fldr = fldr ,
66- ep = fldr ,
67- stae = cable ,
68- tracf = tracf ,
69- )
70-
71- trace = np .linspace (
72- start = fldr , stop = fldr + 1 , num = len (spec .samples )
73- )
74- f .trace [trno ] = trace
75- trno += 1
76- tracf += 1
77-
78- f .bin .update ()
79- return segy_file
80-
81-
8220@pytest .mark .parametrize ("header_locations" , [(17 , 137 , 13 )])
8321@pytest .mark .parametrize ("header_names" , [("shot" , "cable" , "channel" )])
8422@pytest .mark .parametrize ("header_types" , [("int32" , "int16" , "int32" )])
@@ -92,7 +30,7 @@ class TestImport4D:
9230
9331 def test_import_4d_segy (
9432 self ,
95- tmp_path ,
33+ segy_mock_4d_shots ,
9634 zarr_tmp ,
9735 header_locations ,
9836 header_names ,
@@ -102,18 +40,7 @@ def test_import_4d_segy(
10240 chan_header_type ,
10341 ):
10442 """Test importing a SEG-Y file to MDIO."""
105- num_samples = 25
106- fldrs = [2 , 3 , 5 ]
107- cables = [0 , 101 , 201 , 301 ]
108- num_traces = [1 , 5 , 7 , 5 ]
109- segy_path = create_4d_segy (
110- tmp_path ,
111- num_samples = num_samples ,
112- fldrs = fldrs ,
113- cables = cables ,
114- num_traces = num_traces ,
115- chan_header_type = chan_header_type ,
116- )
43+ segy_path = segy_mock_4d_shots [chan_header_type ]
11744
11845 segy_to_mdio (
11946 segy_path = segy_path ,
@@ -127,25 +54,33 @@ def test_import_4d_segy(
12754 grid_overrides = grid_overrides ,
12855 )
12956
57+ # Expected values
58+ num_samples = 25
59+ shots = [2 , 3 , 5 ]
60+ cables = [0 , 101 , 201 , 301 ]
61+ receivers_per_cable = [1 , 5 , 7 , 5 ]
62+
13063 # QC mdio output
13164 mdio = MDIOReader (zarr_tmp .__str__ (), access_pattern = "0123" )
13265 assert mdio .binary_header ["Samples" ] == num_samples
13366 grid = mdio .grid
13467
135- assert grid .select_dim (header_names [0 ]) == Dimension (fldrs , header_names [0 ])
68+ assert grid .select_dim (header_names [0 ]) == Dimension (shots , header_names [0 ])
13669 assert grid .select_dim (header_names [1 ]) == Dimension (cables , header_names [1 ])
13770
13871 if "b" in chan_header_type and grid_overrides is None :
72+ print ()
73+ print (grid .select_dim (header_names [2 ]))
13974 assert grid .select_dim (header_names [2 ]) == Dimension (
140- range (1 , np .sum (num_traces ) + 1 ), header_names [2 ]
75+ range (1 , np .sum (receivers_per_cable ) + 1 ), header_names [2 ]
14176 )
14277 else :
14378 assert grid .select_dim (header_names [2 ]) == Dimension (
144- range (1 , np .amax (num_traces ) + 1 ), header_names [2 ]
79+ range (1 , np .amax (receivers_per_cable ) + 1 ), header_names [2 ]
14580 )
146- assert grid . select_dim ( "sample" ) == Dimension (
147- range (0 , num_samples , 1 ), "sample"
148- )
81+
82+ samples_exp = Dimension ( range (0 , num_samples , 1 ), "sample" )
83+ assert grid . select_dim ( "sample" ) == samples_exp
14984
15085
15186@pytest .mark .parametrize ("header_locations" , [(17 , 13 )])
0 commit comments