예제 #1
0
    def store(self):
        event_name = self.data_event.data()
        if self.t2.rlength == 0:
            self.t2.record = MDSplus.Int64(time.time() * 1000.)
        trend_tree = self.getTrendTree()
        trend_dev = trend_tree.getNode(self.trend_device.data())

        # Getting T1 from TREND:
        t1 = MDSplus.Int64(self.t1.data() * 1000.)

        #Saving TREND shot number information into the tree:
        self.trend_shot.record = trend_tree.getCurrent(self.trend_tree.data())

        #Set Time Context
        trend_tree.setTimeContext(t1, self.t2.data())

        print('Writing data into shot node')
        for i in self.inputs():
            trend_temp = trend_dev.__getattr__('input_%c' % (chr(i)))
            trend_resis = trend_dev.__getattr__('input_%c_resistence' %
                                                (chr(i)))

            times = trend_temp.dim_of().data()
            temps = trend_temp.data()
            resists = trend_resis.data()

            # Might be able to improve
            start_time = times[0]
            for j in range(len(times)):
                times[j] -= start_time
                times[j] = float(times[j]) / 1000.

            shot_temp = self.__getattr__('input_%c' % (chr(i)))
            shot_resis = self.__getattr__('input_%c_resistence' % (chr(i)))

            shot_temp.record = MDSplus.Signal(temps, None, times)
            shot_resis.record = MDSplus.Signal(resists, None, times)

        for i in self.loops():
            trend_outpower = trend_dev.__getattr__('loop_%c' % (str(i + 1)))
            times = trend_outpower.dim_of().data()
            outpower = trend_outpower.data()

            start_time = times[0]
            for j in range(len(times)):
                times[j] -= start_time
                times[j] = float(times[j]) / 1000.

            shot_outpower = self.__getattr__('loop_%c' % (str(i + 1)))
            shot_outpower.record = MDSplus.Signal(outpower, None, times)

        MDSplus.Event.setevent(event_name)
예제 #2
0
 def decompile(self):
     self.assertEqual(str(m.Uint8(123)), '123BU')
     self.assertEqual(str(m.Uint16(123)), '123WU')
     self.assertEqual(str(m.Uint32(123)), '123LU')
     self.assertEqual(str(m.Uint64(123)), '123QU')
     self.assertEqual(str(m.Int8(123)), '123B')
     self.assertEqual(str(m.Int16(123)), '123W')
     self.assertEqual(str(m.Int32(123)), '123')
     self.assertEqual(str(m.Int64(123)), '123Q')
     self.assertEqual(
         str(m.Signal(m.ZERO(100000, 0).evaluate(), None, 0)),
         "Build_Signal(Set_Range(100000,0 /*** etc. ***/), *, 0)")
예제 #3
0
파일: base.py 프로젝트: zack-vii/archive
 def _dim(time, t0):
     if len(time):
         t0 = _mds.Int64(t0)
         time = _mds.Int64Array(time)
         if t0 == 0:
             unit = 'ns'
         else:
             time = _mds.Float64(time - t0) * 1E-9
             unit = 's'
         wind = _mds.Window(time[0], time[time.shape[0] - 1], t0)
         dim = _mds.Dimension(wind, time)
         dim.setUnits(unit)
         return dim
     else:
         return _mds.EmptyData()
예제 #4
0
                def run(self):
                    def time_rel(ns=1e9):
                        return MDSplus.DIVIDE(MDSplus.Int64(ns),
                                              self.frame_rate)

                    try:
                        cur_frame = 0
                        rng = MDSplus.Range(None, None, time_rel())
                        while True:
                            try:
                                queued = self.queue.get(True, 1)
                            except queue.Empty:
                                if self.strm.on:
                                    continue
                                break  # measurement done
                            if queued is None:
                                break
                            trigger, frames = queued
                            if self.fsttrig is None:
                                self.fsttrig = trigger
                            trigger = MDSplus.Int64(trigger - self.fsttrig)
                            trg = MDSplus.ADD(self.trigger, trigger)
                            first_frame = cur_frame
                            for ic in range(frames.shape[0]):
                                dim = MDSplus.ADD(trg,
                                                  time_rel([cur_frame * 1e9]))
                                limit = MDSplus.ADD(trg,
                                                    time_rel(cur_frame * 1e9))
                                data = frames[ic:ic + 1]
                                self.frames.makeSegment(
                                    limit, limit, dim, data)
                                cur_frame += 1
                            last_frame = cur_frame - 1
                            win = MDSplus.Window(first_frame, last_frame, trg)
                            start = MDSplus.ADD(trg,
                                                time_rel(first_frame * 1e9))
                            end = MDSplus.ADD(trg, time_rel(last_frame * 1e9))
                            dim = MDSplus.Dimension(win, rng)
                            frames = frames.reshape(
                                (frames.shape[0], -1)).max(1)
                            self.frames_max.makeSegment(
                                start, end, dim, frames)
                            self.queue.task_done()
                    except Exception as e:
                        self.exception = e
                        traceback.print_exc()
