예제 #1
0
    def storeChannel(self, chan, chanMask, preTrig, postTrig, clock, vins):
        if self.debugging():
            print "working on channel %d" % chan
        chan_node = self.__getattr__('input_%2.2d' % (chan + 1, ))
        if chan_node.on:
            if self.debugging():
                print "it is on so ..."
            if chanMask[chan:chan + 1] == '1':
                try:
                    start = max(
                        int(
                            self.__getattr__('input_%2.2d_startidx' %
                                             (chan + 1, ))), -preTrig)
                except:
                    start = -preTrig
                try:
                    end = min(
                        int(
                            self.__getattr__('input_%2.2d_endidx' %
                                             (chan + 1, ))), postTrig - 1)
                except:
                    end = postTrig - 1
                try:
                    inc = max(
                        int(self.__getattr__('input_%2.2d_inc' %
                                             (chan + 1, ))), 1)
                except:
                    inc = 1
#
# could do the coeffs
#

                if self.debugging():
                    print "about to readRawData(%d, preTrig=%d, start=%d, end=%d, inc=%d)" % (
                        chan + 1, preTrig, start, end, inc)
                try:
                    buf = self.readRawData(chan + 1, preTrig, start, end, inc,
                                           False)
                    if self.debugging():
                        print "readRawData returned %s\n" % (type(buf), )
                    if inc == 1:
                        dim = MDSplus.Dimension(
                            MDSplus.Window(start, end, self.trig_src), clock)
                    else:
                        dim = MDSplus.Dimension(
                            MDSplus.Window(start / inc, end / inc,
                                           self.trig_src),
                            MDSplus.Range(None, None,
                                          clock.evaluate().getDelta() * inc))
                    dat = MDSplus.Data.compile(
                        'build_signal(build_with_units((($1+ ($2-$1)*($value - -32768)/(32767 - -32768 ))), "V") ,build_with_units($3,"Counts"),$4)',
                        vins[chan * 2], vins[chan * 2 + 1], buf, dim)
                    exec('c=self.input_' + '%02d' % (chan + 1, ) +
                         '.record=dat')
                except Exception, e:
                    print "error processing channel %d\n%s\n" % (
                        chan + 1,
                        e,
                    )
예제 #2
0
 def evaluate_data(node):
     try:
         segszs = (1000, 100)
         for n in node.getMembers():
             name = n.getNodeName()
             sig = getSignal(name, True)
             if name.startswith("SEG"):
                 m.tcl('SET NODE %s /COMPRESS_SEGMENTS' % n.getPath())
                 data = sig.data()
                 dims = sig.dim_of().data()
                 duns = sig.dim_of().units
                 segsz = segszs[data.ndim] if data.ndim < 2 else 1
                 for i in range(int(data.shape[0] / segsz)):
                     ft = (i * segsz, (i + 1) * segsz)
                     img = data[ft[0]:ft[1]]
                     dim = m.Dimension(None, dims[ft[0]:ft[1]])
                     dim.setUnits(duns)
                     n.makeSegment(dims[ft[0]], dims[ft[1] - 1], dim, img)
                 # n.setUnits(sig.units)
                 # n.setHelp(sig.getHelp())
             else:
                 n.putData(sig)
         name = None
     finally:
         if name is not None:
             print(name)
예제 #3
0
파일: base.py 프로젝트: zack-vii/archive
 def _addim(dim, units='unknown'):
     if len(dim):
         dim = _mds.Dimension(None, tonumpy(dim))
         dim.setUnits(Units(units))  #
         return dim
     else:
         return None
예제 #4
0
    def storeChannel(self, name, chan, addr, pts, gain, offset):
        import MDSplus

        chan_node = self.__getattr__('input_%1.1d' % (chan + 1, ))
        if chan_node.on:
            if self.debug:
                print("it is on so ...")
            start = 0
            end = pts - 1
            try:
                start = max(
                    int(
                        self.__getattr__('input_%1.1d_start_idx' %
                                         (chan + 1, ))), 0)
            except:
                pass
            try:
                end = min(
                    int(self.__getattr__('input_%1.1d_end_idx' %
                                         (chan + 1, ))), pts - 1)
            except:
                pass
            if self.debug:
                print("about to aeon_getchannel(%s, %d, %d %d)" % (
                    name,
                    addr,
                    chan,
                    end + 1,
                ))
            buf = MDSplus.Data.execute('aeon_getchannel("%s", %d, %d, %d)' % (
                name,
                addr,
                chan,
                end + 1,
            ))
            dim = MDSplus.Dimension(MDSplus.Window(start, end, self.trigger),
                                    self.clock)
            if self.debug:
                print("about to make dat")
                print("gain = %d" % gain)
                print("offset =%d" % offset)
                print("dim is %s" % str(dim))
                print("start is %d end is %d" % (
                    start,
                    end,
                ))
            dat = MDSplus.Data.compile(
                'build_signal(build_with_units(($value - $2)*.02/$1, "V") ,build_with_units($3,"Counts"),$4)',
                gain, offset, buf[start:end], dim)
            exec('c=self.input_' + '%1d' % (chan + 1, ) + '.record=dat')
