예제 #1
0
    def buffering(self):
        if not self.connected:
            print "Device not connected"
            return False
        count3 = PV('in_counts_3')
        count4 = PV('in_counts_4')
        low3 = PV('low_limit_3')
        low4 = PV('low_limit_4')
        trig_buffer = PV('trig_buffer')
        int_time = PV('analog_out_period')
        init = PV('initiate')
        poll(evt=1.e-5, iot=0.01)
        data1 = []
        data2 = []

        def getCount1(pvname, value, **kw):
            data1.append(value)

        def getCount2(pvname, value, **kw):
            data2.append(value)

        if util.put_check(
                low3, 0.0) and util.put_check(low4, 0.0) and util.put_check(
                    trig_buffer, 1000) and util.put_fuzzy(
                        'analog_out_period', 10e-5, 0.05):
            pass
        else:
            print "setting not taking place"
            return False, False

        time.sleep(1)
        count3.add_callback(getCount1)
        init.put(1)
        t0 = time.time()
        while time.time() - t0 < 3:

            poll(evt=1.e-5, iot=0.01)

        run1 = len(data1)
        count3.remove_callback(1)
        count3.add_callback(getCount2)
        if util.put_check(trig_buffer, 500):
            pass
        else:
            print "setting 2nd time not taking place"
            return False, False
        init.put(1)
        t1 = time.time()
        while time.time() - t1 < 3:
            poll(evt=1.e-5, iot=0.01)

        run2 = len(data2)

        return run1, run2
예제 #2
0
    def stopcount_value(self):

        if not self.connected:
            print "Device not connected"
            return False

        #util.pv_check('status', 0)

        #self.stop = 1001
        data1 = []
        data2 = []

        def getData1(pvname, value, **kw):
            if value != 0:
                data1.append(value)

        def getData2(pvname, value, **kw):
            if value != 0:
                data2.append(value)

        analog1 = PV('analogIn1')
        stop_count = PV('outStopCount')
        init = PV('initiate')
        analog2 = PV('analogIn2')
        poll(evt=1.e-5, iot=0.01)
        analog1.wait_for_connection()
        analog2.wait_for_connection()
        init.wait_for_connection()
        stop_count.wait_for_connection()
        util.put_check(stop_count, 100)
        analog1.add_callback(getData1)

        init.put(1)
        poll(evt=1.e-5, iot=0.01)
        t0 = time.time()
        while time.time() - t0 < 10:
            poll(evt=1.e-5, iot=0.01)

        first_run = len(data1)
        analog1.remove_callback(0)
        analog1.add_callback(getData2)

        time.sleep(2)
        util.put_check(stop_count, 200)
        init.put(1)
        poll(evt=1.e-5, iot=0.01)
        t0 = time.time()
        while time.time() - t0 < 10:
            poll(evt=1.e-5, iot=0.01)

        second_run = len(data2)

        return first_run, second_run
