@@ -147,31 +147,27 @@ def grid_density_qc(grid: Grid, num_traces: int) -> None:
147147 raise GridTraceSparsityError (grid .shape , num_traces , msg )
148148
149149
150- def _scan_for_headers (
151- segy_file_kwargs : SegyFileArguments ,
152- segy_file_info : SegyFileInfo ,
150+ def _update_template_from_grid_overrides (
153151 template : AbstractDatasetTemplate ,
154- grid_overrides : dict [str , Any ] | None = None ,
155- ) -> tuple [list [Dimension ], SegyHeaderArray ]:
156- """Extract trace dimensions and index headers from the SEG-Y file.
152+ grid_overrides : dict [str , Any ] | None ,
153+ segy_dimensions : list [Dimension ],
154+ full_chunk_shape : tuple [int , ...],
155+ chunk_size : tuple [int , ...],
156+ ) -> None :
157+ """Update template attributes to match grid plan results after grid overrides.
157158
158- This is an expensive operation.
159- It scans the SEG-Y file in chunks by using ProcessPoolExecutor.
159+ This function modifies the template in-place to reflect changes from grid overrides:
160+ - Updates chunk shape if it changed due to overrides
161+ - Updates dimension names if they changed due to overrides
162+ - Adds non-binned dimensions as coordinates for NonBinned override
160163
161- Note:
162- If grid_overrides are applied to the template before calling this function,
163- the chunk_size returned from get_grid_plan should match the template's chunk shape.
164+ Args:
165+ template: The template to update
166+ grid_overrides: Grid override configuration
167+ segy_dimensions: Dimensions returned from grid planning
168+ full_chunk_shape: Original template chunk shape
169+ chunk_size: Chunk size returned from grid planning
164170 """
165- full_chunk_shape = template .full_chunk_shape
166- segy_dimensions , chunk_size , segy_headers = get_grid_plan (
167- segy_file_kwargs = segy_file_kwargs ,
168- segy_file_info = segy_file_info ,
169- return_headers = True ,
170- template = template ,
171- chunksize = full_chunk_shape ,
172- grid_overrides = grid_overrides ,
173- )
174-
175171 # Update template to match grid_plan results after grid overrides
176172 if full_chunk_shape != chunk_size :
177173 logger .debug (
@@ -205,6 +201,40 @@ def _scan_for_headers(
205201 if to_add :
206202 template ._logical_coord_names = template ._logical_coord_names + to_add
207203
204+
205+ def _scan_for_headers (
206+ segy_file_kwargs : SegyFileArguments ,
207+ segy_file_info : SegyFileInfo ,
208+ template : AbstractDatasetTemplate ,
209+ grid_overrides : dict [str , Any ] | None = None ,
210+ ) -> tuple [list [Dimension ], SegyHeaderArray ]:
211+ """Extract trace dimensions and index headers from the SEG-Y file.
212+
213+ This is an expensive operation.
214+ It scans the SEG-Y file in chunks by using ProcessPoolExecutor.
215+
216+ Note:
217+ If grid_overrides are applied to the template before calling this function,
218+ the chunk_size returned from get_grid_plan should match the template's chunk shape.
219+ """
220+ full_chunk_shape = template .full_chunk_shape
221+ segy_dimensions , chunk_size , segy_headers = get_grid_plan (
222+ segy_file_kwargs = segy_file_kwargs ,
223+ segy_file_info = segy_file_info ,
224+ return_headers = True ,
225+ template = template ,
226+ chunksize = full_chunk_shape ,
227+ grid_overrides = grid_overrides ,
228+ )
229+
230+ _update_template_from_grid_overrides (
231+ template = template ,
232+ grid_overrides = grid_overrides ,
233+ segy_dimensions = segy_dimensions ,
234+ full_chunk_shape = full_chunk_shape ,
235+ chunk_size = chunk_size ,
236+ )
237+
208238 return segy_dimensions , segy_headers
209239
210240
0 commit comments