5
5
import os
6
6
from typing import TYPE_CHECKING
7
7
from typing import Any
8
+ from typing import TypedDict
8
9
from typing import cast
9
10
10
11
import numpy as np
12
+ from segy import SegyFile
11
13
12
14
if TYPE_CHECKING :
13
- from segy import SegyFile
14
15
from segy .arrays import HeaderArray
16
+ from segy .config import SegySettings
17
+ from segy .schema import SegySpec
15
18
from zarr import Array
16
19
17
20
from mdio .core import Grid
18
21
19
22
20
- def header_scan_worker (segy_file : SegyFile , trace_range : tuple [int , int ]) -> HeaderArray :
23
+ class SegyFileArguments (TypedDict ):
24
+ """Arguments to open SegyFile instance creation."""
25
+
26
+ url : str
27
+ spec : SegySpec | None
28
+ settings : SegySettings | None
29
+
30
+
31
+ def header_scan_worker (
32
+ segy_kw : SegyFileArguments ,
33
+ trace_range : tuple [int , int ],
34
+ ) -> HeaderArray :
21
35
"""Header scan worker.
22
36
23
37
If SegyFile is not open, it can either accept a path string or a handle that was opened in
24
38
a different context manager.
25
39
26
40
Args:
27
- segy_file: SegyFile instance.
41
+ segy_kw: Arguments to open SegyFile instance.
28
42
trace_range: Tuple consisting of the trace ranges to read.
29
43
30
44
Returns:
31
45
HeaderArray parsed from SEG-Y library.
32
46
"""
47
+ segy_file = SegyFile (** segy_kw )
48
+
33
49
slice_ = slice (* trace_range )
34
50
35
51
cloud_native_mode = os .getenv ("MDIO__IMPORT__CLOUD_NATIVE" , default = "False" )
@@ -52,7 +68,7 @@ def header_scan_worker(segy_file: SegyFile, trace_range: tuple[int, int]) -> Hea
52
68
53
69
54
70
def trace_worker (
55
- segy_file : SegyFile ,
71
+ segy_kw : SegyFileArguments ,
56
72
data_array : Array ,
57
73
metadata_array : Array ,
58
74
grid : Grid ,
@@ -68,7 +84,7 @@ def trace_worker(
68
84
slices across the sample dimension since SEG-Y data isn't chunked, eliminating concern.
69
85
70
86
Args:
71
- segy_file: SegyFile instance.
87
+ segy_kw: Arguments to open SegyFile instance.
72
88
data_array: Handle for zarr.Array we are writing traces to
73
89
metadata_array: Handle for zarr.Array we are writing trace headers
74
90
grid: mdio.Grid instance
@@ -78,6 +94,7 @@ def trace_worker(
78
94
Partial statistics for chunk, or None
79
95
"""
80
96
# Special case where there are no traces inside chunk.
97
+ segy_file = SegyFile (** segy_kw )
81
98
live_subset = grid .live_mask [chunk_indices [:- 1 ]]
82
99
83
100
if np .count_nonzero (live_subset ) == 0 :
0 commit comments