예제 #3
0
class ProfMon(object):
    """Generic Profile Monitor Object Class that references profile monitor MAD name"""
    def __init__(self, prof_name='OTR02'):
        if prof_name not in pc.PROFS.keys():
            raise ValueError('You have not specified a valid profile monitor')
        prof_dict = pc.PROFS[prof_name]
        self._prof_name = prof_name
        self._prof_set = PV(prof_dict['set'])
        self._prof_get = PV(prof_dict['get'])
        self._prof_image = PV(prof_dict['image'])
        self._prof_res = PV(prof_dict['res'])
        self._x_size = PV(prof_dict['xsize'])
        self._y_size = PV(prof_dict['ysize'])
        self._rate = PV(prof_dict['rate'])
        self._images = []
        self._data_thread = None
        self._gathering_data = False
        self._get_vars = self._prof_get.get_ctrlvars()['enum_strs']
        self._set_vars = self._prof_set.get_ctrlvars()['enum_strs']
        self._motion_state = self._get_vars[self._prof_get.get()]
        self._prof_get.add_callback(self._state_clbk, index=1)
        self._insert_clbk = None
        self._extract_clbk = None

    def _state_clbk(self, pvName=None, value=None, char_value=None, **kw):
        """Keep track of position/motion state"""
        self._motion_state = self._get_vars[value]

    @property
    def prof_name(self):
        """Get the profile monitor MAD name"""
        return self._prof_name

    @property
    def cur_image(self):
        """Get the current image array"""
        return self._prof_image.get()

    @property
    def saved_images(self):
        """Get the images collected"""
        return self._images

    @property
    def resolution(self):
        """Get the resolution"""
        return self._prof_res.get()

    @property
    def arr_dims(self):
        """Get the x and y dimensions"""
        return (self._x_size.get(), self._y_size.get())

    @property
    def rate(self):
        """Get the current rate"""
        return self._rate.get()

    @property
    def motion_state(self):
        """Get the current motion state of the profile monitor"""
        return self._motion_state

    @property
    def state(self):
        """Get the overall state of the profile monitor"""
        return self.__dict__

    def insert(self, user_clbk=None):
        """Generic call to insert profile monitor, can specify callback to be run"""
        if self._motion_state == pc.IN:
            print('{0}: {1}'.format(self._prof_name, pc.ALREADY_INSERTED))
            return

        if user_clbk:
            self._insert_clbk = user_clbk

        self._prof_get.add_callback(self._inserted, index=0)
        self._prof_set.put(pc.IN)

    def _inserted(self, pv_name=None, value=None, char_value=None, **kw):
        """Generic callback after profile monitor has been inserted, default"""
        if self._get_vars[value] == pc.IN:
            print('{0}: {1}'.format(self._prof_name, pc.INSERTED))

            if self._insert_clbk:
                self._insert_clbk()
                self._insert_clbk = None

            self._prof_get.remove_callback(index=0)

    def extract(self, usr_clbk=None):
        """Extract profile monitor command, can specify callback to be run"""
        if self._motion_state == pc.OUT:
            print('{0}: {1}'.format(self._prof_name, pc.ALREADY_EXTRACTED))
            return

        if user_clbk:
            self._extract_clbk = user_clbk

        self._prof_get.add_callback(self._extracted, index=0)
        self._prof_set.put(pc.OUT)

    def _extracted(self, pv_name=None, value=None, char_value=None, **kw):
        """Generic Callback for profile monitor that has been extracted, default"""
        if self._get_vars[value] == pc.OUT:
            print('{0}: {1}'.format(self._prof_name, pc.EXTRACTED))

            if self._extract_clbk:
                self._extract_clbk()
                self._extract_clbk = None

            self._prof_get.remove_callback(index=0)

    def acquire_images(self, images=1):
        """Start the thread"""
        self._data_thread = Thread(target=self._collect_image_data,
                                   args=(images, ))
        self._data_thread.start()

    def _collect_image_data(self, images, callback):
        """Threaded data collection"""
        self._gathering_data = True
        delay = 1.0 / self._rate.get()  # Rate must be in Hz
        i = 0
        while i < images:
            image = self._prof_image.get()
            if len(self._images) > 0 and array_equal(image, self._images[-1]):
                sleep(0.01)
            else:
                self._images.append(image)
                sleep(delay)
                i += 1
        if callback:  # Would want this to be pyqtSignal or Event notification type thing
            callback()
        self._gathering_data = False
        return  # No join, waste of a function
