Skip to content

Commit 076cf60

Browse files
BrianMichelltasansal
authored andcommitted
Extract template update logic
1 parent e71d379 commit 076cf60

File tree

1 file changed

+51
-21
lines changed

1 file changed

+51
-21
lines changed

src/mdio/converters/segy.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,31 +134,27 @@ def grid_density_qc(grid: Grid, num_traces: int) -> None:
134134
raise GridTraceSparsityError(grid.shape, num_traces, msg)
135135

136136

137-
def _scan_for_headers(
138-
segy_file_kwargs: SegyFileArguments,
139-
segy_file_info: SegyFileInfo,
137+
def _update_template_from_grid_overrides(
140138
template: AbstractDatasetTemplate,
141-
grid_overrides: dict[str, Any] | None = None,
142-
) -> tuple[list[Dimension], SegyHeaderArray]:
143-
"""Extract trace dimensions and index headers from the SEG-Y file.
139+
grid_overrides: dict[str, Any] | None,
140+
segy_dimensions: list[Dimension],
141+
full_chunk_shape: tuple[int, ...],
142+
chunk_size: tuple[int, ...],
143+
) -> None:
144+
"""Update template attributes to match grid plan results after grid overrides.
144145
145-
This is an expensive operation.
146-
It scans the SEG-Y file in chunks by using ProcessPoolExecutor.
146+
This function modifies the template in-place to reflect changes from grid overrides:
147+
- Updates chunk shape if it changed due to overrides
148+
- Updates dimension names if they changed due to overrides
149+
- Adds non-binned dimensions as coordinates for NonBinned override
147150
148-
Note:
149-
If grid_overrides are applied to the template before calling this function,
150-
the chunk_size returned from get_grid_plan should match the template's chunk shape.
151+
Args:
152+
template: The template to update
153+
grid_overrides: Grid override configuration
154+
segy_dimensions: Dimensions returned from grid planning
155+
full_chunk_shape: Original template chunk shape
156+
chunk_size: Chunk size returned from grid planning
151157
"""
152-
full_chunk_shape = template.full_chunk_shape
153-
segy_dimensions, chunk_size, segy_headers = get_grid_plan(
154-
segy_file_kwargs=segy_file_kwargs,
155-
segy_file_info=segy_file_info,
156-
return_headers=True,
157-
template=template,
158-
chunksize=full_chunk_shape,
159-
grid_overrides=grid_overrides,
160-
)
161-
162158
# Update template to match grid_plan results after grid overrides
163159
if full_chunk_shape != chunk_size:
164160
logger.debug(
@@ -192,6 +188,40 @@ def _scan_for_headers(
192188
if to_add:
193189
template._logical_coord_names = template._logical_coord_names + to_add
194190

191+
192+
def _scan_for_headers(
193+
segy_file_kwargs: SegyFileArguments,
194+
segy_file_info: SegyFileInfo,
195+
template: AbstractDatasetTemplate,
196+
grid_overrides: dict[str, Any] | None = None,
197+
) -> tuple[list[Dimension], SegyHeaderArray]:
198+
"""Extract trace dimensions and index headers from the SEG-Y file.
199+
200+
This is an expensive operation.
201+
It scans the SEG-Y file in chunks by using ProcessPoolExecutor.
202+
203+
Note:
204+
If grid_overrides are applied to the template before calling this function,
205+
the chunk_size returned from get_grid_plan should match the template's chunk shape.
206+
"""
207+
full_chunk_shape = template.full_chunk_shape
208+
segy_dimensions, chunk_size, segy_headers = get_grid_plan(
209+
segy_file_kwargs=segy_file_kwargs,
210+
segy_file_info=segy_file_info,
211+
return_headers=True,
212+
template=template,
213+
chunksize=full_chunk_shape,
214+
grid_overrides=grid_overrides,
215+
)
216+
217+
_update_template_from_grid_overrides(
218+
template=template,
219+
grid_overrides=grid_overrides,
220+
segy_dimensions=segy_dimensions,
221+
full_chunk_shape=full_chunk_shape,
222+
chunk_size=chunk_size,
223+
)
224+
195225
return segy_dimensions, segy_headers
196226

197227

0 commit comments

Comments
 (0)