Skip to content

Commit 4636674

Browse files
SimonHeybrockjl-wynen
authored andcommitted
Fix exception in coord conversion if (source_)position units mismatch
1 parent 90510fb commit 4636674

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/scippneutron/conversion/beamline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def total_straight_beam_length_no_scatter(
274274
:
275275
:math:`L_\\mathsf{total}`
276276
"""
277-
return sc.norm(position - source_position)
277+
return sc.norm(position - source_position.to(unit=position.unit, copy=False))
278278

279279

280280
def two_theta(

tests/conversion/beamline_conversions_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ def test_total_straight_beam_length_no_scatter():
9393
)
9494

9595

96+
def test_total_straight_beam_length_no_scatter_source_position_unit_is_converted():
97+
position = sc.vectors(dims=['po'], values=[[1, 2, 3], [4, 5, 6]], unit='m')
98+
source_position = sc.vector([0.1, 0.2, 0.3], unit='m').to(unit='mm')
99+
Ltotal = beamline.total_straight_beam_length_no_scatter(
100+
source_position=source_position, position=position
101+
)
102+
sc.testing.assert_allclose(
103+
Ltotal, sc.array(dims=['po'], values=[3.367491648096, 8.410707461325], unit='m')
104+
)
105+
106+
96107
def test_two_theta_arbitrary_values():
97108
incident_beam = sc.vector([0.564, 1.2, -10.4], unit='m')
98109
scattered_beam = sc.vectors(

0 commit comments

Comments
 (0)