예제 #5
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()
예제 #6
0
파일: acqfmc.py 프로젝트: KambaVVV/mdsplus
    def _store_channel(self, chan, chan_offset, pre_trig, post_trig,
                       clock_node, vin):
        if self._debugging():
            print(('store_channel(): working on channel %d (+%d)' %
                   (chan, chan_offset)))

        chan_node = self.__getattr__('input_%02d' % chan)
        if chan_node.on:
            if self._debugging():
                print('store_channel(): channel is on')

            try:
                start_idx = max(
                    int(self.__getattr__('input_%02d_startidx' % chan)),
                    0 - pre_trig)
            except:
                start_idx = 0 - pre_trig

            try:
                end_idx = min(
                    int(self.__getattr__('input_%02d_endidx' % chan)),
                    post_trig - 1)
            except:
                end_idx = post_trig - 1

            try:
                inc = max(int(self.__getattr__('input_%02d_inc' % chan)), 1)
            except:
                inc = 1

            try:
                buf = self._read_raw_data(chan, chan_offset, pre_trig,
                                          start_idx, end_idx, inc)
                dim = MDSplus.Dimension(
                    MDSplus.Window(start_idx / inc, end_idx / inc,
                                   self.trig_src),
                    clock_node if inc == 1 else MDSplus.Range(
                        None, None,
                        clock_node.evaluate().getDelta() * inc))
                chan_node.record = MDSplus.Data.compile(
                    'BUILD_SIGNAL(BUILD_WITH_UNITS((($1 + ($2 - $1)*($VALUE - -32768)/(32767 - -32768))), "V"), BUILD_WITH_UNITS($3, "Counts"), $4)',
                    vin[0], vin[1], buf, dim)

            except Exception as ex:
                raise MDSplus.mdsExceptions.DevNOT_TRIGGERED(
                    'channel %d (+%d)\n%s' % (chan, chan_offset, str(ex)))
예제 #7
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()
예제 #8
0
    def store(self):
        uut = self.getUUT()

        while uut.statmon.get_state() != 0: 
            continue

        self.chans = []
        nchans = uut.nchan()

        for ii in range(nchans):
            self.chans.append(getattr(self, 'INPUT_%3.3d'%(ii+1)))

        channel_data = uut.read_channels()

        for ic, ch in enumerate(self.chans):
            if ch.on:
                
                start_idx     = - self.presamples.data() + 1
                end_idx       = self.postsamples.data()

                clock_period  = 1./self.freq.data()

                # When White Rabbit is used, we can get the trigger time from it:
                # self.wr_wrtd_t0 is the reference to the node in the WRTD device. (secs)
                # self.wr_wrtd_tai  is the reference to the node in WRTD device. (TAI time)
                # mdswindow = MDSplus.Window(start_idx, end_idx, self.wr_wrtd_t0)   
                # mdswindow = MDSplus.Window(start_idx, end_idx, self.wr_trig_tai)

                mdswindow = MDSplus.Window(start_idx, end_idx, 0)
                mdsrange  = MDSplus.Range(None, None, clock_period)
                dim       = MDSplus.Dimension(mdswindow, mdsrange)

                raw_signal = MDSplus.Signal(channel_data[ic], None, dim)
                ch.RAW_INPUT.putData(raw_signal)

        print("Storing data from all channels: done")
