コード例 #1
0
def tune_usaxs_optics(side=False, md={}):
    """
    tune all the instrument optics currently in configuration

    This plan is for staff use.
    Users are advised to use preUSAXStune() instead.
    """
    yield from mode_USAXS()

    suspender_preinstalled = suspend_BeamInHutch in RE.suspenders
    if not suspender_preinstalled:
        yield from bps.install_suspender(suspend_BeamInHutch)

    yield from tune_mr(md=md)
    yield from tune_m2rp(md=md)
    if side:
        yield from tune_msrp(md=md)
        yield from tune_asrp(md=md)
    yield from tune_ar(md=md)
    yield from tune_a2rp(md=md)

    if not suspender_preinstalled:
        yield from bps.remove_suspender(suspend_BeamInHutch)

    yield from bps.mv(
        terms.preUSAXStune.num_scans_last_tune,
        0,
        terms.preUSAXStune.epoch_last_tune,
        time.time(),
    )
コード例 #2
0
    def scan_closure():
        # open shutter for beam
        yield from bps.mv(shutter, 'open')
        yield from bps.install_suspender(shutter_suspender)

        # config output
        for me in [det.tiff1, det.hdf1]:
            yield from bps.mv(me.file_path, fp)
            yield from bps.mv(me.file_name, fn)
            yield from bps.mv(me.file_write_mode, 2)
            yield from bps.mv(me.num_capture, total_images)
            yield from bps.mv(
                me.file_template,
                ".".join([r"%s%s_%06d", cfg['output']['type'].lower()]))

        if cfg['output']['type'] in ['tif', 'tiff']:
            yield from bps.mv(det.tiff1.enable, 1)
            yield from bps.mv(det.tiff1.capture, 1)
            yield from bps.mv(det.hdf1.enable, 0)
        elif cfg['output']['type'] in ['hdf', 'hdf1', 'hdf5']:
            yield from bps.mv(det.tiff1.enable, 0)
            yield from bps.mv(det.hdf1.enable, 1)
            yield from bps.mv(det.hdf1.capture, 1)
        else:
            raise ValueError(
                f"Unsupported output type {cfg['output']['type']}")

        # collect front white field
        yield from bps.mv(det.cam.frame_type,
                          0)  # for HDF5 dxchange data structure
        yield from collect_white_field(experiment, cfg['tomo'], atfront=True)

        # collect projections
        yield from bps.mv(det.cam.frame_type,
                          1)  # for HDF5 dxchange data structure
        if cfg['tomo']['type'].lower() == 'step':
            yield from step_scan(experiment, cfg['tomo'])
        elif cfg['tomo']['type'].lower() == 'fly':
            yield from fly_scan(experiment, cfg['tomo'])
        else:
            raise ValueError(f"Unsupported scan type: {cfg['tomo']['type']}")

        # collect back white field
        yield from bps.mv(det.cam.frame_type,
                          2)  # for HDF5 dxchange data structure
        yield from collect_white_field(experiment, cfg['tomo'], atfront=False)

        # collect back dark field
        yield from bps.mv(det.cam.frame_type,
                          3)  # for HDF5 dxchange data structure
        yield from bps.remove_suspender(shutter_suspender)
        yield from bps.mv(shutter, "close")
        yield from collect_dark_field(experiment, cfg['tomo'])
コード例 #3
0
ファイル: imprint.py プロジェクト: rajanplumley/cxi
def imprint_row(*args, events=1, min_mj=0.5):
    """
    Run a single row of the imprint scan

    Parameters
    ----------
    args: passed to bluesky.plans.scan

    events: int
        The number of events to allow at each stopping point in the scan

    min_mj, float, optional
        The minimum energy the scan should continue to execute scans

    Example
    -------
    .. code::

        # Run a scan from -1, 1 in 10 steps with 40 shots at each step
        RE(imprint_row(pi_x, -1, 1, 10, events=40))

        # Run a scan with two motors from -1, 1 and 12, 20, in five steps with
        # 10 shots at each step. Pause if we have less than 1 mJ in the GDET
        RE(imprint_row(pi_x, -1, 1,
                       cxi.kb2.hl, 12, 20, 5,
                       events=10, min_mj=1))
    """
    # Create a new suspender
    suspender = SuspendFloor(beam_stats.mj_avg, min_mj)
    # Install the new suspender
    yield from bps.install_suspender(suspender)
    # Execute a scan first configuring the Sequencer and DAQ
    try:
        yield from sequencer_mode(daq, sequencer, events, sequence_wait=.25)
        yield from bp.scan([daq, sequencer], *args)
    # Always ensure we remove the suspender
    finally:
        yield from bps.remove_suspender(suspender)