예제 #4
0
class RFCon(object):
    def __init__(self, station_name='GUN'):
        if station_name not in sc.STATIONS.keys():
            raise ValueError('You have not specified a valid RF Station')
        station_dict = sc.STATIONS[station_name]
        self._station_name = station_name
        self._am_lim = station_dict['a_lim']
        self._station_name = station_name
        self._mode = PV(station_dict['mode'])
        self._interval = PV(station_dict['interval'])
        self._amp_set = PV(station_dict['amp_set'])
        self._amp_get = PV(station_dict['amp_get'], form='time')
        self._phase_set = PV(station_dict['ph_set'])
        self._phase_get = PV(station_dict['ph_get'], form='time')
        self._detune = PV(station_dict['detune'])
        self._diff_nom = PV(station_dict['diff_nom'])
        self._freq_offset = PV(station_dict['freq_offset'])
        self._ssas_status = {
            name: PV(name)
            for name in station_dict['ssas_status']
        }
        self._ssa_status_vars = self._ssas_status.values()[0].get_ctrlvars(
        )['enum_strs']
        self._ssas_on = PV(station_dict['ssas_on'])
        self._ssas_off = PV(station_dict['ssas_off'])
        self._amp_data = []
        self._phase_data = []
        self._readings = 1
        self._gathering_data = False
        self._logger = logger.custom_logger(__name__)

    @property
    def name(self):
        """Get stations generic name"""
        return self._station_name

    @property
    def mode(self):
        """Get detune mode"""
        return self._mode.get()

    @property
    def interval(self):
        """Get repetion period"""
        return self._interval.get()

    @property
    def phase(self):
        """Get current phase"""
        return self._phase_get.get()

    @phase.setter
    def phase(self, val):
        """Set phase"""
        if not isinstance(val, float) or isinstance(val, int):
            self._logger.info('You have not entered an int or float')
            return

        self._phase_set.put(val)

    @property
    def amplitude(self):
        """Get current amplitude"""
        return self._amp_get.get()

    @amplitude.setter
    def amplitude(self, val):
        """Set amplitude"""
        if not isinstance(val, float) or isinstance(val, int):
            self._logger.info('You have not entered an int or float')
            return

        if val > self.am_lim:
            self._logger.info(
                'You are tyring to set the amplitude too high at {0}'.format(
                    val))
            return

        if val < 0:
            self._logger.info(
                'You are trying to set a negative amplitude, aborting')
            return

        self._amp_set.put(val)

    @property
    def detune(self):
        """Get detune value"""
        return self._detune.get()

    @property
    def diff_nominal(self):
        """Get diff from nominal"""
        return self._diff_nom.get()

    @property
    def freq_offset(self):
        """Get the frequency offset"""
        return self._freq_offset.get()

    @freq_offset.setter
    def freq_offset(self, val):
        """Set the frequency offset"""
        if not isinstance(val, float) or isinstance(val, int):
            self._logger.info('You have not entered an int or float')
            return

        self._amp_set.put(val)

    @property
    def amplitude_data(self):
        """Get the amplitude data"""
        return self._amp_data

    @property
    def phase_data(self):
        """Get the phase data"""
        return self._phase_data

    @property
    def amp_ave(self):
        """Get mean of amplitude data"""
        if not self._amp_data:
            self._logger.info('You have not gathering any amplitdue data')
            return None

        return np.mean(self._amp_data)

    @property
    def phase_ave(self):
        """Get the mean of the phase data"""
        if not self._phase_data:
            self._logger.info('You have not gathering any phase data')
            return None

        return np.mean(self._phase_data)

    @property
    def amp_std(self):
        """Get the std dev of the amplitude data"""
        if not self._amp_data:
            self._logger.info('You have not gathering any amplitdue data')
            return None

        return np.std(self._amp_data)

    @property
    def phase_std(self):
        """Get the std dev of the phase data"""
        if not self._phase_data:
            self._logger.info('You have not gathering any phase data')
            return None

        return np.std(self._phase_data)

    @property
    def ssas_status(self):
        """Get status of all SSAs for this rf station"""
        return [
            self._ssa_status_vars[ssa.get()]
            for ssa in self._ssas_status.values()
        ]

    def turn_off_ssas(self):
        """Turn off all SSAs"""
        self._ssas_off.put(sc.OFF)

    def turn_on_ssas(self):
        """Turn on all SSAs"""
        self._ssas_on.put(sc.ON)

    def acq_data(self, readings=1, clbk_fn=None):
        """Acquire a specified number of points to collect"""
        if not isinstance(readings, int):
            self._logger.info(
                'You need to enter an int for number of readings')
            return

        if self._gathering_data:
            self._logger.info('You are currently gathering data')
            return

        self._readings = readings
        self._amp_data = []
        self._phase_data = []
        self._gathering_data = True
        self._amp_get.add_callback(self._amp_acq_clbk,
                                   index=0,
                                   with_ctrlvars=False)
        self._phase_get.add_callback(self._phase_acq_clbk,
                                     index=0,
                                     with_ctrlvars=False)

    def _amp_acq_clbk(self,
                      pv_name=None,
                      value=None,
                      char_value=None,
                      timestamp=None,
                      **kw):
        """Amplitude callback"""
        self._amp_data.append(value)
        if len(self._amp_data) is self._readings:
            self._logger.info("finished gathering amplitude data")
            self._amp_get.remove_callback(index=0)
            self._check_data_acquire()

    def _phase_acq_clbk(self,
                        pv_name=None,
                        value=None,
                        char_value=None,
                        timestamp=None,
                        **kw):
        self._phase_data.append(value)
        if len(self._phase_data) is self._readings:
            self._logger.info("finished gathering phase data")
            self._phase_get.remove_callback(index=0)
            self._check_data_acquire()

    def _check_data_acquire(self):
        if len(self._amp_data) == len(self._phase_data) == self._readings:
            self._logger.info('All the data has been acquired')
            self._gathering_data = False
