Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinate transformation to Q vector #412

Merged
merged 7 commits into from Feb 10, 2023
Merged

Conversation

jl-wynen
Copy link
Member

@jl-wynen jl-wynen commented Feb 9, 2023

Part of #411

"""
e_i = incident_beam / sc.norm(incident_beam)
e_f = scattered_beam / sc.norm(scattered_beam)
return 2 * np.pi / wavelength * (e_i - e_f)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure a vector3 dtype is convenient here. Typically, the user will want to bin into the 3 Q components in a subsequent step, so returning Qx, Qy, and Qz may be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

After talking to Celine, I decided to switch to returning individual components and drop Q_vec for now as it seems less important. But it is easy to add back in if it turns out that it is useful, e.g. for computing the hkl vector.

2 * np.pi / wavelength * sc.vector([0.0, -1.0, 1.0]))
assert sc.allclose(
Q_vec['pos', 2], 2 * np.pi / wavelength *
sc.vector([0.0, -0.4472135954999579, 0.1055728090000841]))
Copy link
Member

Choose a reason for hiding this comment

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

As a sanity check, you could compute Q and Q_vec, and check if the norm is consistent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Meant to do that and forgot. Thanks!

Comment on lines 338 to 340
Q_vec = sc.vectors(dims=Qx.dims,
values=np.dstack((Qx.values, Qy.values, Qz.values)),
unit=Qx.unit)
Copy link
Member

Choose a reason for hiding this comment

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

Use https://scipp.github.io/generated/functions/scipp.geometry.position.html?

(I think we should rename this function though, I don't like the name).

Copy link
Member Author

Choose a reason for hiding this comment

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

(I think we should rename this function though, I don't like the name).

I guess this is why I missed it

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah no, this is not the reason. I missed it because I looked at scipp.spatial. Why do we have both modules? (And geometry is not documented as a separate module.)

Copy link
Member

Choose a reason for hiding this comment

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

This is just legacy, from before when we had spatial. I think we could have something named spatial.zip and spatial.unzip, maybe? Or spatial.to_vector?

return 2 * np.pi / wavelength * (e_i - e_f)
e = e_i - e_f
k = 2 * np.pi / wavelength
return k * e.fields.x, k * e.fields.y, k * e.fields.z
Copy link
Member

Choose a reason for hiding this comment

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

It is unlikely that this will ever become a performance bottleneck, but it would be interesting to think about scipp::variable::transform that would return multiple Variable.

@jl-wynen jl-wynen merged commit a061694 into main Feb 10, 2023
@jl-wynen jl-wynen deleted the momentum-transfer-vector branch February 10, 2023 08:10
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.

None yet

2 participants