csaxs_bec.scans.scan_customization.scan_components.CsaxsBecScanComponents#

class CsaxsBecScanComponents(scan: ScanBase)[source]#

Bases: ScanComponents

Scan components for csaxs_bec.

Methods

check_limits

Check if the given positions for the given motors are within the limits of the motors.

get_start_positions

Get the current position of the given motors.

move_and_wait

Move the given motors to the given positions and wait for the movement to complete.

optimize_trajectory

Optimize the trajectory of the scan by reordering the positions. This can help to minimize the movement time of the motors. The optimization can be done in different ways, depending on the optimization_type parameter: - "corridor": optimize the trajectory in a corridor-like way, where the scan moves back and forth along the primary axis. This is typically a good choice for grid scans. If preferred_directions are provided, the optimizer will try to optimize the trajectory in a way that minimizes the movement in the non-preferred direction. - "shell": optimize the trajectory in a shell-like way, where the scan moves in a spiral from the outside to the inside. This is typically a good choice for round scans. - "nearest": optimize the trajectory by always moving to the nearest next point. This is typically a good choice for random scans.

step_scan

Execute a step scan with the given positions.

step_scan_at_each_point

Execute a step scan at each point.

trigger_and_read

Trigger the devices and start the readout.

check_limits(motors: list[str | DeviceBase] | list[str] | list[DeviceBase], positions: ndarray)#

Check if the given positions for the given motors are within the limits of the motors. If not, raise a LimitError.

Parameters:
  • motors (list[str | DeviceBase] | list[str] | list[DeviceBase]) – List of motor names or device instances.

  • positions (np.ndarray) – Array of positions to check, shape (num_points, len(motors)).

Raises:

LimitError – If any of the positions are out of limits for the corresponding motor.

get_start_positions(motors: list[str | DeviceBase] | list[str] | list[DeviceBase]) list[float]#

Get the current position of the given motors. This can be used to make the positions relative to the current position of the motors.

Parameters:

motors (list[str | DeviceBase] | list[str] | list[DeviceBase]) – List of motor names or device instances.

Returns:

List of current positions of the motors.

Return type:

list[float]

move_and_wait(motors: list[str | DeviceBase] | list[str] | list[DeviceBase], positions: ndarray | list[float], last_positions: ndarray | None = None)#

Move the given motors to the given positions and wait for the movement to complete. If last_positions is provided, only the motors with changed positions will be moved.

Parameters:
  • motors (list[str | DeviceBase] | list[str] | list[DeviceBase]) – List of motor names or device instances to move.

  • positions (np.ndarray | list[float]) – Array or list of positions to move to, shape (len(motors),).

  • last_positions (np.ndarray, optional) – Array of last positions, shape (len(motors),). If provided, only motors with changed positions will be moved. Defaults to None.

optimize_trajectory(positions: ndarray, optimization_type: Literal['corridor', 'shell', 'nearest'] = 'corridor', primary_axis: int = 1, preferred_directions: list[int] | None = None, corridor_size: float | None = None, num_iterations: int = 5) ndarray#

Optimize the trajectory of the scan by reordering the positions. This can help to minimize the movement time of the motors. The optimization can be done in different ways, depending on the optimization_type parameter:

  • “corridor”: optimize the trajectory in a corridor-like way, where the scan moves back and forth along the primary axis. This is typically a good choice for grid scans. If preferred_directions are provided, the optimizer will try to optimize the trajectory in a way that minimizes the movement in the non-preferred direction.

  • “shell”: optimize the trajectory in a shell-like way, where the scan moves in a spiral from the outside to the inside. This is typically a good choice for round scans.

  • “nearest”: optimize the trajectory by always moving to the nearest next point. This is typically a good choice for random scans.

Parameters:
  • positions (np.ndarray) – Array of positions to optimize, shape (num_points, num_motors).

  • optimization_type (str, optional) – Type of optimization to perform. Defaults to “corridor”.

  • primary_axis (int, optional) – Primary axis for corridor optimization. Defaults to 1.

  • preferred_directions (list[int] | None, optional) – List of preferred directions for the non-primary axes. Each entry should be -1, 0, or 1, indicating the preferred direction of movement along that axis. The length of the list should be equal to the number of non-primary axes. Defaults to None, which means no preferred directions.

  • corridor_size (float | None, optional) – Size of the corridor for corridor optimization. Defaults to None, which means the default corridor size will be used.

Returns:

Optimized array of positions, shape (num_points, num_motors).

Return type:

np.ndarray

step_scan(motors: list[str | DeviceBase] | list[str] | list[DeviceBase], positions: ndarray, at_each_point: Callable[[list[str | DeviceBase], ndarray, ndarray | None], None] | None = None, last_positions: ndarray | None = None)#

Execute a step scan with the given positions. It is the core scan logic for most step scans.

Parameters:
  • motors (list[str | DeviceBase] | list[str] | list[DeviceBase]) – List of motor names or device instances to move.

  • positions (np.ndarray) – Array of positions to move to, shape (num_points, len(motors)).

  • at_each_point (Callable[[list[str | DeviceBase], np.ndarray, np.ndarray | None], None], optional) – Function to call at each point. Defaults to None.

  • last_positions (np.ndarray, optional) – Array of last positions, shape (num_points, len(motors)). If provided, only motors with changed positions will be moved. Defaults to None.

step_scan_at_each_point(motors: list[str | DeviceBase] | list[str] | list[DeviceBase], pos: ndarray, last_positions: ndarray | None = None)#

Execute a step scan at each point. This is the core logic that is executed at each point of the step scan. It is separated from the step_scan method to allow scan hooks to override the logic.

The logic is as follows:
  1. Move the motors to the next position without waiting for each motor to complete

  2. Wait for each motor to complete

  3. Let the system settle before triggering

  4. Trigger the devices

  5. Let the system settle after the trigger

  6. Start the readout

Parameters:
  • motors (list[str | DeviceBase] | list[str] | list[DeviceBase]) – List of motor names or device instances to move.

  • pos (np.ndarray) – Array of positions to move to, shape (len(motors),).

  • last_positions (np.ndarray, optional) – Array of last positions, shape (len(motors),). If provided, only motors with changed positions will be moved. Defaults to None.

trigger_and_read()#

Trigger the devices and start the readout. This is typically used for step scans after the motors have been moved to the next position.

The logic is as follows:
  1. Let the system settle before triggering

  2. Trigger the devices

  3. Let the system settle after the trigger

  4. Start the readout