@@ -156,7 +156,11 @@ def _scan_for_headers(
156156 """Extract trace dimensions and index headers from the SEG-Y file.
157157
158158 This is an expensive operation.
159- It scans the SEG-Y file in chunks by using ProcessPoolExecutor
159+ It scans the SEG-Y file in chunks by using ProcessPoolExecutor.
160+
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.
160164 """
161165 full_chunk_shape = template .full_chunk_shape
162166 segy_dimensions , chunk_size , segy_headers = get_grid_plan (
@@ -167,13 +171,19 @@ def _scan_for_headers(
167171 chunksize = full_chunk_shape ,
168172 grid_overrides = grid_overrides ,
169173 )
174+
175+ # After applying grid overrides to the template, chunk sizes should match
176+ # If they don't match, it means the template wasn't properly updated
170177 if full_chunk_shape != chunk_size :
171- # TODO(Dmitriy): implement grid overrides
172- # https://github.com/TGSAI/mdio-python/issues/585
173- # The returned 'chunksize' is used only for grid_overrides. We will need to use it when full
174- # support for grid overrides is implemented
175- err = "Support for changing full_chunk_shape in grid overrides is not yet implemented"
176- raise NotImplementedError (err )
178+ logger .warning (
179+ "Chunk shape mismatch: template has %s but grid_plan returned %s. "
180+ "Using grid_plan chunk shape." ,
181+ full_chunk_shape ,
182+ chunk_size ,
183+ )
184+ # Update the template's chunk shape to match what grid_plan returned
185+ template ._var_chunk_shape = chunk_size
186+
177187 return segy_dimensions , segy_headers
178188
179189
@@ -562,6 +572,17 @@ def segy_to_mdio( # noqa PLR0913
562572 )
563573 grid = _build_and_check_grid (segy_dimensions , segy_file_info , segy_headers )
564574
575+ # Update template dimensions to match the actual grid dimensions after grid overrides
576+ # The chunk shape was already updated in _scan_for_headers, we just need to fix dimensions
577+ actual_spatial_dims = tuple (grid .dim_names [:- 1 ]) # All dims except the vertical/time dimension
578+ if mdio_template .spatial_dimension_names != actual_spatial_dims :
579+ logger .info (
580+ "Adjusting template dimensions from %s to %s to match grid after overrides" ,
581+ mdio_template .spatial_dimension_names ,
582+ actual_spatial_dims ,
583+ )
584+ mdio_template ._dim_names = actual_spatial_dims + (mdio_template .trace_domain ,)
585+
565586 _ , non_dim_coords = _get_coordinates (grid , segy_headers , mdio_template )
566587 header_dtype = to_structured_type (segy_spec .trace .header .dtype )
567588
0 commit comments