Skip to content

Commit

Permalink
Fix padded dimension handling in SEG-Y serialization worker (#506)
Browse files Browse the repository at this point in the history
* Fix padded dimension handling in SEG-Y creation.

* Correct block file ordering by filtering live blocks when some are missing.

* update lockfile

* Fix block unwrapping by adding early return check.

---------

Co-authored-by: Altay Sansal <altay.sansal@tgs.com>
  • Loading branch information
tasansal and Altay Sansal authored Feb 4, 2025
1 parent 047b0bd commit 446384b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/mdio/converters/mdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ def mdio_to_segy( # noqa: C901
else:
is_block_live = is_block_live.compute(num_workers=NUM_CPUS)

n_blocks = len(is_block_live)
ordered_files = [
tmp_dir.name + f"/{block}._mdiotemp" for block in range(n_blocks)
]
live_blocks = np.where(is_block_live)[0]
ordered_files = [tmp_dir.name + f"/{block}._mdiotemp" for block in live_blocks]
ordered_files = [output_segy_path] + ordered_files

if client is not None:
Expand Down
5 changes: 5 additions & 0 deletions src/mdio/segy/blocked_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ def to_segy(
# to first (slowest) dimension. End result will be the blocks with the
# size of the outermost dimension in ascending order.
consecutive_dim_index = find_trailing_ones_index(is_block_live.numblocks)

# Shortcut if no unwrapping necessary.
if consecutive_dim_index == 1:
return is_block_live.any(axis=-1)

while consecutive_dim_index != 1:
current_chunks = is_block_live.chunks

Expand Down
8 changes: 4 additions & 4 deletions src/mdio/segy/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ def serialize_to_segy_stack(
Returns:
Live mask, as is, for combined blocks (dropped sample dimension).
"""
# Drop map_blocks padded dim
live_mask = live_mask[..., 0]
headers = headers[..., 0]

if block_info is None:
return live_mask

if np.count_nonzero(live_mask) == 0:
return live_mask

# Drop map_blocks padded dim
live_mask = live_mask[..., 0]
headers = headers[..., 0]

# Set up chunk boundaries and coordinates to write
global_num_blocks = block_info[0]["num-chunks"]
block_coords = block_info[0]["array-location"]
Expand Down

0 comments on commit 446384b

Please # to comment.