예제 #5
0
    def buffer_mode(self):
        data = []
        data2 = []

        if not self.connected:
            print "Device not connected"
            return False

        time.sleep(1)

        acquisition_mode = PV('acquisition_mode')
        buffered_mode = PV('buffered_acquisition')
        #stop_trig_source = PV('stop_trigger_source')
        stopcount = PV('stop_count')
        current1 = PV('current_in_1')
        init = PV('initiate')

        #util.put_check(acquisition_mode, 1)
        #util.put_check(buffered_mode, 1)
        #util.put_check(stop_trig_source, 0)
        #util.put_check(stopcount, 500)
        acquisition_mode.put(1)
        poll(evt=1.0, iot=1.0)
        #stop_trig_source.put(1)
        buffered_mode.put(1)
        poll(evt=1.0, iot=1.0)
        stopcount.put(500)
    
        poll(evt=1.0, iot=1.0)
        buff1 = buffered_mode.get()

        def getCount(pvname, value, **kw):
            data.append(value)

        def getCount2(pvname, value, **kw):
            data2.append(value)

        print caget('buffered_acquisition')
        print caget('stop_count')
        print caget('acquisition_mode')
        current1.add_callback(getCount)

        #caput('initiate', 1)
        init.put(1)
        poll(evt=1.e-5, iot=0.01)
        t0 = time.time()
        while time.time() - t0 < 12:
            poll(evt=1.e-5, iot=0.01)

        #caput('initiate', 0)
        poll(evt=1.e-5, iot=0.01)
        #util.put_check(buffered_mode, 0)
        poll(evt=1.e-5, iot=0.01)
        #util.put_check(stopcount, 0)
        buffered_mode.put(0)
        stopcount.put(0)
        poll(evt=1.e-5, iot=0.01)
        # print current1.callbacks
        current1.remove_callback(1)
        current1.add_callback(getCount2)
        poll(evt=1.e-5, iot=0.01)

        #caput('initiate', 1)
        init.put(1)
        poll(evt=1.e-5, iot=0.01)
        buff2 = buffered_mode.get()
        t1 = time.time()
        while time.time() - t1 < 10:
            if len(data2) >= 250:
                #caput('initiate', 0)
                init.put(0)
                break
            poll(evt=1.e-5, iot=0.01)

        current1.remove_callback(1)
        # stopcount.disconnect()
        # buffered_mode.disconnect()
        # current1.disconnect()

        return len(data), len(data2), buff1, buff2
