Skip to content

Commit e5d0970

Browse files
committed
address rabbit
1 parent 611b4f0 commit e5d0970

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

dascore/proc/align.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def _get_source_indices(shifts, start_shift, end_shift, n_samples):
4141
def _get_dest_indices(shifts, start_shift, end_shift, n_samples, output_size):
4242
"""Get indices in the output array."""
4343
start = np.maximum(0, shifts - start_shift)
44-
# Calculate actual source data length for each trace
44+
# Clamp source indices to valid range [0, n_samples]
4545
min_start = -shifts + start_shift
46-
source_start = np.where(min_start < 0, 0, min_start)
46+
source_start = np.clip(min_start, 0, n_samples)
4747
max_end = n_samples - shifts + end_shift
48-
source_end = np.where(max_end > n_samples, n_samples, max_end)
49-
source_length = source_end - source_start
50-
# Destination end is start + actual source length
51-
max_ends = start + source_length
52-
end = np.where(max_ends > output_size, output_size, max_ends)
48+
source_end = np.clip(max_end, 0, n_samples)
49+
# Compute source length, ensuring non-negative
50+
source_length = np.maximum(source_end - source_start, 0)
51+
# Destination end bounded to [0, output_size]
52+
end = np.clip(start + source_length, 0, output_size)
5353
return (start, end)
5454

5555

tests/test_proc/test_align.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_reverse_shift_with_larger_shifts(self, random_patch):
463463
# Reverse - this should work without broadcasting error
464464
reversed_patch = aligned.align_to_coord(
465465
relative=False,
466-
reverse=False,
466+
reverse=True,
467467
samples=True,
468468
mode="same",
469469
time="shifts",

0 commit comments

Comments
 (0)