示例#1
0
def grid_fly(flyer, y, ystart, ystop, ynum, x, xstart, xstop, xnum):
    generator = CompoundGenerator(
        generators=[
            LineGenerator(y.name, "mm", ystart, ystop, ynum),
            LineGenerator(x.name, "mm", xstart, xstop, xnum),
        ],
        duration=0.1,
    )
    mapping.configure(dict(generator=generator))
    md = dict(
        hints=dict(
            gridding="rectilinear",
            dimensions=[([y.name], "primary"), ([x.name], "primary")],
        ),
        shape=(ynum, xnum),
        extents=([ystart, ystop], [xstart, xstop]),
    )
    uid = yield from bps.open_run(md)
    yield from bps.kickoff(flyer, wait=True)
    yield from bps.collect(flyer, stream=True)
    yield from bps.checkpoint()
    yield from bps.complete(flyer, group="flyer")
    for _ in range(int(ynum * xnum * 0.1)):
        yield from bps.sleep(1)
        yield from bps.collect(flyer, stream=True)
        yield from bps.checkpoint()
    yield from bps.wait(group="flyer")
    yield from bps.collect(flyer, stream=True)
    yield from bps.close_run()
    return uid
示例#2
0
def set_and_fly(filepaths, flyers, sleeptime=10):
    '''
        Fly on flyers with file prefix for a certain sleep time.
        fileprefix: file prefix
        sleeptime : sleep time to let flyer run for


        I've written this manually for now.
    '''

    # set the file paths
    for filepath, flyer in zip(filepaths, flyers):
        yield from bps.abs_set(flyer.filepath, filepath)

    yield from bps.open_run()
    for flyer in flyers:
        yield from bps.stage(flyer)

    grp = str(uuid4())
    for flyer in flyers:
        yield from bps.kickoff(flyer, group=grp, wait=False)

    yield from bps.wait(group=grp)
    yield from bps.sleep(sleeptime)

    for flyer in flyers:
        yield from bps.complete(flyer, group=grp, wait=False)

    for flyer in flyers:
        yield from bps.collect(flyer)

    for flyer in flyers:
        yield from bps.unstage(flyer)

    yield from bps.close_run()
示例#3
0
 def plan(self):
     print("plan() start")
     try:
         yield from bps.complete(self, wait=True)
     except FailedStatus:
         raise NotEnoughTriggers(self.expected_triggers.get(),
                                 self.actual_triggers.get())
     print("plan() end")
示例#4
0
 def inner():
     print('Beamline Ready... waiting for HPLC Injected Signal')
     yield from kickoff(hplc, wait=True)
     print('Acquiring data...')
     for mo in monitors:
         yield from monitor(mo)
     status = yield from complete(hplc, wait=False)
     while True:
         yield from trigger_and_read(
             detectors)  # one 'primary' event per loop
         if status.done:
             break
     for mo in monitors:
         yield from unmonitor(mo)
     print('Collecting the data...')
     yield from collect(hplc)
示例#5
0
    def inner(detectors, fast_axis, ready_pos, slow_axis, Nslow, pos_s):
        running_forward = True
        #for mo in monitors:
        #    yield from bps.monitor(mo)

        for i in range(Nslow):
            if slow_axis is not None:
                yield from mov(fast_axis, ready_pos[running_forward],
                               slow_axis, pos_s[i])
            else:
                yield from mov(fast_axis, ready_pos[running_forward])

            xps_trj.select_forward_traj(running_forward)
            yield from bps.kickoff(xps_trj, wait=True)
            yield from bps.complete(xps_trj, wait=True)
            running_forward = not running_forward
        yield from bps.collect(xps_trj)
    def inner():
        # Prepare statistics plugin
        yield from bps.mv(stats.enable, 1, stats.compute_centroid, 1)

        # Prepare Camera
        yield from bps.mv(cam.acquire, 0)  # Stop camera...
        yield from bps.sleep(.5)  # ...and wait for the pipeline to empty.
        yield from bps.mv(
            cam.trigger_mode,
            "Sync In 1",  # External Trigger
            cam.array_counter,
            0,
        )
        yield from bps.abs_set(cam.acquire, 1)  # wait=False

        # Move to the starting positions
        yield from bps.mv(
            slt_gap,
            gap,  # Move gap to desired position
            slt_ctr,
            start - move_slack,  # Move slits to the beginning of the motion
            stats.ts_control,
            "Erase/Start",  # Prepare statistics Time Series
        )

        # Set Slits Center velocity for the scan
        yield from bps.mv(slt_ctr.velocity, speed)

        # Go
        yield from bps.kickoff(flyer, wait=True)
        st = yield from bps.complete(flyer)
        yield from bps.abs_set(slt_ctr, end + move_slack)

        while not st.done:
            yield from bps.collect(flyer, stream=True)
            # RE._uncollected.add(flyer)        # TODO: This is a hideous hack until the next bluesky version. Remove this line
            yield from bps.sleep(0.5)

        yield from bps.sleep(1)
        yield from bps.collect(flyer, stream=True)

        yield from bps.mv(stats.ts_control, "Stop")
