Skip to content

Commit

Permalink
add more peakPositons for it to move to after scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Relm-Arrowny committed Jan 2, 2025
1 parent 52a3fe3 commit 8da4bf1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/i10_bluesky/plans/utils/alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
from p99_bluesky.plans.fast_scan import fast_scan_1d


class PeakPosition(int, Enum):
COM = 2
CEN = 3
class PeakPosition(tuple, Enum):
COM = ("stats", "com")
CEN = ("stats", "cen")
MIN = ("stats", "min")
MAX = ("stats", "max")
D_COM = ("derivative_stats", "com")
D_CEN = ("derivative_stats", "cen")
D_MIN = ("derivative_stats", "min")
D_MAX = ("derivative_stats", "max")


def scan_and_move_cen(funcs) -> Callable:
Expand All @@ -23,12 +29,19 @@ def inner(**kwargs):
f"{kwargs['det'].name}",
calc_derivative_and_stats=True,
)

yield from bpp.subs_wrapper(

Check warning on line 32 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L32

Added line #L32 was not covered by tests
funcs(**kwargs),
ps,
)
yield from abs_set(kwargs["motor"], ps["stats"][kwargs["loc"]], wait=True)
print(ps)
peak_position = get_stat_loc(ps, kwargs["loc"])
if (

Check warning on line 38 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L36-L38

Added lines #L36 - L38 were not covered by tests
kwargs["start"] >= peak_position >= kwargs["end"]
or kwargs["start"] <= peak_position <= kwargs["end"]
):
yield from abs_set(kwargs["motor"], peak_position, wait=True)

Check warning on line 42 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L42

Added line #L42 was not covered by tests
else:
raise ValueError(f"New position ({peak_position}) is outside scan range.")

Check warning on line 44 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L44

Added line #L44 was not covered by tests

return inner

Expand All @@ -55,3 +68,9 @@ def fast_scan_and_move_cen(
loc: PeakPosition = PeakPosition.CEN,
) -> MsgGenerator:
return fast_scan_1d([det], motor, start, end, motor_speed=motor_speed)

Check warning on line 70 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L70

Added line #L70 was not covered by tests


def get_stat_loc(ps: PeakStats, loc: PeakPosition) -> float:
stat = getattr(ps, loc.value[0])
stat_pos = getattr(stat, loc.value[1])
return stat_pos if isinstance(stat_pos, float) else stat_pos[0]

Check warning on line 76 in src/i10_bluesky/plans/utils/alignments.py

View check run for this annotation

Codecov / codecov/patch

src/i10_bluesky/plans/utils/alignments.py#L74-L76

Added lines #L74 - L76 were not covered by tests

0 comments on commit 8da4bf1

Please sign in to comment.