55import os
66from typing import TYPE_CHECKING
77from typing import Any
8+ from typing import TypedDict
89from typing import cast
910
1011import numpy as np
12+ from segy import SegyFile
1113
1214if TYPE_CHECKING :
13- from segy import SegyFile
1415 from segy .arrays import HeaderArray
16+ from segy .config import SegySettings
17+ from segy .schema import SegySpec
1518 from zarr import Array
1619
1720 from mdio .core import Grid
1821
1922
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 :
2135 """Header scan worker.
2236
2337 If SegyFile is not open, it can either accept a path string or a handle that was opened in
2438 a different context manager.
2539
2640 Args:
27- segy_file: SegyFile instance.
41+ segy_kw: Arguments to open SegyFile instance.
2842 trace_range: Tuple consisting of the trace ranges to read.
2943
3044 Returns:
3145 HeaderArray parsed from SEG-Y library.
3246 """
47+ segy_file = SegyFile (** segy_kw )
48+
3349 slice_ = slice (* trace_range )
3450
3551 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
5268
5369
5470def trace_worker (
55- segy_file : SegyFile ,
71+ segy_kw : SegyFileArguments ,
5672 data_array : Array ,
5773 metadata_array : Array ,
5874 grid : Grid ,
@@ -68,7 +84,7 @@ def trace_worker(
6884 slices across the sample dimension since SEG-Y data isn't chunked, eliminating concern.
6985
7086 Args:
71- segy_file: SegyFile instance.
87+ segy_kw: Arguments to open SegyFile instance.
7288 data_array: Handle for zarr.Array we are writing traces to
7389 metadata_array: Handle for zarr.Array we are writing trace headers
7490 grid: mdio.Grid instance
@@ -78,6 +94,7 @@ def trace_worker(
7894 Partial statistics for chunk, or None
7995 """
8096 # Special case where there are no traces inside chunk.
97+ segy_file = SegyFile (** segy_kw )
8198 live_subset = grid .live_mask [chunk_indices [:- 1 ]]
8299
83100 if np .count_nonzero (live_subset ) == 0 :
0 commit comments