Skip to content

Commit 49b25b3

Browse files
committed
Avoid full grid_map pickler overhead for every ingestion chunk
1 parent a80b42e commit 49b25b3

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/mdio/segy/_workers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from mdio.segy.file import SegyFileWrapper
1515

1616
if TYPE_CHECKING:
17+
from numpy.typing import NDArray
1718
from segy import SegyFile
1819
from zarr import Array as zarr_Array
1920

@@ -74,7 +75,7 @@ def trace_worker( # noqa: PLR0913
7475
header_array: zarr_Array | None,
7576
raw_header_array: zarr_Array | None,
7677
region: dict[str, slice],
77-
grid_map: zarr_Array,
78+
local_grid_map: NDArray,
7879
) -> SummaryStatistics | None:
7980
"""Writes a subset of traces from a region of the dataset of Zarr file.
8081
@@ -84,7 +85,7 @@ def trace_worker( # noqa: PLR0913
8485
header_array: Zarr array for writing trace headers (or None if not needed).
8586
raw_header_array: Zarr array for writing raw headers (or None if not needed).
8687
region: Region of the dataset to write to.
87-
grid_map: Zarr array mapping live traces to their positions in the dataset.
88+
local_grid_map: Sliced numpy array mapping live traces to their positions.
8889
8990
Returns:
9091
SummaryStatistics object containing statistics about the written traces.
@@ -94,7 +95,6 @@ def trace_worker( # noqa: PLR0913
9495
zarr_config.set({"threading.max_workers": 1})
9596

9697
region_slices = tuple(region.values())
97-
local_grid_map = grid_map[region_slices[:-1]] # minus last (vertical) axis
9898

9999
# The dtype.max is the sentinel value for the grid map.
100100
# Normally, this is uint32, but some grids need to be promoted to uint64.

src/mdio/segy/blocked_io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,17 @@ def to_zarr( # noqa: PLR0913, PLR0915
113113
with executor:
114114
futures = []
115115
for region in chunk_iter:
116-
# Pass zarr array handles directly to workers
116+
region_slices = tuple(region.values())
117+
local_grid_map = grid_map[region_slices[:-1]]
118+
# Pass zarr array handles and local grid map slice to workers
117119
future = executor.submit(
118120
trace_worker,
119121
segy_file,
120122
data_array,
121123
header_array,
122124
raw_header_array,
123125
region,
124-
grid_map,
126+
local_grid_map,
125127
)
126128
futures.append(future)
127129

0 commit comments

Comments
 (0)