コード例 #4
0
    def scan_closure():
        # -------------------
        # collect white field
        # -------------------
        # 1-1 monitor shutter status, auto-puase scan if beam is lost
        yield from bps.open_run()
        yield from bps.mv(A_shutter, 'open')
        yield from bps.install_suspender(suspend_A_shutter)

        #1-1.5 configure output plugins     edited by Jason 07/19/2019
        for me in [det.tiff1, det.hdf1]:
            yield from bps.mv(me.file_path, fp)
            yield from bps.mv(me.file_name, fn)
            yield from bps.mv(me.file_write_mode, 2)
            yield from bps.mv(me.num_capture, total_images)
            yield from bps.mv(
                me.file_template,
                ".".join([r"%s%s_%06d", config['output']['type'].lower()]))

        if config['output']['type'] in ['tif', 'tiff']:
            yield from bps.mv(det.tiff1.enable, 1)
            yield from bps.mv(det.tiff1.capture, 1)
            yield from bps.mv(det.hdf1.enable, 0)
        elif config['output']['type'] in ['hdf', 'hdf1', 'hdf5']:
            yield from bps.mv(det.tiff1.enable, 0)
            yield from bps.mv(det.hdf1.enable, 1)
            yield from bps.mv(det.hdf1.capture, 1)
        else:
            raise ValueError(f"Unsupported output type {output_dict['type']}")

        # 1-2 move sample out of the way
        initial_samx = samX.position
        initial_samy = samY.position
        initial_preci = preci.position
        dx = config['tomo']['sample_out_position']['samX']
        dy = config['tomo']['sample_out_position']['samY']
        r = config['tomo']['sample_out_position']['preci']
        yield from bps.mv(samX, initial_samx + dx)
        yield from bps.mv(samY, initial_samy + dy)
        yield from bps.mv(preci, r)

        # 1-2.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 0)

        # 1-3 collect front white field images
        yield from bps.mv(det.hdf1.nd_array_port, 'PROC1')
        yield from bps.mv(det.tiff1.nd_array_port, 'PROC1')
        yield from bps.mv(det.proc1.enable, 1)
        yield from bps.mv(det.proc1.reset_filter, 1)
        yield from bps.mv(det.proc1.num_filter, n_frames)
        yield from bps.mv(det.cam.trigger_mode, "Internal")
        yield from bps.mv(det.cam.image_mode, "Multiple")
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.mv(det.cam.acquire_time, acquire_time)
        yield from bps.mv(det.cam.acquire_period, acquire_period)
        yield from bps.trigger_and_read([det])

        # 1-4 move sample back
        yield from bps.mv(samX, initial_samx)
        yield from bps.mv(samY, initial_samy)
        #yield from bps.mv(preci, initial_preci)

        # -------------------
        # collect projections
        # -------------------
        # 1-5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 1)
        # 1-6 step and fly scan are differnt
        if config['tomo']['type'].lower() == 'step':
            yield from bps.mv(det.proc1.reset_filter, 1)
            yield from bps.mv(det.cam.num_images, n_frames)
            # 1-6 collect projections
            for ang in angs:
                yield from bps.checkpoint()
                yield from bps.mv(preci, ang)
                yield from bps.trigger_and_read([det])
        elif config['tomo']['type'].lower() == 'fly':
            yield from bps.mv(det.proc1.num_filter, 1)
            yield from bps.mv(det.hdf1.nd_array_port, 'PG1')
            yield from bps.mv(det.tiff1.nd_array_port, 'PG1')
            yield from bps.mv(
                psofly.start,
                config['tomo']['omega_start'],
                psofly.end,
                config['tomo']['omega_end'],
                psofly.scan_delta,
                abs(config['tomo']['omega_step']),
                psofly.slew_speed,
                slew_speed,
            )
            # taxi
            yield from bps.mv(psofly.taxi, "Taxi")
            # setup detector to overlap for fly scan
            yield from bps.mv(
                det.cam.num_images,
                n_projections,
                det.cam.trigger_mode,
                "Overlapped",
            )
            # start the fly scan
            print("before trigger")
            yield from bps.trigger(det, group='trigger')
            print("waiting for trigger")
            # yield from bps.wait(group='trigger')
            print("before plan()")
            try:
                yield from psofly.plan()
            except NotEnoughTriggers as err:
                reason = (
                    f"{err.expected:.0f} were expected but {err.actual:.0f} were received."
                )
                yield from bps.close_run('fail', reason=reason)
                return  # short-circuit

            # fly scan finished. switch image port and trigger_mode back
            yield from bps.mv(det.cam.trigger_mode, "Internal")
            yield from bps.mv(det.hdf1.nd_array_port, 'PROC1')
            yield from bps.mv(det.tiff1.nd_array_port, 'PROC1')
        else:
            raise ValueError(f"Unknown scan type: {config['tomo']['type']}")

        # ------------------
        # collect back white
        # ------------------
        # 1-7 move the sample out of the way
        # NOTE:
        # this will return ALL motors to starting positions, we need a
        # smart way to calculate a shorter trajectory to move sample
        # out of way
        yield from bps.mv(preci, r)
        yield from bps.mv(samX, initial_samx + dx)
        yield from bps.mv(samY, initial_samy + dy)

        # 1-7.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 2)

        # 1-8 take the back white
        yield from bps.mv(det.proc1.num_filter, n_frames)
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.trigger_and_read([det])

        # 1-9 move sample back
        yield from bps.mv(samX, initial_samx)
        yield from bps.mv(samY, initial_samy)

        # -----------------
        # collect back dark
        # -----------------
        # 1-10 close the shutter
        yield from bps.remove_suspender(suspend_A_shutter)
        yield from bps.mv(A_shutter, "close")

        # 1-10.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 3)

        # 1-11 collect the back dark
        yield from bps.mv(det.cam.num_images, n_frames * n_dark)
        yield from bps.trigger_and_read([det])
        yield from bps.close_run('success')
