-
Notifications
You must be signed in to change notification settings - Fork 12
Created a dcm as a baseline device for i11 #1581
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
Open
RJCD-Diamond
wants to merge
18
commits into
main
Choose a base branch
from
i11_dcm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−0
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d178fef
added i11 dcm
RJCD-Diamond b64df7c
added i11 dcm
RJCD-Diamond 9876818
added i11 dcm tests
RJCD-Diamond 6dc9536
remove useless fixture
RJCD-Diamond 8c60f2a
Merge remote-tracking branch 'origin/main' into i11_dcm
RJCD-Diamond 4d79058
derived_signal_r for dcm
RJCD-Diamond 6fb2234
get wavelength from derived signal
RJCD-Diamond c3c896c
added missing imports and tidied up dcm class
RJCD-Diamond 9d0e4f3
assert wavelength
RJCD-Diamond 7196cec
tests fixture is valid
RJCD-Diamond e259b74
remove useless unit
RJCD-Diamond 3a62786
remove useless unit
RJCD-Diamond 3271c00
moved fixture to end
RJCD-Diamond b1d9acf
renamed tests
RJCD-Diamond ba622a3
add init to i11 devices
RJCD-Diamond b9e6257
wavelength asserton added
RJCD-Diamond ada2068
remove print
RJCD-Diamond 0e33d1c
added back unit and added to test
RJCD-Diamond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import numpy as np | ||
from ophyd_async.core import Array1D, derived_signal_r, soft_signal_r_and_setter | ||
from ophyd_async.epics.core import epics_signal_r | ||
from ophyd_async.epics.motor import Motor | ||
|
||
from dodal.common.crystal_metadata import ( | ||
CrystalMetadata, | ||
MaterialsEnum, | ||
make_crystal_metadata_from_material, | ||
) | ||
from dodal.devices.common_dcm import ( | ||
BaseDCM, | ||
PitchAndRollCrystal, | ||
StationaryCrystal, | ||
) | ||
|
||
# Conversion constant for energy and wavelength, taken from the X-Ray data booklet | ||
# Converts between energy in KeV and wavelength in angstrom | ||
_CONVERSION_CONSTANT = 12.3984 | ||
|
||
|
||
class DCM(BaseDCM[PitchAndRollCrystal, StationaryCrystal]): | ||
""" | ||
A double crystal monochromator (DCM), used to select the energy of the beam. | ||
|
||
perp describes the gap between the 2 DCM crystals which has to change as you alter | ||
the angle to select the requested energy. | ||
|
||
offset ensures that the beam exits the DCM at the same point, regardless of energy. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
prefix: str, | ||
xtal_prefix: str, | ||
name: str = "", | ||
crystal_metadata: CrystalMetadata | None = None, | ||
) -> None: | ||
cm = crystal_metadata or make_crystal_metadata_from_material( | ||
MaterialsEnum.Si, (1, 1, 1) | ||
) | ||
with self.add_children_as_readables(): | ||
self.perp_in_mm = Motor(prefix + "PERP") | ||
|
||
# temperatures | ||
self.xtal1_holder_temp = epics_signal_r(str, xtal_prefix + "PT100-1.SEVR") | ||
self.xtal1_temp = epics_signal_r(str, xtal_prefix + "PT100-2.SEVR") | ||
|
||
self.xtal2_heater_temp = epics_signal_r(str, xtal_prefix + "PT100-3.SEVR") | ||
self.xtal2_temp = epics_signal_r(str, xtal_prefix + "PT100-4.SEVR") | ||
|
||
self.xtal1_heater_temp = epics_signal_r( | ||
float, xtal_prefix + "H1:TTEMP:CALC" | ||
) | ||
self.xtal2_heater_temp = epics_signal_r( | ||
float, xtal_prefix + "H2:TTEMP:CALC" | ||
) | ||
|
||
self.crystal_metadata_usage, _ = soft_signal_r_and_setter( | ||
str, initial_value=cm.usage | ||
) | ||
self.crystal_metadata_type, _ = soft_signal_r_and_setter( | ||
str, initial_value=cm.type | ||
) | ||
reflection_array = np.array(cm.reflection) | ||
self.crystal_metadata_reflection, _ = soft_signal_r_and_setter( | ||
Array1D[np.uint64], | ||
initial_value=reflection_array, | ||
) | ||
super().__init__(prefix, PitchAndRollCrystal, StationaryCrystal, name) | ||
|
||
with self.add_children_as_readables(): | ||
self.wavelength = derived_signal_r( | ||
self._wavelength_from_energy, | ||
energy=self.energy_in_kev, | ||
unit="angstrom", | ||
) | ||
|
||
def _wavelength_from_energy(self, energy: float, unit: str) -> float: | ||
if energy > 0: | ||
return _CONVERSION_CONSTANT / energy | ||
return 0 |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import bluesky.plans as bp | ||
import pytest | ||
from bluesky.run_engine import RunEngine | ||
from ophyd_async.core import init_devices | ||
from ophyd_async.testing import ( | ||
assert_emitted, | ||
set_mock_value, | ||
) | ||
|
||
from dodal.devices.i11.dcm import DCM | ||
|
||
|
||
@pytest.fixture | ||
async def i11_dcm() -> DCM: | ||
async with init_devices(mock=True): | ||
i11_dcm = DCM(prefix="x-MO-DCM-01:", xtal_prefix="x-DI-DCM-01:") | ||
return i11_dcm | ||
|
||
|
||
def test_count_i11_dcm( | ||
RE: RunEngine, | ||
run_engine_documents: dict[str, list[dict]], | ||
i11_dcm: DCM, | ||
): | ||
RE(bp.count([i11_dcm])) | ||
assert_emitted( | ||
run_engine_documents, | ||
start=1, | ||
descriptor=1, | ||
event=1, | ||
stop=1, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"wavelength,energy,unit", | ||
[ | ||
(0.0, 0.0, "angstrom"), | ||
(1.0, 12.3984, "angstrom"), | ||
(2.0, 6.1992, "angstrom"), | ||
], | ||
) | ||
async def test_i11_wavelength( | ||
wavelength: float, | ||
energy: float, | ||
unit: str, | ||
i11_dcm: DCM, | ||
): | ||
set_mock_value(i11_dcm.energy_in_kev.user_readback, energy) | ||
set_mock_value(i11_dcm.wavelength_in_a.user_readback, wavelength) | ||
|
||
reading = await i11_dcm.read() | ||
|
||
assert reading["i11_dcm-energy_in_kev"]["value"] == energy | ||
assert reading["i11_dcm-wavelength_in_a"]["value"] == wavelength | ||
assert reading["i11_dcm-wavelength"]["value"] == wavelength |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.