コード例 #1
0
    def load_sample(self, sample_number, sample_geometry=None):
        # If no sample is loaded, current_sample_number=0
        # is reported by the robot.
        if self.current_sample_number.get() != 0:
            raise RuntimeError("Sample %d is already loaded." %
                               self.current_sample_number.get())

        # Rotate theta into loading position if necessary (e.g. flat plate mode).
        load_pos = self.TH_POS[sample_geometry]['load']
        if load_pos is not None:
            print('Moving theta to load position')
            self.theta.move(load_pos, wait=True)

        # Loading the sample is a three-step procedure:
        # Set sample_number; issue load_cmd; issue execute_cmd.
        set_and_wait(self.sample_number, sample_number)
        set_and_wait(self.load_cmd, 1)
        self.execute_cmd.put(1)
        print('Loading...')
        self._poll_until_idle()

        # Rotate theta into measurement position if necessary (e.g. flat plate mode).
        measure_pos = self.TH_POS[sample_geometry]['measure']
        if measure_pos is not None:
            print('Moving theta to measure position')
            self.theta.move(measure_pos, wait=True)

        # Stash the current sample geometry for reference when we unload.
        self._current_sample_geometry = sample_geometry
コード例 #2
0
 def stage(self):
     # Ensure the plugin is enabled. We do not disable it on unstage
     if self.enable not in self.stage_sigs and 'enable' not in self.stage_sigs:
         if not self.enable.connected:
             self.enable.get()
         set_and_wait(self.enable, 1, atol=0)
     ADBase.stage(self)
コード例 #3
0
    def unload_sample(self):
        if self.current_sample_number.get() == 0:
            # there is nothing to do
            return

        # Rotate theta into loading position if necessary (e.g. flat plate mode)
        if self._current_sample_geometry == SAMPLE_GEOMETRY_NULL:
            raise RuntimeError(
                "Unknown current sample geometry, can not unload")
        load_pos = self.TH_POS[self._current_sample_geometry]['load']
        measure_pos = self.TH_POS[self._current_sample_geometry]['measure']
        print(load_pos, measure_pos)
        if load_pos is not None:
            print('Moving theta to unload position')
            if self._current_sample_geometry not in self.REL_MOVES:
                self.theta.move(load_pos, wait=True)
            else:
                pos = self.theta.get().user_readback
                self.theta.move(pos - measure_pos, wait=True)

        set_and_wait(self.unload_cmd, 1)
        self.execute_cmd.put(1)
        print('Unloading...')
        self._poll_until_idle()
        self._poll_until_sample_cleared()
        self._current_sample_geometry = SAMPLE_GEOMETRY_NULL
コード例 #4
0
    def stage(self):
        # Make a filename.
        filename, read_path, write_path = self.make_filename()

        # Ensure we do not have an old file open.
        if self.file_write_mode != 'Single':
            set_and_wait(self.capture, 0)
        # These must be set before parent is staged (specifically
        # before capture mode is turned on. They will not be reset
        # on 'unstage' anyway.
        self.file_path.set(write_path).wait()
        set_and_wait(self.file_name, filename)
        FileStoreBase.stage(self)

        # AD does this same templating in C, but we can't access it
        # so we do it redundantly here in Python.
        self._fn = self.file_template.get() % (
            read_path,
            filename,
            # file_number is *next* iteration
            self.file_number.get())
        self._fp = read_path
        if not self.file_path_exists.get():
            raise IOError("Path %s does not exist on IOC."
                          "" % self.file_path.get())
