Skip to content

Commit c4d5e5b

Browse files
committed
Add find_a2rp
1 parent 0fa9342 commit c4d5e5b

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

src/usaxs/plans/axis_tuning.py

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def find_ar(md: Optional[Dict[str, Any]] = None):
264264
-1*howWiderRangeToScan*a_stage.r.tune_range.get(),
265265
howWiderRangeToScan*a_stage.r.tune_range.get(),
266266
howManyPoints,
267-
nscans=4,
267+
nscans=3,
268268
signal_stats=stats,
269269
md=md,
270270
)
@@ -398,6 +398,116 @@ def tune_a2rp(md: Optional[Dict[str, Any]] = None):
398398
# return success
399399

400400

401+
def find_a2rp(md: Optional[Dict[str, Any]] = None):
402+
"""
403+
Tune the AR stage a2rp angle with adaptive range.
404+
405+
This function tunes the analyzer rotation stage by finding the optimal position
406+
for maximum signal intensity. It includes setting up the scaler, configuring
407+
the detector controls, and performing a lineup scan.
408+
409+
Uses adaptive scanning to search over originally large range = 5* range for tune_ar,
410+
narrowing closer and closer. Uses longer time and 61 scan points, so it takes significantly longer than tune_ar.
411+
uses lineup2 algoritmus and allows for up to 3 scans. It then runs code which is basically tune_ar
412+
413+
uses upd_photocurrent_calc = oregistry["upd_photocurrent_calc"]
414+
- optionally this is I0: I0_photocurrent_calc = oregistry["I0_photocurrent_calc"]
415+
416+
Parameters
417+
----------
418+
md : Optional[Dict[str, Any]], optional
419+
Metadata dictionary to be added to the scan, by default None
420+
421+
Yields
422+
------
423+
Generator[Any, None, None]
424+
A generator that yields plan steps
425+
"""
426+
howWiderRangeToScan = 4
427+
howManyPoints = 61
428+
if md is None:
429+
md = {}
430+
success = False
431+
try:
432+
yield from bps.mv(usaxs_shutter, "open")
433+
yield from bps.mv(scaler0.preset_time, 0.2)
434+
#yield from bps.mv(upd_controls.auto.mode, "manual")
435+
md["plan_name"] = "find_a2rp"
436+
yield from IfRequestedStopBeforeNextScan()
437+
logger.info(f"tuning axis: {a_stage.r2p.name}")
438+
# axis_start = a_stage.r.position
439+
yield from bps.mv(
440+
mono_shutter,
441+
"open",
442+
usaxs_shutter,
443+
"open",
444+
upd_controls.auto.mode,
445+
"automatic", #set UPD amlifier to autorange to automatic so we do not top the UPD
446+
)
447+
#yield from autoscale_amplifiers([upd_controls, I0_controls]) - do NOT use, would set to manual mode...
448+
trim_plot_by_name(5)
449+
# control BEC plotting since we use upd_photocurrent_calc
450+
scaler0.kind = "normal"
451+
scaler0.select_channels([]) # no scaler channels to be plotted (sets 'kind=normal' for all channels)
452+
stats = SignalStatsCallback() # init stats to return stuff back.
453+
tune_start = -1*howWiderRangeToScan*a_stage.r2p.tune_range.get()
454+
tune_end = howWiderRangeToScan*a_stage.r2p.tune_range.get()
455+
#tune_start must be larger than 0
456+
tune_start = max(tune_start, 0)
457+
tune_end = min(tune_end, 88)
458+
yield from lineup2(
459+
[upd_photocurrent_calc, scaler0],
460+
a_stage.r2p,tune_start, tune_end,howManyPoints,
461+
nscans=3,signal_stats=stats,
462+
md=md,
463+
)
464+
print(stats.report())
465+
#now we need to setup regular tune_ar and run that here.
466+
yield from bps.mv(scaler0.preset_time, 0.1)
467+
yield from bps.mv(
468+
mono_shutter,
469+
"open",
470+
usaxs_shutter,
471+
"open",
472+
)
473+
474+
yield from autoscale_amplifiers([upd_controls, I0_controls])
475+
scaler0.select_channels(["UPD"])
476+
trim_plot_by_name(5)
477+
stats = SignalStatsCallback()
478+
yield from lineup2(
479+
[UPD, scaler0],
480+
a_stage.r2p,
481+
-a_stage.r2p.tune_range.get(),
482+
a_stage.r2p.tune_range.get(),
483+
31,
484+
nscans=1,
485+
signal_stats=stats,
486+
md=md,
487+
)
488+
print(stats.report())
489+
yield from bps.mv(
490+
usaxs_shutter,
491+
"close",
492+
scaler0.count_mode,
493+
"AutoCount",
494+
upd_controls.auto.mode,
495+
"auto+background",
496+
)
497+
scaler0.select_channels()
498+
# success = stats.analysis.success
499+
if stats.analysis.success:
500+
logger.debug(f"final position: {a_stage.r2p.position}")
501+
else:
502+
print(f"tune_a2rp failed for {stats.analysis.reasons}")
503+
504+
except Exception as e:
505+
logger.error(f"Error in find_ar: {str(e)}")
506+
raise
507+
508+
# return success
509+
510+
401511
def tune_dx(md: Optional[Dict[str, Any]] = None):
402512
"""
403513
Tune the DX stage.

src/usaxs/startup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139

140140
# these are all tuning plans facing users and staff
141141
from .plans.axis_tuning import tune_a2rp
142+
from .plans.axis_tuning import find_a2rp
142143
from .plans.axis_tuning import tune_ar
143144
from .plans.axis_tuning import find_ar
144145
from .plans.axis_tuning import tune_diode

0 commit comments

Comments
 (0)