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

compute_UB() should return UB matrix #85

Merged
merged 8 commits into from
Jan 5, 2021
Merged

compute_UB() should return UB matrix #85

merged 8 commits into from
Jan 5, 2021

Conversation

prjemian
Copy link
Contributor

fixes #68, previously sample.compute_UB(r1, r2) returned 1 or 0 (success, fail) which is not so useful. The underlying code will raise an exception if a failure (such as r1 & r2 are parallel). The code had a comment telling what to do. If we're just going to ignore the return result, it might as well be a useful one.

@ambarb Agree?

@prjemian prjemian added this to the v0.3.16 milestone Dec 26, 2020
@prjemian prjemian self-assigned this Dec 26, 2020
Copy link
Member

@mrakitin mrakitin left a comment

Choose a reason for hiding this comment

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

Looks good. I have a couple of suggestions below.

hkl/sample.py Outdated

for name in ('lattice', 'name', 'U', 'UB', 'ux', 'uy', 'uz',
'reflections', ):
raise ValueError("Invalid unit type")
Copy link
Member

Choose a reason for hiding this comment

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

Since we are here, it'd probably make sense to improve this error message, at least by reporting what unit was used, and what are the allowed units.

Copy link

Choose a reason for hiding this comment

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

in practice, we use the default units always. So I guess the default value for units is "user" so these text strings will match. if the user accidentally entered a float in nm (not Angstrom) for a, b, and c, then it will not be caught unless we start explicitly defining the units. I would say the most people are lazy and will want to do what spec assumes.

I think there more important issues to address (get spec features that are missing) as opposed to robust unit fault finding, but I am fine if @prjemian wants to address unit type now. I just don't think there is much value gained unless we force people to include proper units.

Copy link
Contributor Author

@prjemian prjemian Jan 4, 2021

Choose a reason for hiding this comment

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

For this PR, I'll just improve the detail in the exception message (received v. expected).

There is a deeper issue in the libhkl code where the units are actually something engineering (degrees for rotations as an example) but the hklpy code expects default or user. Need to identify a clear example before we could consider resolving how to handle units properly.

Copy link
Member

Choose a reason for hiding this comment

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

For this PR, I'll just improve the detail in the exception message (received v. expected).

I was asking exactly for that, thanks @prjemian!

hkl/sample.py Show resolved Hide resolved
import pytest

import gi
gi.require_version('Hkl', '5.0')
Copy link
Member

Choose a reason for hiding this comment

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

Looks like black ignored this file (' -> " did not happen). Should it format this test file too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we black this now, we'll get a merge conflict with another PR. Is it easier to resolve conflicts after code styling is applied? If we don't style the code now, we might forget...

@prjemian prjemian mentioned this pull request Jan 4, 2021
@prjemian
Copy link
Contributor Author

prjemian commented Jan 5, 2021

Conflicts with main branch. Merged from main rather than rebase due to multiple conflicting commits involving black -l 75 style reformatting of sample.py and test_sample.py.

@prjemian prjemian merged commit d46a4f7 into main Jan 5, 2021
@prjemian prjemian deleted the 68-return_UB branch January 5, 2021 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compute_UB() should return the UB matrix
3 participants