コード例 #5
0
def Override_AD_prime_plugin2(plugin):
    """Override faulty apstools implementation"""
    if Override_AD_plugin_primed(plugin):
        logger.debug("'%s' plugin is already primed", plugin.name)
        return

    sigs = OrderedDict([
        (plugin.enable, 1),
        (plugin.parent.cam.array_callbacks, 1),  # set by number
        (plugin.parent.cam.image_mode, 0),  # Single, set by number
        (plugin.parent.cam.trigger_mode, 0),  # set by number
        # just in case the acquisition time is set very long...
        (plugin.parent.cam.acquire_time, 1),
        (plugin.parent.cam.acquire_period, 1),
        (plugin.parent.cam.acquire, 1),  # set by number
    ])

    original_vals = {sig: sig.get() for sig in sigs}

    for sig, val in sigs.items():
        time.sleep(0.1)  # abundance of caution
        set_and_wait(sig, val)

    while plugin.parent.cam.acquire.get() not in (0, "Done"):
        time.sleep(.05)  # wait for acquisition to finish

    for sig, val in reversed(list(original_vals.items())):
        time.sleep(0.1)
        set_and_wait(sig, val)
コード例 #6
0
ファイル: 85-robot.py プロジェクト: CJ-Wright/ipython_ophyd
    def load_sample(sample_number, sample_type):
        # self.theta.move(self.TH_POS[sample_type]['load'], wait=True)
        set_and_wait(self.sample_number, sample_number)
        set_and_wait(self.load_cmd, 1)
        self.execute_cmd.put(1)

        while self.status.get() != 'Idle':
            time.sleep(.1)
コード例 #7
0
ファイル: hxn_xspress3.py プロジェクト: licode/hxntools
    def stop(self):
        super().stop()

        logger.info('Ensuring detector %r capture stopped...',
                    self.name)
        set_and_wait(self.settings.acquire, 0)
        self.hdf5.stop()
        logger.info('... detector %r ok', self.name)
コード例 #8
0
    def pause(self):
        set_val = 0
        set_and_wait(self.hdf5.capture, set_val)
        #val = self.hdf5.capture.get()
        ## Julien fix to ensure these are set correctly
        #print("pausing FCCD")
        #while (np.abs(val-set_val) > 1e-6):
            #self.hdf5.capture.put(set_val)
            #val = self.hdf5.capture.get()

        return super().pause()
コード例 #9
0
    def pause(self):
        set_val = 0
        set_and_wait(self.hdf5.capture, set_val)
        # val = self.hdf5.capture.get()
        ## Julien fix to ensure these are set correctly
        # print("pausing FCCD")
        # while (np.abs(val-set_val) > 1e-6):
        # self.hdf5.capture.put(set_val)
        # val = self.hdf5.capture.get()

        return super().pause()
コード例 #10
0
 def stage(self):
     res_uid = new_short_uid()
     write_path = datetime.now().strftime(self.write_path_template)
     set_and_wait(self.file_path, write_path)
     set_and_wait(self.file_write_name_pattern, '{}_$id'.format(res_uid))
     super().stage()
     fn = (PurePath(self.file_path.get()) / res_uid)
     ipf = int(self.file_write_images_per_file.get())
     # logger.debug("Inserting resource with filename %s", fn)
     self._fn = fn
     res_kwargs = {'images_per_file' : ipf}
     self._generate_resource(res_kwargs)
コード例 #11
0
    def stage(self):
        res_uid = new_short_uid()
        write_path = datetime.now().strftime(self.write_path_template)
        set_and_wait(self.file_path, write_path)
        set_and_wait(self.file_write_name_pattern, '{}_$id'.format(res_uid))
        super().stage()
        fn = (PurePath(self.file_path.get()) / res_uid).relative_to(
            self.reg_root)

        ipf = int(self.file_write_images_per_file.get())
        # logger.debug("Inserting resource with filename %s", fn)
        self._resource = self._reg.register_resource(self.resource_SPEC,
                                                     str(self.reg_root), fn,
                                                     {'images_per_file': ipf})
コード例 #12
0
    def stage(self):

        # pop both string and object versions to be paranoid
        self.stage_sigs.pop('cam.acquire', None)
        self.stage_sigs.pop(self.cam.acquire, None)

        # we need to take the detector out of acquire mode
        self._original_vals[self.cam.acquire] = self.cam.acquire.get()
        set_and_wait(self.cam.acquire, 0)
        # but then watch for when detector state
        while self.cam.detector_state.get(as_string=True) != 'Idle':
            ttime.sleep(.01)

        return super().stage()
