Skip to content

Commit

Permalink
Merge pull request #11 from NSLS-II-SST/Issue10-bug-long-pause-after-…
Browse files Browse the repository at this point in the history
…completion-of-each-scan

Issue10 bug long pause after completion of each scan
  • Loading branch information
PriyankaKetkarBNL authored Oct 23, 2024
2 parents 0f72650 + bef6e4e commit 42c3f7c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 163 deletions.
69 changes: 1 addition & 68 deletions rsoxs/Functions/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def duplicate_sample(samp_num,name_suffix):
newsamp['sample_name']+=f'_{name_suffix}'
newsamp['sample_id']+=f'_{name_suffix}'
rsoxs_config['bar'].append(newsamp)
#rsoxs_config.write()



def move_to_location(locs=get_sample_location()):
for item in locs:
Expand Down Expand Up @@ -466,7 +465,6 @@ def samxscan():



#@finalize_decorator(#rsoxs_config.write_plan)
def spiralsearch(
diameter=0.6,
stepsize=0.2,
Expand Down Expand Up @@ -603,76 +601,12 @@ def spiralsearch(



# Bar imaging utilities:

# usage:

# load bar onto imager, load bar file, and do image_bar(bar,path='path_to_image')

# this will automatically go into image tagging, but to pick up where you left off, do

# locate_samples_from_image(bar,'path_to_image')

# Find alignment fiducials in chamber
#
# Helpful Functions goto_af1() goto_af2() and find_af1x(),find_af1y(),find_af2x(),find_af2y()
#
# and then remap the bar using
# correct_bar(bar,af1x,af1y,af2x,af2y)


# def find_fiducials(f2=[7.5, 3.5, -2.5, 1.1]):
# thoffset = 0
# angles = [-90 + thoffset, 0 + thoffset, 90 + thoffset, 180 + thoffset]
# xrange = 3.5
# xnum = 36
# startxss = [f2, [4.2, 3.5, 1, 1.1]]
# yield from bps.mv(Shutter_enable, 0)
# yield from bps.mv(Shutter_control, 0)
# yield from load_configuration("SAXSNEXAFS")
# Beamstop_SAXS.kind = "hinted"
# # yield from bps.mv(DiodeRange, 7)
# # bec.enable_plots() # TODO: need to turn on plotting temporarilly for this function
# startys = [3, -187.0] # af2 first because it is a safer location
# maxlocs = []
# for startxs, starty in zip(startxss, startys):
# yield from bps.mv(sam_Y, starty, sam_X, startxs[1], sam_Th, 0, sam_Z, 0)
# yield from bps.mv(Shutter_control, 1)
# yield from bp.rel_scan([Beamstop_SAXS], sam_Y, -1, 0.5, 16) # TODO: replace with flymax
# yield from bps.mv(Shutter_control, 0)
# #maxlocs.append(bec.peaks.max["SAXS Beamstop"][0]) #TODO: need to find maxiumum another way
# # yield from bps.mv(sam_Y, bec.peaks.max["SAXS Beamstop"][0])
# for startx, angle in zip(startxs, angles):
# yield from bps.mv(sam_X, startx, sam_Th, angle)
# yield from bps.mv(Shutter_control, 1)
# yield from bp.scan( # TODO: replace with flymax
# [Beamstop_SAXS],
# sam_X,
# startx - 0.5 * xrange,
# startx + 0.5 * xrange,
# xnum,
# )
# yield from bps.mv(Shutter_control, 0)
# yield from bps.sleep(3)
# # maxlocs.append(bec.peaks.max["SAXS Beamstop"][0]) #TODO: need to find maxiumum another way
# print(maxlocs) # [af2y,af2xm90,af2x0,af2x90,af2x180,af1y,af1xm90,af1x0,af1x90,af1x180]
# accept = input(f"Do you want to apply this correction (y,n)?")
# if accept in ['y','Y','yes']:
# back = False
# #rsoxs_config.read()
# for samp in rsoxs_config['bar']:
# if samp['front'] ==False:
# back = True
# correct_bar(maxlocs,include_back=back)
# # bec.disable_plots()


def rotate_now(theta, force=False):
if theta is not None:
samp = get_sample_dict()
samp["angle"] = theta
rotate_sample(samp, force)
#rsoxs_config.write()
yield from load_sample(samp)


Expand All @@ -686,7 +620,6 @@ def jog_samp_zoff(id_or_num,jog_val,write_default=True,move=True):
samp['bar_loc']['zoff'] += jog_val
if write_default:
rotate_sample(samp) # this will write the new rotated positions into the position (without moving anything)
#rsoxs_config.write() # this saves the zoff and the new rotated position to the persistent sample list
if(move):
RE(load_samp(id_or_num))
else:
Expand Down
41 changes: 7 additions & 34 deletions rsoxs/Functions/alignment_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

def sample_by_value_match(key, string, bar=None):
if bar == None:
##rsoxs_config.read()
bar = rsoxs_config['bar']
results = [d for (index, d) in enumerate(bar) if d[key].find(string) >= 0]
if len(results) == 1:
Expand All @@ -41,7 +40,6 @@ def sample_by_name( name, bar=None):

def list_samples(bar=None):
if bar == None:
##rsoxs_config.read()
bar = rsoxs_config['bar']
text = " i Sample Name"
for index, sample in enumerate(bar):
Expand Down Expand Up @@ -123,12 +121,10 @@ def sanatize_angle(samp, force=False):
samp["bar_loc"]["th"] = 195.0
if samp["bar_loc"]["th"] <= -155:
samp["bar_loc"]["th"] = -155.0
##rsoxs_config.write()




def samp_dict_from_id_or_num(num_or_id):
##rsoxs_config.read()
if isinstance(num_or_id,str):
sam_dict = [d for (index, d) in enumerate(rsoxs_config['bar']) if d['sample_id'].find(num_or_id) >= 0]
if len(sam_dict) > 0:
Expand All @@ -146,7 +142,6 @@ def samp_dict_from_id_or_num(num_or_id):

def offset_bar(xoff, yoff, zoff, thoff, bar=None):
if bar == None:
##rsoxs_config.read()
bar = rsoxs_config['bar']
for samp in bar:
for mot in samp["location"]:
Expand All @@ -160,8 +155,7 @@ def offset_bar(xoff, yoff, zoff, thoff, bar=None):
mot["position"] += thoff
sample_recenter_sample(samp)

##rsoxs_config.write()


def default_sample(name,proposal_id,institution='NIST',grazing=False,front=True):
return {
"institution": institution,
Expand Down Expand Up @@ -206,7 +200,6 @@ def stop(self, doc):
import bluesky.preprocessors as bpp
def image_bar( path=None, front=True, bar=None):
if bar == None:
##rsoxs_config.read()
bar = rsoxs_config['bar']
global loc_Q
loc_Q = queue.Queue(1)
Expand All @@ -226,7 +219,6 @@ def image_bar( path=None, front=True, bar=None):

def locate_samples_from_image( impath, front=True, bar=None):
if bar == None:
##rsoxs_config.read()
bar = rsoxs_config['bar']
# if the image was just taken itself, before a bar was compiled, then this can be run to just load that image
# and then interactively place the elements of bar
Expand All @@ -249,7 +241,6 @@ def update_bar(loc_Q, front, inbar=None):
updated with whether we are pointing at the front or the back of the bar
"""
if inbar == None:
##rsoxs_config.read()
inbar = rsoxs_config['bar']
from threading import Thread

Expand Down Expand Up @@ -277,6 +268,7 @@ def worker():
gbar.insert(0, AF1)
gbar.insert(1, AF2)
gbar.insert(2, diode)
## Appending fiducials/diodes to the end does not always reliably add image position into rsoxs_config (Issue #2, also encountered during 20241006 beam time), so it is simpler to add these at the beginnng.



Expand All @@ -300,7 +292,6 @@ def worker():
AF2 = default_sample("AF2_back",proposal_id=gbar[0]['proposal_id'],institution=gbar[0]['institution'],front=False)
gbar.insert(1, AF1) # inserts in the second position
gbar.insert(-1, AF2) # inserts in the second to last position
##rsoxs_config.write()
while True:
# for sample in bar:
sample = gbar[samplenum]
Expand Down Expand Up @@ -338,8 +329,6 @@ def worker():
sample["bar_loc"]["th0"] = float(180)
annotateImage(sample_image_axes, item, sample["sample_name"])
# advance sample and loop
#rsoxs_config['bar'] = gbar
#rsoxs_config.write()
samplenum += 1
elif item == "escape":
print("aborting")
Expand All @@ -352,8 +341,6 @@ def worker():
samplenum -= 1
if samplenum >= len(gbar):
print("done")
#rsoxs_config['bar'] = gbar
#rsoxs_config.write()
break

t = Thread(target=worker)
Expand Down Expand Up @@ -448,7 +435,6 @@ def plot_key_press(event):
def offset_bar( xoff, yoff, zoff, thoff, bar = None):

if bar == None:
#rsoxs_config.read()
bar = rsoxs_config['bar']
for samp in bar:
for mot in samp["location"]:
Expand All @@ -460,8 +446,7 @@ def offset_bar( xoff, yoff, zoff, thoff, bar = None):
mot["position"] += zoff
if mot["motor"] == "th":
mot["position"] += thoff
#rsoxs_config.write()



def correct_bar(fiduciallist, include_back, training_wheels=True, bar = None):
"""
Expand All @@ -475,7 +460,6 @@ def correct_bar(fiduciallist, include_back, training_wheels=True, bar = None):
fiducial list is the list output by find_fiducials()
"""
if bar == None:
#rsoxs_config.read()
bar = deepcopy(rsoxs_config['bar'])
af2y = fiduciallist[0]
af2xm90 = fiduciallist[1]
Expand Down Expand Up @@ -606,8 +590,7 @@ def correct_bar(fiduciallist, include_back, training_wheels=True, bar = None):
rotate_sample(samp) # this will take the positions found above and the desired incident angle and
# rotate the location of the sample accordingly
rsoxs_config['bar'] = bar #event_model.sanitize_doc() #rsoxs_config['bar'] = orjson.dumps(bar)
#rsoxs_config.write()


def zoffset(af1zoff, af2zoff, y, front=True, height=0.25, af1y=-186.3, af2y=4):
"""
Using the z offset of the fiducial positions from the center of rotation,
Expand Down Expand Up @@ -688,7 +671,6 @@ def rotate_sample(samp, force=False):
motor["position"] = theta_new
if motor["motor"] == "y":
motor["position"] = y0
# #rsoxs_config.write()
# in future, updating y (if the rotation axis is not perfectly along y
# and z (to keep the sample-detector distance constant) as needed would be good as well
# newz = rotatedz(newx, th, zoff, af1xoff)
Expand All @@ -715,13 +697,11 @@ def sample_recenter_sample(samp):
samp["bar_loc"]["x0"] = newx0
samp["bar_loc"]["y0"] = newy # y and y0 are the same, so we can just copy this
samp["angle"] = newangle
# #rsoxs_config.write()




def read_positions(bar=None):
if bar == None:
#rsoxs_config.read()
bar = rsoxs_config['bar']
# for when the positions are altered by hand in the excel sheet, (i.e. after spiral scans)
# this reads those positions and sets the default positions (x0 and y0) to match
Expand All @@ -731,7 +711,6 @@ def read_positions(bar=None):

def resolve_spirals(bar=None):
if bar == None:
#rsoxs_config.read()
bar = rsoxs_config['bar']
for samp in bar:
if len(str(samp['bar_loc'].get('spiral_started',''))) > 0 and len(samp['bar_loc'].get('spiral_done','')) == 0:
Expand All @@ -757,7 +736,6 @@ def resolve_spirals(bar=None):
newsamp['sample_name']+=f'_{i}'
newsamp['sample_id']+=f'_{i}'
rsoxs_config['bar'].append(newsamp)
#rsoxs_config.write()
else:
accept = input(f"image {im} at ({xs[im],ys[im]}) is correct (y,n)?")
if accept in ['y','Y','yes']:
Expand All @@ -767,14 +745,9 @@ def resolve_spirals(bar=None):
{'motor':'z','position':z}]
samp['bar_loc']['spiral_done']={"scan":h['start']['uid'],
'best_num':im}
#rsoxs_config.write()




#def clear_bar():
# accept = input(f"Are you sure you want to clear the presistant bar? (y,n)?")
# if accept in ['y','Y','yes']:
#rsoxs_config.clear_bar()

def acq(id_or_num,acq_num=0):
samp = samp_dict_from_id_or_num(id_or_num)
Expand Down
4 changes: 0 additions & 4 deletions rsoxs/Functions/energyscancore.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def cleanup():
yield from bps.mv(Shutter_control, 0)


#@finalize_decorator(##rsoxs_config.write_plan)
def NEXAFS_step_scan_core(
dets=None, # a list of detectors to run at each step - must be scalar type detectors wtih set_exp functions
energy=None, # optional energy object to set energy commands to - sets to energy by default, but allows for simulation
Expand Down Expand Up @@ -342,7 +341,6 @@ def NEXAFS_step_scan_core(



#@finalize_decorator(#rsoxs_config.write_plan)
def new_en_scan_core(
dets=None, # a list of detectors to run at each step - get from md by default
energy=None, # optional energy object to set energy commands to - sets to energy by default, but allows for simulation
Expand Down Expand Up @@ -668,7 +666,6 @@ def final():



#@finalize_decorator(#rsoxs_config.write_plan)
def NEXAFS_old_fly_scan_core(
scan_params,
openshutter=True,
Expand Down Expand Up @@ -795,7 +792,6 @@ def NEXAFS_old_fly_scan_core(



#@finalize_decorator(#rsoxs_config.write_plan)
def NEXAFS_fly_scan_core(
scan_params,
openshutter=True,
Expand Down
4 changes: 1 addition & 3 deletions rsoxs/Functions/fly_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
BeamStopS)
from .alignment import load_configuration, rsoxs_config,correct_bar

## TODO: Not sure why this is redefined identically as the function in flystream_wrapper.py, but end goal is to move to Jamie's function.
def flystream_during_wrapper(plan, flyers, stream=False):
"""
Kickoff and collect "flyer" (asynchronously collect) objects during runs.
Expand Down Expand Up @@ -334,8 +335,6 @@ def find_optimum_motor_pos(db, uid, motor_name='RSoXS Sample Up-Down', signal_na



#@finalize_decorator(#rsoxs_config.write_plan)
#RE(fly_find_fiducials(f2=[3.5,-1,-2.4,1.5],f1=[2.0,-0.9,-1.5,0.8],y1=-187.5,y2=2)) # new encoders
#def fly_find_fiducials(f2=[7.5,5,-2.5,0],f1=[4.6, 4, 1, 1.1],y2=2.5,y1=-188):
def fly_find_fiducials(f2=[3.5,-1,-2.4,1.5],f1=[2.0,-0.9,-1.5,0.8],y1=-187.5,y2=2):
thoffset = 0
Expand Down Expand Up @@ -380,7 +379,6 @@ def fly_find_fiducials(f2=[3.5,-1,-2.4,1.5],f1=[2.0,-0.9,-1.5,0.8],y1=-187.5,y2=
accept = input(f"Do you want to apply this correction (y,n)?")
if accept in ['y','Y','yes']:
back = False
#rsoxs_config.read()
for samp in rsoxs_config['bar']:
if samp['front'] ==False:
back = True
Expand Down
1 change: 1 addition & 0 deletions rsoxs/Functions/flystream_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bluesky.preprocessors import plan_mutator


## TODO: This is intended to be centralized in Jamie Titus's nbs-bl package. Switch the imports after moving to all the new packages.
def flystream_during_wrapper(plan, flyers, stream=False):
"""
Kickoff and collect "flyer" (asynchronously collect) objects during runs.
Expand Down
3 changes: 0 additions & 3 deletions rsoxs/Functions/rsoxs_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
motors = {"temp_ramp_rate": tem_tempstage.ramp_rate}


#@finalize_decorator(#rsoxs_config.write_plan)
def run_bar(
bar=None,
sort_by=["apriority"],
Expand Down Expand Up @@ -72,7 +71,6 @@ def run_bar(
_description_
"""
if bar == None:
#rsoxs_config.read()
bar = rsoxs_config['bar']
if dry_run:
verbose = True
Expand Down Expand Up @@ -120,7 +118,6 @@ def run_bar(
message += f'total time {time_sec(actual_total_time)}, expected {time_sec(queue_step["time_before"]+queue_step["acq_time"])}\n'
message += f'expected time remaining {time_sec(queue_step["time_after"])} plus overhead\n'

#rsoxs_config.write() # bar may have changed - added annotations etc
message = message[:message.rfind('expected')]
message += f"End of Queue"
rsoxs_bot.send_message(message)
Expand Down
1 change: 0 additions & 1 deletion rsoxs/Functions/spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def load_sheet(path):
newbar = load_samplesxlsx(path)
if isinstance(newbar, list):
rsoxs_config['bar'] = newbar
##rsoxs_config.write()
print(f'replaced persistent bar with bar loaded from {path}')
return

Expand Down
Loading

0 comments on commit 42c3f7c

Please sign in to comment.