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

Component for motors moving halfs of JF4M detector #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
pip install git+https:/European-XFEL/EXtra.git
```

Added:

- [JF4MHalfMotors][extra.components.JF4MHalfMotors] to access positions of motors moving halfs of Jungfrau detector (!224).

Fixed:

- Karabacon 3.0.10 is now supported by the [Scantool][extra.components.Scantool]
Expand Down
2 changes: 2 additions & 0 deletions docs/components/detector-motors.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
::: extra.components.AGIPD1MQuadrantMotors

::: extra.components.JF4MHalfMotors
1 change: 1 addition & 0 deletions docs/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Component index:
- [AdqRawChannel][extra.components.AdqRawChannel]
- [Detector motors](detector-motors.md)
- [AGIPD1MQuadrantMotors][extra.components.AGIPD1MQuadrantMotors]
- [JF4MHalfMotors][extra.components.JF4MHalfMotors]
2 changes: 1 addition & 1 deletion src/extra/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .dld import DelayLineDetector # noqa
from .las import OpticalLaserDelay # noqa
from .adq import AdqRawChannel # noqa
from .detector_motors import AGIPD1MQuadrantMotors # noqa
from .detector_motors import AGIPD1MQuadrantMotors, JF4MHalfMotors # noqa
68 changes: 66 additions & 2 deletions src/extra/components/detector_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@
src = pattern.format(**args)
label = ''.join(f"{n}{v}" for n, v in args.items())

if src in dc.control_sources and position_key in dc[src].keys():
if (
src in dc.control_sources and
position_key in dc[src].keys(inc_timestamps=False)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
position_key in dc[src].keys(inc_timestamps=False)
position_key in dc[src]

This should work, and can be faster than loading the list of keys.

):
motors[label] = (src, position_key)
continue

Expand Down Expand Up @@ -244,7 +247,7 @@
dc (extra_data.DataCollection):
The data
detector_id (str):
The detector ID, e.g. SPB_IRU_AGIPD1M or SPB_IRU_AGIPD1M
The detector ID, e.g. SPB_IRU_AGIPD1M or MID_EXP_AGIPD1M

Raises:
ValueError:
Expand Down Expand Up @@ -278,3 +281,64 @@

detector_id, detector_motors = all_motors.popitem()
super().__init__(dc, detector_id, detector_motors, q=groups, m=motors)


class JF4MHalfMotors(DetectorMotors):
"""Interface to Jungfrau 4M half motors.

Example usage in a Jupyter notebook:
```python
-----------------------------------------------------------
In [1]: |motors = JF4MHalfMotors(run) |
|motors |
-----------------------------------------------------------
Out[1]: <JF4MHalfMotors(2, 1)for SPB_IRDA_JF4M at
2024-08-21T19:38:47.690044000>
```
"""
# SPB
# SPB_IRDA_JF4M/MOTOR/X{q+1}
# SPB_IRDA_JF4M/MOTOR/Z

KNOWN_DETECTORS = ["SPB_IRDA_JF4M"]

def __init__(self, dc, detector_id=None):
"""
Args:
dc (extra_data.DataCollection):
The data
detector_id (str):
The detector ID, e.g. SPB_IRDA_JF4M

Raises:
ValueError:
If motors are not found or multiple motor groups are found
"""
pattern = "{detector_id}/MOTOR/X{q}"

Check warning on line 317 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L317

Added line #L317 was not covered by tests

num_groups = 2
num_motors = 1
groups = list(range(1, num_groups + 1))
motors = list(range(1, num_motors + 1))

Check warning on line 322 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L319-L322

Added lines #L319 - L322 were not covered by tests

data_selectors = sources_by_class(dc)

Check warning on line 324 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L324

Added line #L324 was not covered by tests

all_motors = {}
detectors = (

Check warning on line 327 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L326-L327

Added lines #L326 - L327 were not covered by tests
self.KNOWN_DETECTORS if detector_id is None else [detector_id])
for det_id in detectors:
pattern = det_id + "/MOTOR/X{q}"
det_motors = find_motors(dc, pattern, self._position_key,

Check warning on line 331 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L329-L331

Added lines #L329 - L331 were not covered by tests
data_selectors, q=groups, m=motors)
if det_motors:
all_motors[det_id] = det_motors

Check warning on line 334 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L333-L334

Added lines #L333 - L334 were not covered by tests

if len(all_motors) == 0:
raise ValueError("Motors are not found")
elif len(all_motors) > 1:
raise ValueError(

Check warning on line 339 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L336-L339

Added lines #L336 - L339 were not covered by tests
"Many detector found: {', '.join(det_motors.keys())}. "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Many detector found: {', '.join(det_motors.keys())}. "
"Many detector found: {', '.join(det_motors.keys())}.\n"

Nitpicking, it might be nicer formatting to print the 'please specify' message on a new line.

"Please specify 'detector_id'")

detector_id, detector_motors = all_motors.popitem()
super().__init__(dc, detector_id, detector_motors, q=groups, m=motors)

Check warning on line 344 in src/extra/components/detector_motors.py

View check run for this annotation

Codecov / codecov/patch

src/extra/components/detector_motors.py#L343-L344

Added lines #L343 - L344 were not covered by tests