コード例 #13
0
ファイル: test_utils.py プロジェクト: pshafer-als/ophyd
def test_none_signal():
    import itertools

    class CycleSignal(Signal):
        def __init__(self, *args, value_cycle, **kwargs):
            super().__init__(*args, **kwargs)
            self._value_cycle = itertools.cycle(value_cycle)

        def get(self):
            return next(self._value_cycle)

    cs = CycleSignal(name='cycle', value_cycle=[0, 1, 2, None, 4])

    set_and_wait(cs, 4, rtol=.01, atol=.01)
コード例 #14
0
    def stage(self):
        from ophyd.utils import set_and_wait
        import time as ttime

        # pop both string and object versions to be paranoid
        self.stage_sigs.pop('cam.acquire', None)
        self.stage_sigs.pop(self.cam.acquire, None)

        # we need to take the detector out of acquire mode
        self._original_vals[self.cam.acquire] = self.cam.acquire.get()
        set_and_wait(self.cam.acquire, 0)
        # but then watch for when detector state
        while self.cam.detector_state.get(as_string=True) != 'Idle':
            ttime.sleep(.01)

        return super().stage()
コード例 #15
0
    def unload_sample(self):
        if self.current_sample_number.get() == 0:
            # there is nothing to do
            return

        # Rotate theta into loading position if necessary (e.g. flat plate mode).
        load_pos = self.TH_POS[self._current_sample_geometry]['load']
        if load_pos is not None:
            print('Moving theta to unload position')
            self.theta.move(load_pos, wait=True)

        set_and_wait(self.unload_cmd, 1)
        self.execute_cmd.put(1)
        print('Unloading...')
        self._poll_until_idle()
        self._poll_until_sample_cleared()
        self._current_sample_geometry = None
コード例 #16
0
    def resume(self):
        set_val = 1
        set_and_wait(
            self.hdf5.capture,
            set_val)  # use acquire pv here rather than disable capture
        self.hdf5._point_counter = itertools.count()
        # The AD HDF5 plugin bumps its file_number and starts writing into a
        # *new file* because we toggled capturing off and on again.
        # Generate a new Resource document for the new file.

        # grab the stashed result from make_filename
        filename, read_path, write_path = self.hdf5._ret
        self.hdf5._fn = self.hdf5.file_template.get() % (
            read_path, filename, self.hdf5.file_number.get() - 1)
        # file_number is *next* iteration
        res_kwargs = {'frame_per_point': self.hdf5.get_frames_per_point()}
        self.hdf5._generate_resource(res_kwargs)

        return super().resume()
コード例 #17
0
    def warmup(self):
        """
        This method is overridden to use the num_capture/continuous mode with external triggering
        """
        set_and_wait(self.enable, 1)
        sigs = OrderedDict([
            (self.parent.cam.array_callbacks, 1),
            (self.parent.cam.image_mode, 'Single'),
            (self.parent.cam.trigger_mode, 'Internal'),
            # (self.num_capture, 1),
            # just in case tha acquisition time is set very long...
            (self.parent.cam.acquire_time, 1),
            (self.parent.cam.acquire_period, 1),
            (self.parent.cam.acquire_raw, 1)
        ])

        original_vals = {sig: sig.get() for sig in sigs}

        for sig, val in sigs.items():
            ttime.sleep(0.1)  # abundance of caution
            set_and_wait(sig, val)

        ttime.sleep(2)  # wait for acquisition

        for sig, val in reversed(list(original_vals.items())):
            ttime.sleep(0.1)
            set_and_wait(sig, val)
コード例 #18
0
    def resume(self):
        set_val = 1
        set_and_wait(self.hdf5.capture, set_val)
        self.hdf5._point_counter = itertools.count()
        # The AD HDF5 plugin bumps its file_number and starts writing into a
        # *new file* because we toggled capturing off and on again.
        # Generate a new Resource document for the new file.

        # grab the stashed result from make_filename
        filename, read_path, write_path = self.hdf5._ret
        self.hdf5._fn = self.hdf5.file_template.get() % (read_path,
                                               filename,
                                               self.hdf5.file_number.get() - 1)
                                               # file_number is *next* iteration
        res_kwargs = {'frame_per_point': self.hdf5.get_frames_per_point()}
        self.hdf5._generate_resource(res_kwargs)
        # can add this if we're not confident about setting...
        #val = self.hdf5.capture.get()
        #print("resuming FCCD")
        #while (np.abs(val-set_val) > 1e-6):
            #self.hdf5.capture.put(set_val)
            #val = self.hdf5.capture.get()
        #print("Success")
        return super().resume()