コード例 #5
0
    def scan_closure():
        yield from bps.mv(det.cam.acquire_time, acquire_time)
        yield from bps.mv(det.cam.acquire_period, acquire_period)

        # -------------------
        # collect white field
        # -------------------
        # 1-1 monitor shutter status, auto-puase scan if beam is lost
        yield from bps.mv(A_shutter, 'open')
        yield from bps.install_suspender(suspend_A_shutter)

        # 1-2 move sample out of the way
        current_samx = samx.position
        current_samy = samy.position
        current_preci = preci.position
        dx = config['tomo']['sample_out_position']['samx']
        dy = config['tomo']['sample_out_position']['samy']
        dr = config['tomo']['sample_out_position']['preci']
        yield from bps.mv(samx, current_samx + dx)
        yield from bps.mv(samy, current_samy + dy)
        yield from bps.mv(preci, current_preci + dr)

        # 1-2.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 0)

        # 1-3 collect front white field images
        yield from bps.mv(det.proc1.enable, 1)
        yield from bps.mv(det.proc1.reset_filter, 1)
        yield from bps.mv(det.proc1.num_filter, n_frames)
        yield from bps.mv(det.cam.trigger_mode, "Internal")
        yield from bps.mv(det.cam.image_mode, "Multiple")
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.trigger_and_read([det])

        # 1-4 move sample back
        yield from bps.mv(samx, current_samx)
        yield from bps.mv(samy, current_samy)
        yield from bps.mv(preci, current_preci)

        # -------------------
        # collect projections
        # -------------------
        # 1-4.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 1)

        # 1-5 quicly reset proc1
        yield from bps.mv(det.proc1.reset_filter, 1)
        yield from bps.mv(det.cam.num_images, n_frames)

        # 1-6 collect projections
        for ang in angs:
            yield from bps.checkpoint()
            yield from bps.mv(preci, ang)
            yield from bps.trigger_and_read([det])

        # ------------------
        # collect back white
        # ------------------
        # 1-7 move the sample out of the way
        # NOTE:
        # this will return ALL motors to starting positions, we need a
        # smart way to calculate a shorter trajectory to move sample
        # out of way
        yield from bps.mv(preci, current_preci + dr)
        yield from bps.mv(samx, current_samx + dx)
        yield from bps.mv(samy, current_samy + dy)

        # 1-7.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 2)

        # 1-8 take the back white
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.trigger_and_read([det])

        # 1-9 move sample back
        yield from bps.mv(samx, current_samx)
        yield from bps.mv(samy, current_samy)
        yield from bps.mv(preci, current_preci)

        # -----------------
        # collect back dark
        # -----------------
        # 1-10 close the shutter
        yield from bps.remove_suspender(suspend_A_shutter)
        yield from bps.mv(A_shutter, "close")

        # 1-10.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 3)

        # 1-11 collect the back dark
        yield from bps.mv(det.cam.num_images, n_frames * n_dark)
        yield from bps.trigger_and_read([det])