예제 #9
0
    def storeftp(self, arg):

        try:
            from xml.marshal.generic import load
        except:
            print "you must install PyXML to use this deprecated device.  Please switch to acq216 device type"

 	path = self.local_path
        tree = self.local_tree
        shot = self.tree.shot
        CPCIDataDir = os.getenv('CPCI_DATA_DIR')
	if not CPCIDataDir:
	    raise 'CPCI_DATA_DIR environment variable must be defined'
        dataDir="%s/%s/%s/%s"%(CPCIDataDir, tree, shot, path,)
        try :
	    settingsf = open("%s/settings.xml"%(dataDir,), "r")
	except :
	    raise Exception,"Could not open Settings file %s/settings.xml"%(dataDir,)
        try :
            settings = load(settingsf)
        except:
            settingsf.close()
	    raise Exception, "Could not parse XML settings"
        settingsf.close()
	if self.debugging() :
	    print "xml is loaded\n"
        status = []
        cmds = self.status_cmds.record
        for cmd in cmds:
	    cmd = cmd.strip()
	    if self.debugging():
		print "about to append answer for /%s/\n" % (cmd,)
		print "   which is /%s/\n" %(settings[cmd],)
	    status.append(settings[cmd])
	    if self.debugging():
		print "%s returned %s\n" % (cmd, settings[cmd],)
	if self.debugging():
	    print "about to write board_status signal"
	self.board_status.record = MDSplus.Signal(cmds, None, status)

        numSampsStr = settings['getNumSamples']
	preTrig = self.getPreTrig(numSampsStr)
        postTrig = self.getPostTrig(numSampsStr)
        if self.debugging():
            print "got preTrig %d and postTrig %d\n" % (preTrig, postTrig,)
        vins = MDSplus.makeArray(numpy.array(settings['get.vin'].split(',')).astype('float'))
        if self.debugging:
            print "got the vins "
            print vins
	self.ranges.record = MDSplus.makeArray(numpy.array(settings['get.vin'].split(',')).astype('float'))
        chanMask = settings['getChannelMask'].split('=')[-1]
        if self.debugging():
            print "chan_mask = %s\n" % (chanMask,)
        clock_src=str(self.clock_src.record.getOriginalPartName())[1:]
        if self.debugging():
            print "clock_src = %s\n" % (clock_src,)
        if clock_src == 'INT_CLOCK' :
	    intClock = float(settings['getInternalClock'].split()[1])
            delta=1./float(intClock)
            self.clock.record = MDSplus.Range(None, None, delta)
        else:
            self.clock.record = self.clock_src

        clock = self.clock.record
#
# now store each channel
#
	for chan in range(16):
	    if self.debugging():
		print "working on channel %d" % chan
            chan_node = self.__getattr__('input_%2.2d' % (chan+1,))
            if chan_node.on :
                if self.debugging():
                    print "it is on so ..."
                if chanMask[chan:chan+1] == '1' :
                    try:
                        start = max(int(self.__getattr__('input_%2.2d_startidx'%(chan+1,))),-preTrig)
                    except:
                        start = -preTrig
                    try:
			end = min(int(self.__getattr__('input_%2.2d_endidx'%(chan+1,))),postTrig-1)
                    except:
                        end = postTrig-1
                    try:
                        inc = max(int(self.__getattr__('input_%2.2d_inc'%(chan+1,))),1)
                    except:
                        inc = 1
#
# could do the coeffs
#
		    chanFileName="%s/%2.2d"%(dataDir, chan+1,)
                    if self.debugging():
			print "about to readRawData(%s, preTrig=%d, start=%d, end=%d, inc=%d)" % (chanFileName, preTrig, start, end, inc)
                    buf = self.readRawData(chanFileName, preTrig, start, end, inc)
		    if inc == 1:
			dim = MDSplus.Dimension(MDSplus.Window(start, end, self.trig_src ), clock)
                    else:
			dim = MDSplus.Data.compile('Map($,$)', MDSplus.Dimension(MDSplus.Window(start/inc, end/inc, self.trig_src), clock), MDSplus.Range(start, end, inc))
		    dat = MDSplus.Data.compile(
                        '_v0=$, _v1=$, build_signal(build_with_units(( _v0+ (_v1-_v0)*($value - -32768)/(32767 - -32768 )), "V") ,build_with_units($,"Counts"),$)',
                        vins[chan*2], vins[chan*2+1], buf,dim)
                    exec('c=self.input_'+'%02d'%(chan+1,)+'.record=dat')
	return 1
