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

wavelength units should be angstrom #23

Merged
merged 7 commits into from
Sep 26, 2020
Merged

Conversation

prjemian
Copy link
Contributor

@prjemian prjemian commented Sep 2, 2020

fixes #17

The wavelength units must match the same units used by the lattice parameters. When X-ray energy is specified, the computed wavelength must be in angstrom.

@prjemian prjemian added the bug label Sep 2, 2020
@prjemian prjemian self-assigned this Sep 2, 2020
@prjemian
Copy link
Contributor Author

prjemian commented Sep 2, 2020

Note that @ambarb discussed this change previously as part of a different PR.

@prjemian prjemian added this to the 0.3.15 milestone Sep 2, 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 to me. I'd like to ask @ambarb to look at it as you are more closely dealing with this object.

@mrakitin
Copy link
Member

mrakitin commented Sep 3, 2020

The test failures are worrying. Were they passing before?

@prjemian
Copy link
Contributor Author

prjemian commented Sep 3, 2020

I don't know. Need to look at them.

@prjemian
Copy link
Contributor Author

prjemian commented Sep 25, 2020

The failures relate to tardis calculations of the forward solutions ((hkl) to motor positions). Might be affected by this code. Will apply tests on master branch to see if they are duplicate.

https://travis-ci.org/github/bluesky/hklpy/builds/723607153#L1494-L1506

@prjemian
Copy link
Contributor Author

@mrakitin - I can't test this code since I do not have the example IOCs running. The error message offers some incorrect (assumed correct when it was written long ago) advice.

(hkl) prjemian@poof ~/.../hklpy/tests $ ./coverage_full.sh 
**ERROR** TThe Motor IOC is not running or is inaccessible from this network.  See ophyd.git/examples/iocs.

These tests assume the motor IOC example and the areaDetector IOC example are running.
PVs checked for:
  XF:31IDA-OP{Tbl-Ax:FakeMtr}-I (='')
  XF:31IDA-BI{Cam:Tbl}image1:Dim0SA (='')

This search may help to locate the current way to run: https://github.com/search?q=org%3Abluesky+examples%2Fiocs&type=code

Another point may be in how travis runs the test. Next place to look...

@prjemian
Copy link
Contributor Author

Need to conda install pytest, then in root dir of repo: py.test tests will run the tests. Confirm same errors locally on this (17-angstrom-wavelength) branch.

Switching to master branch, run tests again (summary: no errors):

(hkl) prjemian@poof ~/.../projects/hklpy $ py.test tests
================================================== test session starts ===================================================
platform linux -- Python 3.7.7, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/prjemian/Documents/projects/hklpy
collected 4 items                                                                                                        

tests/test_tardis.py ....                                                                                          [100%]

==================================================== warnings summary ====================================================
hkl/util.py:9
  /home/prjemian/Documents/projects/hklpy/hkl/util.py:9: PyGIWarning: Hkl was imported without specifying a version first. Use gi.require_version('Hkl', '5.0') before import to ensure that the right version gets loaded.
    from gi.repository import Hkl as hkl_module

tests/test_tardis.py::test_params
  /home/prjemian/Apps/anaconda/envs/hkl/lib/python3.7/site-packages/ophyd/utils/startup.py:10: UserWarning: This function is deprecated in ophyd 1.2 and will be removed in ophyd 1.3. setup is now automatically called.
    warnings.warn("This function is deprecated in ophyd 1.2 "

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================= 4 passed, 2 warnings in 0.85s ==============================================

@prjemian
Copy link
Contributor Author

Conclusion: I'll resolve those test errors in this PR.

@prjemian
Copy link
Contributor Author

It should not be necessary to have EPICS PVs to test this code. It is possible to test this code with the ophyd.SoftPositioner. The switch SoftPositioner to is beyond the scope of this PR but should be the focus of a future issue.

@prjemian
Copy link
Contributor Author

Confirmed that:

  1. tardis tests use SoftPositioner already
  2. tardis test conditions are specific to tardis.calc.wavelength = 1.3317319441460795
  3. tardis test setup sets energy of 0.931 keV which calculates wavelength of 13.317 angstrom now

Easiest thing to do now is to set the test energy to 9.31 keV (even though that energy might be unrealistic for the NSLS-II tardis diffractometer but this code tests the calculation, not the NSLS-II instrument).

@prjemian
Copy link
Contributor Author

@mrakitin Thought I'd ask you to review once more.
@ambarb: Could you also take a look at this?

I'd like to merge it by 2020-10-03 unless objections arise.

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, have a couple of clarifications in the comments.

hkl/calc.py Outdated Show resolved Hide resolved
tests/test_tardis.py Show resolved Hide resolved
tests/test_tardis.py Outdated Show resolved Hide resolved
Co-authored-by: Maksim Rakitin <mrakitin@users.noreply.github.com>
@ambarb
Copy link

ambarb commented Sep 25, 2020

It should not be necessary to have EPICS PVs to test this code. It is possible to test this code with the ophyd.SoftPositioner. The switch SoftPositioner to is beyond the scope of this PR but should be the focus of a future issue.

I've used the bluesky simulator motors and had it working at CSX, but I didn't commit and someone deleted the file. It worked great as a replacement for spec onsim

@mrakitin
Copy link
Member

mrakitin commented Sep 25, 2020

@prjemian, I saw your lesson on hkl in https://github.com/BCDA-APS/use_bluesky/blob/master/lessons/lesson7.ipynb, it looks great!

@ambarb
Copy link

ambarb commented Sep 25, 2020

I don't see anything of concern. We should start working together though so we don't have competing higher level functions to interact with HKL. Some of the things in your lesson are very nice ( print formatting and simplify setting the calculation limits), but those are higher level functions.

@ambarb
Copy link

ambarb commented Sep 25, 2020

I also would say that a nice part of python that you may show off is something like, which is equivalent to some of the things I picked up from spec power users:

myhkl = tardis.position
myhkl_motors = tardis.real_positions` #or whatever is the actual attribute name

which is nice, because then you can move the diffractometer around and later return

tardis.forward(myhkl)
tardis.move(myhkl)

Or use it for simulating plans prior to running them without having to edit the plans - you cannot accurately simulate relative scans using print_summary, but you can fake it with absolute scans.

hh, kk, ll = myhkl
print_summary(scan([fccd, tardis], tardis.h, hh-.05, hh+.05, 21))

which in the end, is may be the way you want to write your plan so you are not needlessly thrashing around the motors to "return" to the starting point.

@prjemian
Copy link
Contributor Author

prjemian commented Sep 25, 2020 via email

@prjemian prjemian merged commit e5d0e8c into master Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

calc should use wavelength in angstrom
3 participants