コード例 #6
0
    def scan_closure():
        yield from bps.mv(det.cam.acquire_time, acquire_time)
        yield from bps.mv(det.cam.acquire_period, acquire_period)

        # -------------------
        # collect white field
        # -------------------
        # 1-1 monitor shutter status, auto-puase scan if beam is lost
        yield from bps.mv(A_shutter, 'open')
        yield from bps.install_suspender(suspend_A_shutter)

        # 1-2 move sample out of the way
        current_samx = samx.position
        current_samy = samy.position
        current_preci = preci.position
        dx = config['tomo']['sample_out_position']['samx']
        dy = config['tomo']['sample_out_position']['samy']
        dr = config['tomo']['sample_out_position']['preci']
        yield from bps.mv(samx, current_samx + dx)
        yield from bps.mv(samy, current_samy + dy)
        yield from bps.mv(preci, current_preci + dr)

        # 1-2.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 0)

        # 1-3 collect front white field images
        yield from bps.mv(det.proc1.enable, 1)
        yield from bps.mv(det.proc1.reset_filter, 1)
        yield from bps.mv(det.proc1.num_filter, n_frames)
        yield from bps.mv(det.cam.trigger_mode, "Internal")
        yield from bps.mv(det.cam.image_mode, "Multiple")
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.trigger_and_read([det])

        # 1-4 move sample back
        yield from bps.mv(samx, current_samx)
        yield from bps.mv(samy, current_samy)
        yield from bps.mv(preci, current_preci)

        # -------------------
        # collect projections
        # -------------------
        # 1-4.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 1)

        # 1-5 quicly reset proc1
        yield from bps.mv(det.proc1.reset_filter, 1)

        # 1-6 collect projections
        yield from motor_set_modulo(preci, 360.0)

        # configure the psofly interface
        yield from bps.mv(
            psofly.start,
            config['tomo']['omega_start'],
            psofly.end,
            config['tomo']['omega_end'],
            psofly.scan_control,
            "Standard",
            psofly.scan_delta,
            config['tomo']['omega_step'],
            psofly.slew_speed,
            slew_speed,
            preci.velocity,
            ROT_STAGE_FAST_SPEED,
            preci.acceleration,
            slew_speed / accl,
        )
        # taxi
        yield from bps.mv(psofly.taxi, "Taxi")
        yield from bps.mv(preci.velocity, slew_speed)
        # ???
        yield from bps.mv(
            det.cam.num_images,
            n_projections,
            det.cam.trigger_mode,
            "Overlapped",
        )
        # start the fly scan
        yield from bps.trigger(det, group='fly')
        yield from bps.abs_set(psofly.fly, "Fly", group='fly')
        yield from bps.wait(group='fly')

        # ------------------
        # collect back white
        # ------------------
        # 1-7 move the sample out of the way
        # NOTE:
        # this will return ALL motors to starting positions, we need a
        # smart way to calculate a shorter trajectory to move sample
        # out of way
        yield from bps.mv(preci, current_preci + dr)
        yield from bps.mv(samx, current_samx + dx)
        yield from bps.mv(samy, current_samy + dy)

        # 1-7.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 2)

        # 1-8 take the back white
        yield from bps.mv(det.cam.num_images, n_frames * n_white)
        yield from bps.trigger_and_read([det])

        # 1-9 move sample back
        yield from bps.mv(samx, current_samx)
        yield from bps.mv(samy, current_samy)
        yield from bps.mv(preci, current_preci)

        # -----------------
        # collect back dark
        # -----------------
        # 1-10 close the shutter
        yield from bps.remove_suspender(suspend_A_shutter)
        yield from bps.mv(A_shutter, "close")

        # 1-10.5 set frame type for an organized HDF5 archive
        yield from bps.mv(det.cam.frame_type, 3)

        # 1-11 collect the back dark
        yield from bps.mv(det.cam.num_images, n_frames * n_dark)
        yield from bps.trigger_and_read([det])