예제 #10
0
    def init(self, auto_store=None):
        import tempfile
        import time
        import uu
        import MDSplus
        import StringIO
        import subprocess
        import numpy
        """
        Initialize the device
        Send parameters
        Arm hardware
        """
        start=time.time()
        msg=None

	try:
            if self.debugging():
                print "starting init\n";
	    path = self.local_path
            tree = self.local_tree
            shot = self.tree.shot

            message = "max_samples must be a postiive integer"
            max_samples = int(self.max_samples)
            if max_samples < 0 :
                raise Exception(message)
            msg="Could not read clock source"
            clock_src=self.ao_clock.record.getOriginalPartName().getString()[1:]
            msg="Clock must be filled in with valid Range value"
            clock = self.__getattr__(clock_src.lower())
            if self.debugging():
                print "clock source is %s clock is %s\n"%(clock_src, clock,)
            msg="Could not read trigger source"
            trig_src=self.ao_trig.record.getOriginalPartName().getString()[1:]
            msg="Trigger time must be defined  at init time"
            trigger = self.__getattr__(trig_src.lower())
            msg="FAWG_DIV must be a postive integer"
            fawg_div = int(self.fawg_div)
            if fawg_div <= 0:
                raise Exception(message)
            message = "Could not retrieve the slope from the specified clock"
            delta = self.getDelta(clock.record)
            slope = delta*fawg_div

            msg="Could not read cycle type"
            cycle_type = str(self.cycle_type.record)
            if cycle_type not in self.cycle_types :
               raise Exception("cycle type must be one of %s\n" % (self.cycle_types,))
            msg="Could not read trigger type"
            trig_type = str(self.trig_type.record)
            if trig_type not in self.trig_types :
               raise Exception("trigger type must be one of %s\n" % (self.trig_types,))
            msg = "Error constructing output timebase"
            dim = MDSplus.Dimension(MDSplus.Window(0, max_samples-1, trigger), MDSplus.Range(None, None, slope)).data()

            msg = "Error writing initialization file"


#
# now create the post_shot ftp command file
#
            fd = tempfile.TemporaryFile()
            host = self.getMyIp()
            fd.write("acqcmd setAbort\n")
	    fd.write("host=%s\n"%(host,))
            fd.write("tree=%s\n"%(tree,))
            fd.write("shot=%s\n"%(shot,))
            fd.write("path='%s'\n"%(path,))

            for chan in range(16):
                if self.debugging():
                    print "working on channel %d" % chan
                chan_node = self.__getattr__('output_%2.2d' % (chan+1,))
                if chan_node.on :
                    if self.debugging():
                        print "it is on so ..."
                    try:
                        sig = chan_node.record
                        knots_x = sig.dim_of().data()
                        knots_y = sig.data()
                        fit_type = str(chan_node.getNode('fit').record)
                        if  fit_type not in self.fits:
                            raise Exception( "Error reading Fit for channel %d\n" %(chan+1,))
                    except Exception,e:
                        print "Error on channel %d - ZEROING\n%s\n" %(chan+1, e,)
                        knots_x = [0.0, 1.0]
                        knots_y = [0.0, 0.0]
                        fit_type='LINEAR'
                else:
                    if self.debugging():
                        print "   it is off so Zeroing\n"
                    knots_x = [0.0, 1.0]
                    knots_y = [0.0, 0.0]
                    fit_type='LINEAR'
                if self.debugging():
                    print "  call the fit\n"
                wave=self.doFit(knots_x, knots_y, dim, fit_type)
                if self.debugging():
                    print "  have the fit now subscript and scale"
                if len(wave) > max_samples:
                    wave = wave[0:max_samples-1]
                wave = wave/10.*2**15
                wave = wave.astype(numpy.int16)
#                uuinfd = StringIO.StringIO(wave)
                outname = "/dev/acq196/AO/f.%2.2d\n" % (chan + 1,)
                fd.write("cat - <<EOF | uudecode  -o %s" % (outname,))
                fd.flush()
                if self.debugging():
                    print "   ready to uuencode"
                p = subprocess.Popen(["uuencode", "-m", "%s"%(outname,)], stdout=fd, stdin=subprocess.PIPE)
                p.communicate(wave.tostring())
                fd.flush()
                fd.write("EOF\n")

            fd.write("set.ao_clk %s rising\n" %(clock_src,))
            fd.write("set.ao_trig %s rising\n" % (trig_src,))
            fd.write("set.dtacq FAWG_div %d\n" % (fawg_div))
            fd.write("set.dtacq AO_sawg_rate 10000\n")
            fd.write("set.arm.AO.FAWG %s %s\n" % (cycle_type, trig_type,))


            fd.flush()
            fd.seek(0,0)
	    print "Time to make init file = %g\n" % (time.time()-start)
	    start=time.time()
            self.doAOInit(fd)
	    fd.close()

	    print "Time for board to init = %g\n" % (time.time()-start)
            return  1