예제 #6
0
class BPM(object):
    """Generic BPM Object class"""
    def __init__(self, bpm_name='BPM1B'):
        if bpm_name not in bc.BPMS.keys():
            raise ValueError('You have not specified a valid bpm')
        bpm_dict = bc.BPMS[bpm_name]
        self._name = bpm_name
        self._x = PV(bpm_dict['x'], form='time')
        self._y = PV(bpm_dict['y'], form='time')
        self._z = PV(bpm_dict['z'])
        self._tmit = PV(bpm_dict['tmit'], form='time')
        self._status = PV(bpm_dict['status'])
        self._alarm = PV(bpm_dict['alarm'])
        self._x_data = []
        self._y_data = []
        self._tmit_data = []
        self._readings = 1
        self._gathering_data = False
        self._logger = logger.custom_logger(__name__)
        self._data_clbk = None
        self._data_thread = None

    @property
    def name(self):
        """Get MAD name of bpm"""
        return self._name

    @property
    def x(self):
        """Get current x reading"""
        return self._x.get()

    @property
    def y(self):
        """Get current y reading"""
        return self._y.get()

    @property
    def z(self):
        """Get z position"""
        return self._z.get()

    @property
    def tmit(self):
        """Get current tmit reading"""
        return self._tmit.get()

    @property
    def current_data(self):
        """Get the current x, y, and tmit data tuple"""
        return (self._x_data, self._y_data, self._tmit_data)

    @property
    def gathering_data(self):
        """Get bool indicating whether the bpm is gathering data or not"""
        return self._gathering_data

    @property
    def x_ave(self):
        """Get the average of the x data list"""
        if not self._x_data:
            self._logger.info("You have no x data")
            return None

        return np.mean(self._x_data)

    @property
    def y_ave(self):
        """Get the average of the y data list"""
        if not self._y_data:
            self._logger.info("You have no y data")
            return None

        return np.mean(self._y_data)

    @property
    def tmit_ave(self):
        """Get the average of the tmit data list"""
        if not self._tmit_data:
            self._logger.info("You have no tmit data")
            return None

        return np.mean(self._tmit_data)

    @property
    def x_std(self):
        """Get the average of the x data list"""
        if not self._x_data:
            self._logger.info("You have no x data")
            return None

        return np.std(self._x_data)

    @property
    def y_std(self):
        """Get the average of the y data list"""
        if not self._y_data:
            self._logger.info("You have no y data")
            return None

        return np.std(self._y_data)

    @property
    def tmit_std(self):
        """Get the average of the tmit data list"""
        if not self._tmit_data:
            self._logger.info("You have no tmit data")
            return None

        return np.std(self._tmit_data)

    @property
    def status(self):
        """Get the status of the bpm"""
        return self._status.get()

    @property
    def alarm(self):
        """Get the alarm status"""
        return self._alarm.get()

    def acquire_data(self, readings=1, user_clbk=None):
        """Acquire a number of readings, defaults to 1"""
        if not isinstance(readings, int):
            self._logger.info(
                'You did not enter an int for number of readings')
            return

        if self._gathering_data:
            self._logger.info("You are already gathering data")
            return

        if user_clbk:
            self._data_clbk = user_clbk

        self._readings = readings
        self.clear_data()
        self._gathering_data = True

        self._data_thread = Thread(target=self.watcher)
        self._data_thread.start()

        self._x.add_callback(self._x_acq_clbk, index=0, with_ctrlvars=False)
        self._y.add_callback(self._y_acq_clbk, index=0, with_ctrlvars=False)
        self._tmit.add_callback(self._tmit_acq_clbk,
                                index=0,
                                with_ctrlvars=False)

    def watcher(self):
        """Watch for all the data to be done"""
        while not len(self._x_data) == len(self._y_data) == \
                len(self._tmit_data) == self._readings:
            time.sleep(0.1)
        if self._data_clbk:
            self._data_clbk()
            self._data_clbk = None
        return

    def _x_acq_clbk(self,
                    pv_name=None,
                    value=None,
                    char_value=None,
                    time_stamp=None,
                    **kw):
        """x data callback"""
        self._x_data.append(value)
        if len(self._x_data) is self._readings:
            self._x.remove_callback(0)

    def _y_acq_clbk(self,
                    pv_name=None,
                    value=None,
                    char_value=None,
                    time_stamp=None,
                    **kw):
        """y data callback"""
        self._y_data.append(value)
        if len(self._y_data) is self._readings:
            self._y.remove_callback(0)

    def _tmit_acq_clbk(self,
                       pv_name=None,
                       value=None,
                       char_value=None,
                       time_stamp=None,
                       **kw):
        """tmit data callback"""
        self._tmit_data.append(value)
        if len(self._tmit_data) is self._readings:
            self._tmit.remove_callback(0)

    def clear_data(self):
        """Clear the x, y, tmit data"""
        self._x_vals = []
        self._y_vals = []
        self._tmit_vals = []