示例#7
0
    def fly_each_step(detectors, motor, step, firststep):
        "See http://nsls-ii.github.io/bluesky/plans.html#the-per-step-hook"
        # First, let 'scan' handle the normal y step, including a checkpoint.
        yield from one_1d_step(detectors, motor, step)

        # Now do the x steps.
        v = (xstop - xstart) / (xnum-1) / dwell  # compute "stage speed"
        yield from abs_set(xmotor, xstart - delta, wait=True) # ready to move
        yield from abs_set(xmotor.velocity, v, wait=True)  # set the "stage speed"

        yield from abs_set(xs.hdf5.num_capture, xnum, wait=True)
        yield from abs_set(xs.settings.num_images, xnum, wait=True)
        yield from abs_set(ion.nuse_all,xnum)
        # arm the Zebra (start caching x positions)


        yield from kickoff(flying_zebra, xstart=xstart, xstop=xstop, xnum=xnum, dwell=dwell, wait=True)
        yield from abs_set(ion.erase_start, 1) # arm SIS3820, note that there is a 1 sec delay in setting X into motion
                                               # so the first point *in each row* won't normalize...
        yield from bps.trigger(xs, group='row')
        #if firststep == True:
        #    ttime.sleep(0.)
        yield from bps.sleep(1.5)
        yield from abs_set(xmotor, xstop+1*delta, group='row')  # move in x
        yield from bps.wait(group='row')
        # yield from abs_set(xs.settings.acquire, 0)  # stop acquiring images
        yield from abs_set(ion.stop_all, 1)  # stop acquiring scaler
        yield from complete(flying_zebra)  # tell the Zebra we are done
        yield from collect(flying_zebra)  # extract data from Zebra
        if ('e_tomo' in xmotor.name):
            v_return = 4
            v_max = xmotor.velocity.high_limit
            if (v_return > v_max):
                xmotor.velocity.set(v_max)
            else:
                xmotor.velocity.set(v_return)
        else:
            yield from abs_set(xmotor.velocity, 1.0, wait=True)  # set the "stage speed"
示例#8
0
 def zebra_complete():
     yield from complete(flying_zebra)  # tell the Zebra we are done