コード例 #19
0
    def stage(self):
        global proposal_id
        global run_id
        global current_sample

        set_and_wait(self.file_template, '%s%s_%6.6d_'+self.parent.detector_id+'.cbf', timeout=99999)
        if self.reset_file_number.get() == 1:
            set_and_wait(self.file_number, 1, timeout=99999)
        path = '/GPFS/xf16id/exp_path/'
        rpath = str(proposal_id)+"/"+str(run_id)+"/"
        fpath = path + rpath
        makedirs(fpath)
        set_and_wait(self.file_path, fpath, timeout=99999)
        set_and_wait(self.file_name, current_sample, timeout=99999)
        super().stage()
        res_kwargs = {'template': self.file_template.get(),
                      'filename': self.file_name.get(),
                      'frame_per_point': self.get_frames_per_point(),
                      'initial_number': self.file_number.get()}
        self._resource = fs.insert_resource('AD_CBF', rpath, res_kwargs, root=path)
コード例 #20
0
    def stage(self):
        global proposal_id
        global run_id
        global current_sample
        global data_path
        global collection_lock_file

        set_and_wait(self.file_template, '%s%s_%6.6d_'+self.parent.detector_id+'.cbf', timeout=99999)
        if self.reset_file_number.get() == 1:
            set_and_wait(self.file_number, 1, timeout=99999)

        # original code by Hugo
        # this is done now when login()
        #path = '/GPFS/xf16id/exp_path/'
        #rpath = str(proposal_id)+"/"+str(run_id)+"/"
        #fpath = path + rpath
        #makedirs(fpath)
        
        # modified by LY
        # camserver saves data to the local ramdisk, a background process then move them to data_path
        # interesting to note that camserver saves the data to filename.tmp, then rename it filename after done writing
        # must have the '/' at the end, since camserver will add it to the RBV
        # this should done only once for all Pilatus detectors
        if self.parent.name == first_Pilatus():
            #print("first Pilatus is %s" % self.parent.name)
            change_path()
        
        #set_and_wait(self.file_path, "/ramdisk/", timeout=99999)
        set_and_wait(self.file_path, data_path, timeout=99999)
        set_and_wait(self.file_name, current_sample, timeout=99999)
        
        super().stage()
        res_kwargs = {'template': self.file_template.get(),
                      'filename': self.file_name.get(),
                      'frame_per_point': self.get_frames_per_point(),
                      'initial_number': self.file_number.get()}
        #self._resource = fs.insert_resource('AD_CBF', rpath, res_kwargs, root=path)
        self._resource = fs.insert_resource('AD_CBF', data_path, res_kwargs, root="/")
        
        if self.parent.name == first_Pilatus():
            caput("XF:16IDC-ES:Sol{ctrl}ready", 1)