예제 #5
0
 def run(self):
     while not self.stopped.wait(0.01):
         if (self.index == len(self.data) - 1):
             self.stopped.set()
         MDSplus.Event.stream(1, 'LIFT_COIL_DEMAND',
                              MDSplus.Int64((time.time()) * 1000),
                              MDSplus.Float64(self.data[self.index]))
         #            data = json.dumps({u'absolute_time': 0,
         #                    u'shot': 1,
         #                    u'name': u'LIFT_COIL_DEMAND',
         #                    u'timestamp': int(time.time()),
         #                    u'times': [(time.time()-self.start_time)*1000],
         #                    u'seq_number': self.index,
         #                    u'samples': [self.data[self.index]]})
         #            print(data.__class__)
         #            print(np.array(data))
         #            MDSplus.Event.setevent('LIFT_COIL_DEMAND',np.array(data))
         self.index += 1
예제 #6
0
    def trend(self):
        # start it trending
        self.running.on = True

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((str(self.node.data()), 5000))

        # open the instrument
        if self.debugging():
            print("about to open cryocon device %s" % str(self.node.data()))

        event_name = self.data_event.data()

        try:
            self.status_out.getData()
        except:
            if self.debugging():
                print(
                    "Status_Out tree node is empty. Lets write the data now.")
            # read and save the status commands
            status_out = {}

            for cmd in self.status_cmds:
                if self.debugging():
                    print('about to send %s' % cmd)

                # status_out[str(cmd)] = instrument.query(str(cmd))
                status_out[str(cmd)] = self.queryCommand(s, str(cmd))

                if self.debugging():
                    print('  got back %s' % status_out[str(cmd)])

            self.status_out.record = status_out

        # Control Loop PID values Numeric Entry The Pgain, Igain and Dgain lines correspond to the Proportional,
        # Integral and Derivative coefficients of the control loop. Pman is the output power that will be applied
        # to the load if the manual control mode is selected.
        # Values for the Proportional, or P, gain term range from zero to 1000. This is a unit- less gain term
        # that is applied to the control loop. Gain is scaled to reflect the actual heater range and the load resistance.
        # Integrator gain values range from zero to 10,000. The units of this term are Seconds. A value of zero
        # turns the integration function off.
        # Derivative gain values have units of inverse Seconds and may have values from zero to 1000. A value of
        # zero turns the Derivative control function off.

        for i in self.loops():
            # Proportional gain, or P term for PID control.
            # This is a numeric field that is a percent of full scale.
            pgain_chan = self.__getattr__('loop_%c_propor_gain' % (str(i + 1)))
            pgain_query_cmd = 'LOOP %c:PGA?' % (str(i + 1), )

            # Integrator gain term, in Seconds, for PID control.
            # This is a numeric field that is a percent of full scale.
            igain_chan = self.__getattr__('loop_%c_integr_gain' % (str(i + 1)))
            igain_query_cmd = 'LOOP %c:IGA?' % (str(i + 1), )

            # Derivative gain term, in inverse-Seconds, for PID control.
            # This is a numeric field that is a percent of full scale.
            dgain_chan = self.__getattr__('loop_%c_deriva_gain' % (str(i + 1)))
            dgain_query_cmd = 'LOOP %c:DGA?' % (str(i + 1), )

            spoint_chan = self.__getattr__('loop_%c_setpoint' % (str(i + 1)))
            spoint_query_cmd = 'LOOP %c:SETP?' % (str(i + 1), )

            ansQuery = self.queryCommand(s, pgain_query_cmd)

            try:
                pgain_chan.getData()
                igain_chan.getData()
                dgain_chan.getData()
            except:
                try:
                    print("Parsing Proportional Gain /%s/" % ansQuery)
                    pgain = float(ansQuery)
                except:
                    if self.debugging():
                        print("Could not parse Proportional Gain /%s/" %
                              ansQuery)
                    pgain = 0.0

                pgain_chan.record = MDSplus.Float32(pgain)

                ansQuery = self.queryCommand(s, igain_query_cmd)

                try:
                    print("Parsing Integral Gain /%s/" % ansQuery)
                    igain = float(ansQuery)
                except:
                    if self.debugging():
                        print("Could not parse Integral Gain /%s/" % ansQuery)
                    igain = 0.0

                igain_chan.record = MDSplus.Float32(igain)

                ansQuery = self.queryCommand(s, dgain_query_cmd)

                try:
                    print("Parsing Derivative Gain /%s/" % ansQuery)
                    dgain = float(ansQuery)
                except:
                    if self.debugging():
                        print("Could not parse Derivative Gain /%s/" %
                              ansQuery)
                    dgain = 0.0

                dgain_chan.record = MDSplus.Float32(dgain)

                ansQuery = self.queryCommand(s, spoint_query_cmd)

                try:
                    print("Parsing Setpoint /%s/" % ansQuery)
                    spoint = float(ansQuery)
                except:
                    if self.debugging():
                        print("Could not parse Setpoint /%s/" % ansQuery)
                    spoint = 0.0

                spoint_chan.record = MDSplus.Float32(spoint)

        for i in self.inputs():
            t_chans = self.__getattr__('input_%c' % (chr(i)))
            r_chans = self.__getattr__('input_%c_resistence' % (chr(i)))
            if t_chans.on:
                query_cmd_temp = 'INP %c:TEMP?;SENP?' % (chr(i), )
                ansQuery = self.queryCommand(s, query_cmd_temp)

                t_time = time.time()

                # Temperature reading
                try:
                    temps = float(ansQuery.split(';')[0])
                    is_digit = True
                except ValueError:
                    is_digit = False
                    if self.debugging():
                        print("Could not parse temperature /%s/" %
                              ansQuery.split(';')[0])
                if not is_digit:
                    temps = -9999.0

                t_chans.putRow(1000, MDSplus.Float32(temps),
                               MDSplus.Int64(t_time * 1000.))

                # Resistence reading
                try:
                    resists = float(ansQuery.split(';')[1])
                    is_digit = True
                except ValueError:
                    is_digit = False
                    if self.debugging():
                        print("Could not parse resist /%s/" %
                              ansQuery.split(';')[1])
                if not is_digit:
                    resists = -9999.0

                r_chans.putRow(1000, MDSplus.Float32(resists),
                               MDSplus.Int64(t_time * 1000.))

        for i in self.loops():
            p_chans = self.__getattr__('loop_%c' % (str(i + 1)))
            query_cmd_outp = 'LOOP %c:HTRRead?' % (str(i + 1), )
            ansQuery = self.queryCommand(s, query_cmd_outp)
            answerOutp = ansQuery[:
                                  -1]  #remove the '%' at the end of the number

            if p_chans.on:
                t_time = time.time()
                # Output Power reading: Queries the output power of the selected control loop.
                # This is a numeric field that is a percent of full scale.
                try:
                    print("Parsing output power /%s/" % ansQuery)
                    if 'NAK' not in ansQuery:
                        outpower = float(answerOutp)
                    else:
                        outpower = float(-9999.0)
                except ValueError:
                    if self.debugging():
                        print("Could not parse output power /%s/" % ansQuery)

                p_chans.putRow(1000, MDSplus.Float32(outpower),
                               MDSplus.Int64(t_time * 1000.))

        MDSplus.Event.setevent(event_name)
        s.close()
