Skip to content

Commit 9efd351

Browse files
authored
Fix tensorstore empty array handling (#326)
* Fix tensorstore empty array handling - Add validation for empty arrays in _save_transformed before tensorstore write - Skip write operations for empty arrays with warning messages - Add comprehensive error handling with detailed diagnostics for tensorstore failures - Improve error messages to include array shapes, sizes, and tensorstore details This resolves the ValueError: Error aligning dimensions issue when empty arrays are passed to tensorstore write operations. * Add empty results check to prevent tensorstore alignment errors Adds validation in apply_transform_to_tczyx_and_save() to check for empty results dictionary before calling _save_transformed(). When no valid time points are available, logs diagnostic message and skips write operation instead of attempting to write empty arrays to tensorstore, which causes alignment dimension mismatches. * Revert "Fix tensorstore empty array handling" This reverts commit 65c9ddb. * better handling of output_time_indices * style
1 parent ffc8a9d commit 9efd351

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

iohub/ngff/utils.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,8 @@ def apply_transform_to_tczyx_and_save(
407407
Additional arguments to pass to the function.
408408
"""
409409
input_time_indices = _slice_to_list(input_time_indices)
410-
output_time_indices = _slice_to_list(output_time_indices)
411410
results = {}
412-
for input_time_index in input_time_indices:
411+
for i, input_time_index in enumerate(input_time_indices):
413412
result = _apply_transform_to_czyx(
414413
func,
415414
input_position_path=input_position_path,
@@ -418,19 +417,28 @@ def apply_transform_to_tczyx_and_save(
418417
**kwargs,
419418
)
420419
if result is not None:
421-
results[input_time_index] = result
420+
results[i] = result
422421
else:
423422
_echo_finished(
424423
input_time=input_time_index,
425424
output_channel=output_channel_indices,
426425
skipped=True,
427426
)
428-
_save_transformed(
429-
transformed=list(results.values()),
430-
output_position_path=output_position_path,
431-
output_channel_indices=output_channel_indices,
432-
output_time_indices=list(results.keys()),
433-
)
427+
if results:
428+
output_time_indices = _slice_to_list(output_time_indices)
429+
output_time_indices = [output_time_indices[i] for i in results.keys()]
430+
_save_transformed(
431+
transformed=list(results.values()),
432+
output_position_path=output_position_path,
433+
output_channel_indices=output_channel_indices,
434+
output_time_indices=output_time_indices,
435+
)
436+
else:
437+
click.echo(
438+
f"No valid time points to write for channel indices "
439+
f"{output_channel_indices}, output time indices "
440+
f"{output_time_indices}"
441+
)
434442
del results
435443
_echo_finished(input_time_indices, output_channel_indices, skipped=False)
436444

0 commit comments

Comments
 (0)