8000 Fix coord conversion position unit mismatch exceptions by SimonHeybrock · Pull Request #633 · scipp/scippneutron · GitHub
[go: up one dir, main page]

Skip to content

Fix coord conversion position unit mismatch exceptions#633

Merged
SimonHeybrock merged 4 commits intomainfrom
fix-coord-conv-position-unit-mismatch-exception
Jul 9, 2025
Merged

Fix coord conversion position unit mismatch exceptions#633
SimonHeybrock merged 4 commits intomainfrom
fix-coord-conv-position-unit-mismatch-exception

Conversation

@SimonHeybrock
Copy link
Member
@SimonHeybrock SimonHeybrock commented Jul 8, 2025

Issues seen during DREAM data reduction.

Note sure converting everything to meter is nice in all cases, but everything else felt like a mess and totally unpredictable.

@SimonHeybrock SimonHeybrock requested a review from jl-wynen July 8, 2025 08:52
Copy link
Member
@jl-wynen jl-wynen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to return a fixed unit. We do the same in other places, too. E.g., to ensure that wavelengths are in Å.

Compute the incident beam for a straight beamline.
"""
return sc.norm(incident_beam)
return sc.norm(_canonical_length(incident_beam))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you apply it to the result of norm? That uses 3x less memory if it has to convert.

``scattered_beam``
"""
return position - sample_position
return _canonical_length(position) - _canonical_length(sample_position)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you convert the inputs. In straight_incident_beam, you convert the output. Is there a reason? I think since the positions are typically read from file, the implementation in straight_scattered_beam makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, need to fix straight_incident_beam to convert individually, or else we may get more exceptions.

This is used in reflectometry.
"""
incident_beam = _canonical_length(incident_beam)
scattered_beam = _canonical_length(scattered_beam)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary. If it is, then there is something wrong with _scattering_angles_with_gravity_generic or _scattering_angles_with_gravity_orthogonal_coords which currently convert dtypes but not units.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was necessary to fix a failing unit test with gravity.

@SimonHeybrock SimonHeybrock enabled auto-merge July 9, 2025 11:55
@SimonHeybrock SimonHeybrock merged commit c0ab18d into main Jul 9, 2025
5 checks passed
@SimonHeybrock SimonHeybrock deleted the fix-coord-conv-position-unit-mismatch-exception branch July 9, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0