예제 #7
0
 def time_rel(ns=1e9):
     return MDSplus.DIVIDE(MDSplus.Int64(ns),
                           self.frame_rate)
예제 #8
0
    def trend(self):
        '''
        trend method for cryocon18i

        record the values of the status commands
        start the stream

        STILL NEEDS TO STORE Calibration CURVES !!

        Store one sample for each of the channels that is on using
        putRow.  The timestamp will be time since the unix EPOCH in msec
        '''

        # start it trending
        self.running.on = True

        event_name = self.data_event.data()

        if self.debugging():
            print("About to open cryocon device %s" % str(self.node.data()))

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((str(self.node.data()), 5000))

        try:
            self.status_out.getData()
        except:
            # read and save the status commands
            status_out = {}
            for cmd in self.status_cmds:
                if self.debugging():
                    print('about to send %s' % cmd)
                status_out[str(cmd)] = self.queryCommand(s, str(cmd))
                if self.debugging():
                    print('  got back %s' % status_out[str(cmd)])
            self.status_out.record = status_out

            # for i in range(ord('a'), ord('h')+1+1):
            #    chan = self.__getattr__('input_%c'%(chr(i),))
            #    if chan.on:
            #      cal = self.__getattr__('input_%c_calibration'%(chr(i),))
            #      ans = self.queryCommand(s, 'CALCUR %c?'%(chr(i)))
            #      print(ans)
            #      cal.record = ans
            #print(self.queryCommand(s, 'CALCUR'))

        query_cmd = ''
        ansQuery = []
        for i in self.inputs:
            t_chan = self.__getattr__('input_%c' % (i, ))
            if t_chan.on:
                query_cmd = 'INP %c?;INP %c:SENP?;' % (i, i)
                ansQuery = self.queryCommand(s, query_cmd)[:-1].split(';')
                t_time = time.time()

                try:
                    temp = float(ansQuery[0])
                except:
                    if self.debugging():
                        print("Could not parse temperature /%s/" % ansQuery[0])
                    temp = 0.0

                t_chan.putRow(1000, MDSplus.Float32(temp),
                              MDSplus.Int64(t_time * 1000.))

                r_chan = self.__getattr__('input_%c_resistence' % (i, ))
                try:
                    resist = float(ansQuery[1])
                except:
                    if self.debugging():
                        print("Could not parse resist /%s/" % ansQuery[1])
                    resist = 0.0

                r_chan.putRow(1000, MDSplus.Float32(resist),
                              MDSplus.Int64(t_time * 1000.))

        MDSplus.Event.setevent(event_name)
        s.close()