示例#9
0
    def fly_each_step(motor, step):
        "See http://nsls-ii.github.io/bluesky/plans.html#the-per-step-hook"
        # First, let 'scan' handle the normal y step, including a checkpoint.
        yield from one_1d_step([], motor, step)
        # yield from bps.sleep(1.0)  # wait for the "x motor" to move

        # Now do the x steps.
        v = ((xstop - xstart) / (xnum - 1)) / dwell  # compute "stage speed"
        yield from abs_set(xmotor, xstart - delta, wait=True)  # ready to move

        # TODO  Why are we re-trying the move?  This should be fixed at
        # a lower level
        # yield from bps.sleep(1.0)  # wait for the "x motor" to move
        x_set = xstart - delta
        x_dial = xmotor.user_readback.get()
        i = 0
        while (np.abs(x_set - x_dial) > 0.0001):
            if (i == 0):
                print('Waiting for motor to reach starting position...',
                      end='')
            i = i + 1
            yield from abs_set(xmotor, xstart - delta, wait=True)
            yield from bps.sleep(1.0)
            x_dial = xmotor.user_readback.get()
        if (i != 0):
            print('done')

        yield from abs_set(xmotor.velocity, v,
                           wait=True)  # set the "stage speed"

        # set up all of the detectors
        # TODO we should be able to move this out of the per-line call?!
        if 'xs' in dets_by_name:
            xs = dets_by_name['xs']
            yield from abs_set(xs.hdf5.num_capture, xnum, wait=True)
            yield from abs_set(xs.settings.num_images, xnum, wait=True)

        if 'xs2' in dets_by_name:
            xs2 = dets_by_name['xs2']
            yield from abs_set(xs2.hdf5.num_capture, xnum, wait=True)
            yield from abs_set(xs2.settings.num_images, xnum, wait=True)

        if 'merlin' in dets_by_name:
            merlin = dets_by_name['merlin']
            yield from abs_set(merlin.hdf5.num_capture, xnum, wait=True)
            yield from abs_set(merlin.cam.num_images, xnum, wait=True)

        if 'dexela' in dets_by_name:
            dexela = dets_by_name['dexela']
            yield from abs_set(dexela.hdf5.num_capture, xnum, wait=True)
            yield from abs_set(dexela.cam.num_images, xnum, wait=True)

        ion = flying_zebra.sclr
        yield from abs_set(ion.nuse_all, xnum)

        # arm the Zebra (start caching x positions)
        yield from kickoff(flying_zebra,
                           xstart=xstart,
                           xstop=xstop,
                           xnum=xnum,
                           dwell=dwell,
                           wait=True)

        # arm SIS3820, note that there is a 1 sec delay in setting X
        # into motion so the first point *in each row* won't
        # normalize...
        yield from abs_set(ion.erase_start, 1)

        # trigger all of the detectors
        for d in flying_zebra.detectors:
            yield from bps.trigger(d, group='row')

        yield from bps.sleep(1.5)
        # start the 'fly'
        yield from abs_set(xmotor, xstop + 1 * delta, group='row')  # move in x
        # wait for the motor and detectors to all agree they are done
        yield from bps.wait(group='row')

        # yield from abs_set(xs.settings.acquire, 0)  # stop acquiring images

        # we still know about ion from above
        yield from abs_set(ion.stop_all, 1)  # stop acquiring scaler

        yield from complete(flying_zebra)  # tell the Zebra we are done
        yield from collect(flying_zebra)  # extract data from Zebra
        # TODO what?
        if ('e_tomo' in xmotor.name):
            v_return = min(4, xmotor.velocity.high_limit)
            yield from bps.mov(xmotor.velocity, v_return)
        else:
            # set the "stage speed"
            yield from bps.mov(xmotor.velocity, 1.0)
            # TODO wat
            # set the "stage speed" twice just in case
            yield from abs_set(xmotor.velocity, 1.0, wait=True)
    def inner():
        # Prepare TIFF plugin
        if filepath is not None and filename is not None:
            fp = filepath

            if fp[-1] != '/':
                fp += '/'

            print("Saving files as", "".join((fp, filename, "_XXX.tif")))
            print("First file number:", cam_8.tiff.file_number.get())

            yield from bps.mv(
                tiff.enable,
                1,
                tiff.auto_increment,
                1,
                tiff.file_path,
                fp,
                tiff.file_name,
                filename,
                tiff.file_template,
                "%s%s_%3.3d.tif",
                tiff.file_write_mode,
                1,  # Capture mode
                tiff.num_capture,
                steps,
            )

        # Prepare statistics plugin
        yield from bps.mv(stats.enable, 1, stats.compute_centroid, 1)

        # Prepare Camera
        yield from bps.mv(cam.acquire, 0)  # Stop camera...

        yield from bps.sleep(.5)  # ...and wait for the pipeline to empty.
        yield from bps.mv(
            cam.trigger_mode,
            "Sync In 1",  # External Trigger
            cam.array_counter,
            0,
        )
        yield from bps.abs_set(cam.acquire, 1)  # wait=False
        # DAMA (mrakitin) comment 2019-08-20: the tiff plugin is not used (images are not saved)
        # (see https://github.com/NSLS-II-FMX/profile_collection/issues/3 for details), so commenting it out
        # yield from bps.abs_set(tiff.capture, 1)

        # Move to the starting positions
        yield from bps.mv(
            slt_gap,
            gap,  # Move gap to desired position
            slt_ctr,
            start - move_slack,  # Move slits to the beginning of the motion
            stats.ts_control,
            "Erase/Start",  # Prepare statistics Time Series
        )

        # Set Slits Center velocity for the scan
        yield from bps.mv(slt_ctr.velocity, speed)

        # Go
        yield from bps.kickoff(flyer, wait=True, group='kickoff')
        st = (yield from bps.complete(flyer))
        yield from bps.abs_set(slt_ctr, end + move_slack)

        while not st.done:
            yield from bps.collect(flyer, stream=True)
            yield from bps.sleep(0.2)

        yield from bps.sleep(1)
        yield from bps.collect(flyer, stream=True)

        yield from bps.mv(stats.ts_control, "Stop")

        # Stop the camera after the scan
        yield from bps.mv(cam.acquire, 0)  # Stop camera...