コード例 #21
0
    def stage(self):
        """
        overrides default behavior
        Set EPICS items before device is staged, then copy EPICS
        naming template (and other items) to ophyd after staging.
        """
        # Make a filename.
        filename, read_path, write_path = self.make_filename()

        # Ensure we do not have an old file open.
        set_and_wait(self.capture, 0)
        # These must be set before parent is staged (specifically
        # before capture mode is turned on. They will not be reset
        # on 'unstage' anyway.

        if not (write_path.endswith("/") or write_path.endswith("\\")):
            if write_path.find("\\") >= 0:
                write_path += "\\"
            else:
                write_path += "/"

        set_and_wait(self.file_path, write_path)
        set_and_wait(self.file_name, filename)
        ### set_and_wait(self.file_number, 0)

        # get file number now since it is incremented during stage()
        file_number = self.file_number.get()
        # Must avoid parent's stage() since it sets file_number to 0
        # Want to call grandparent's stage()
        #super().stage()     # avoid this - sets `file_number` to zero
        # call grandparent.stage()
        FileStoreBase.stage(self)

        # AD does the file name templating in C
        # We can't access that result until after acquisition
        # so we apply the same template here in Python.
        template = self.file_template.get()
        self._fn = template % (read_path, filename, file_number)
        self._fp = read_path
        if not self.file_path_exists.get():
            raise IOError("Path {} does not exist on IOC.".format(
                self.file_path.get()))

        self._point_counter = itertools.count()

        # from FileStoreHDF5.stage()
        res_kwargs = {'frame_per_point': self.get_frames_per_point()}
        self._generate_resource(res_kwargs)
コード例 #22
0
ファイル: anc350.py プロジェクト: licode/hxntools
    def setup_dc(self, enable, period, off_time, verify=True):
        enable = 1 if enable else 0
        period = int(period)
        off_time = int(off_time)

        self.dc_period.put(period)
        self.dc_off_time.put(off_time)

        if verify:
            set_and_wait(self.dc_period, period)
            set_and_wait(self.dc_off_time, off_time)

        self.dc_enable.put(enable)

        if verify:
            set_and_wait(self.dc_enable, enable)
コード例 #23
0
 def set(self, *args, **kwargs):
     set_and_wait(self.brake, 1)
     return self.gap.set(*args, **kwargs)
コード例 #24
0
 def set_input_edges(self, edge1, edge2):
     set_and_wait(self.input1.edge, int(edge1))
     set_and_wait(self.input2.edge, int(edge2))
コード例 #25
0
ファイル: test_utils.py プロジェクト: pshafer-als/ophyd
def test_array_into_softsignal():
    data = np.array([1, 2, 3])
    s = Signal(name='np.array')
    set_and_wait(s, data)
    assert np.all(s.get() == data)
コード例 #26
0
    def stage(self):
        global proposal_id
        global run_id
        global current_sample
        global data_path

        f_tplt = '%s%s_%06d_' + self.parent.detector_id + '.cbf'
        set_and_wait(self.file_template, f_tplt, timeout=99999)

        if self.parent.name == first_Pilatus(
        ) or self.parent.name == first_PilatusExt():
            #print("first Pilatus is %s" % self.parent.name)
            change_path()

        # if file number reset is Ture, use 1 as the next file #
        # if reset is False, when the first Pilatus/PilatusExt instance is staged, the file# will be
        # synchronized to the highest current value
        if PilatusFilePlugin.file_number_reset == 1:
            print("resetting file number for ", self.parent.name)
            # it is a bad idea to wait since auto-increment may change this value immediately
            #set_and_wait(self.file_number, 1, timeout=99999)
            self.file_number.put(1)
            print('done.')
        elif self.parent.name == first_Pilatus():
            next_file_number = np.max(
                [d.file.file_number.get() for d in pilatus_detectors])
            for d in pilatus_detectors:
                print("setting file number for %s to %d." %
                      (d.name, next_file_number))
                set_and_wait(d.file.file_number,
                             next_file_number,
                             timeout=99999)
        elif self.parent.name == first_PilatusExt():
            next_file_number = np.max(
                [d.file.file_number.get() for d in pilatus_detectors_ext])
            for d in pilatus_detectors_ext:
                print("setting file number for %s to %d." %
                      (d.name, next_file_number))
                set_and_wait(d.file.file_number,
                             next_file_number,
                             timeout=99999)

        if PilatusFilePlugin.sub_directory is not None:
            f_path = data_path + PilatusFilePlugin.sub_directory
            RE.md['subdir'] = PilatusFilePlugin.sub_directory
        else:
            f_path = data_path
            if 'subdir' in RE.md.keys():
                del RE.md['subdir']
        f_fn = current_sample
        # file_path must ends with '/'
        print('%s: setting file path ...' % self.name)
        #if DET_replace_data_path:
        if self.froot == data_file_path.ramdisk:
            #f_path = f_path.replace(default_data_path_root, substitute_data_path_root)
            f_path = f_path.replace(data_file_path.gpfs.value,
                                    data_file_path.ramdisk.value)
        set_and_wait(self.file_path, f_path, timeout=99999)
        #set_and_wait(self.file_path, f_path, timeout=99999)
        set_and_wait(self.file_name, f_fn, timeout=99999)
        self._fn = Path(f_path)

        fpp = self.get_frames_per_point()
        # when camserver collects in "multiple" mode, another number is added to the file name
        # even though the template does not specify it.
        # Camserver doesn't like the template to include the second number
        # The template will be revised in the CBF handler if fpp>1

        print('%s: super().stage() ...' % self.name)
        super().stage()
        res_kwargs = {
            'template': f_tplt,  # self.file_template(),
            'filename': f_fn,  # self.file_name(),
            'frame_per_point': fpp,
            'initial_number': self.file_number.get()
        }
        print('%s: _generate_resource() ...' % self.name)
        self._generate_resource(res_kwargs)
