77from typing import TYPE_CHECKING
88
99import numpy as np
10- import zarr
1110
12- from mdio .constants import UINT32_MAX
1311from mdio .core import Dimension
1412from mdio .core .serialization import Serializer
15- from mdio .core .utils_write import get_constrained_chunksize
1613
1714if TYPE_CHECKING :
15+ import zarr
1816 from segy .arrays import HeaderArray
1917 from zarr import Array as ZarrArray
2018
@@ -112,8 +110,8 @@ def build_map(self, index_headers: HeaderArray) -> None:
112110 """Compute per-trace grid coordinates (lazy map).
113111
114112 Instead of allocating a full `self.map` and `self.live_mask`, this computes, for each trace,
115- its integer index along each dimension (excluding the final sample dimension) and stores them in
116- `self.header_index_arrays`. The full mapping can then be derived chunk-by-chunk when writing.
113+ its integer index along each dimension (excluding the sample dimension) and stores them in
114+ `self.header_index_arrays`. The full mapping can then be derived chunkwise when writing.
117115
118116 Args:
119117 index_headers: Header array containing dimension indices (length = number of traces).
@@ -126,8 +124,8 @@ def build_map(self, index_headers: HeaderArray) -> None:
126124 # Cast to uint32.
127125 idx_arrays : list [np .ndarray ] = []
128126 for dim in self .dims [:- 1 ]:
129- hdr_vals = index_headers [dim .name ] # shape: (num_traces,)
130- coords = np .searchsorted (dim , hdr_vals ) # integer indices
127+ hdr_vals = index_headers [dim .name ] # shape: (num_traces,)
128+ coords = np .searchsorted (dim , hdr_vals ) # integer indices
131129 coords = coords .astype (np .uint32 )
132130 idx_arrays .append (coords )
133131
@@ -136,7 +134,6 @@ def build_map(self, index_headers: HeaderArray) -> None:
136134
137135 # We no longer allocate `self.map` or `self.live_mask` here.
138136 # The full grid shape is `self.shape`, but mapping is done lazily per chunk.
139- return
140137
141138 def get_traces_for_chunk (self , chunk_slices : tuple [slice , ...]) -> np .ndarray :
142139 """Return all trace IDs whose grid-coordinates fall inside the given chunk slices.
@@ -157,16 +154,15 @@ def get_traces_for_chunk(self, chunk_slices: tuple[slice, ...]) -> np.ndarray:
157154 arr = self .header_index_arrays [dim_idx ] # shape: (num_traces,)
158155 start , stop = sl .start , sl .stop
159156 if start is not None :
160- mask &= ( arr >= start )
157+ mask &= arr >= start
161158 if stop is not None :
162- mask &= ( arr < stop )
159+ mask &= arr < stop
163160 if not mask .any ():
164161 # No traces remain after this dimension's filtering
165162 return np .empty ((0 ,), dtype = np .uint32 )
166163
167164 # Gather the trace IDs that survived all dimension tests
168- trace_ids = np .nonzero (mask )[0 ].astype (np .uint32 )
169- return trace_ids
165+ return np .nonzero (mask )[0 ].astype (np .uint32 )
170166
171167
172168class GridSerializer (Serializer ):
0 commit comments