コード例 #27
0
 def set(self, *args, **kwargs):
     set_and_wait(self.brake, 1)
     return self.gap.set(*args, **kwargs)
コード例 #28
0
def take_image(plugin, filename=None):
    if filename is not None:
        set_and_wait(plugin.file_name, filename)
    set_and_wait(plugin.capture, 1)
    plugin.write_file.put(1)
コード例 #29
0
ファイル: test_utils.py プロジェクト: NSLS-II/ophyd
def test_array_into_softsignal():
    data = np.array([1, 2, 3])
    s = Signal(name='np.array')
    set_and_wait(s, data)
    assert np.all(s.get() == data)
コード例 #30
0
ファイル: anc350.py プロジェクト: licode/hxntools
def _dc_toggle(axis, enable, freq, dc_period, off_time):
    print('Axis {} {}: '.format(axis.axis_num, axis.desc.value), end='')
    set_and_wait(axis.frequency, freq)
    print('frequency={}'.format(axis.frequency.get()))
コード例 #31
0
def setup_plugin(plugin, filename):
    set_and_wait(plugin.file_template, '%s%s_%3.3d.tif')
    set_and_wait(plugin.file_path, '/reg/neh/home/zlentz/images/')
    set_and_wait(plugin.file_name, filename)
    set_and_wait(plugin.auto_increment, 1)
コード例 #32
0
 def trigger(self):
     status = super().trigger()
     set_and_wait(self.special_trigger_button, 1)
     return status
コード例 #33
0
 def stage(self):
     # before parent
     super().stage()
     # after parent
     set_and_wait(self.manual_trigger, 1)
コード例 #34
0
 def trigger(self, *args, **kwargs):
     status = super().trigger(*args, **kwargs)
     set_and_wait(self.special_trigger_button, 1)
     return status
コード例 #35
0
 def unstage(self):
     set_and_wait(self.manual_trigger, 0)
     super().unstage()
コード例 #36
0
 def stage(self, *args, **kwargs):
     # before parent
     ret = super().stage(*args, **kwargs)
     # after parent
     set_and_wait(self.manual_trigger, 1)
     return ret
コード例 #37
0
ファイル: test_utils.py プロジェクト: pshafer-als/ophyd
def test_set_signal_to_None():
    s = Signal(value='0', name='bob')
    set_and_wait(s, None, timeout=1)
コード例 #38
0
ファイル: zebra.py プロジェクト: NSLS-II-HXN/hxntools
 def set_input_edges(self, edge1, edge2):
     set_and_wait(self.input1.edge, int(edge1))
     set_and_wait(self.input2.edge, int(edge2))
コード例 #39
0
 def set(self, *args, **kwargs):
     from ophyd.utils import set_and_wait
     set_and_wait(self.brake, 1)
     return self.gap.set(*args, **kwargs)
コード例 #40
0
 def set_thresh(self, ene):
     """ set threshold
     """
     set_and_wait(self.ThresholdEnergy, ene)
     self.cam.threshold_apply.put(1)