Ejemplo n.º 1
0
def create_test_shot(shot_number, tree_name=TEST_TREE_NAME):
    """Create a shot using all of the MDSplus data types.

    Note: this is incomplete, so not all datatypes are present yet.
    """
    t = MDSplus.Tree(tree_name, shot_number, mode="NEW")
    t.addNode('node_A')
    t.addNode('node_B')

    node_a = t.getNode('node_A')
    node_a.setUsage("SIGNAL")
    node_a.addTag("tag_A")

    node_a.addNode('node_AA')
    node_a.addNode('node_AB')

    sig = MDSplus.Signal(MDSplus.makeArray(numpy.random.poisson(lam=10, size=SIGNAL_LENGTH)), 
                         None, MDSplus.makeArray(0.1*numpy.arange(SIGNAL_LENGTH)))
    node_a.putData(sig)

    node_aa = t.getNode('\\test::top.node_A.node_AA')
    node_aa.addTag("tag_AA")
    node_aa.addNode("node_AAA")

    node_ab = t.getNode('\\test::top.node_A.node_AB')
    str_data = MDSplus.StringArray(["elmt1", "elmt2"])
    node_ab.putData(str_data)
    
    t.setCurrent('test', shot_number)
    t.write()
Ejemplo n.º 2
0
        def start(self):
            def validate(node, value):
                node.write_once = node.no_write_shot = False
                try:
                    node.record = node.record.setValidation(value)
                finally:
                    node.write_once = node.no_write_shot = True

            def store_temp(node, new):
                if isinstance(new, (float, )):
                    node.record = MDSplus.Float64([new])
                elif isinstance(new, (int, )):
                    node.record = MDSplus.Uint32([new])

            try:
                validate(self.frame_rate,
                         MDSplus.Float32(self.cygnet4k.frame_rate))
                validate(self.exposure,
                         MDSplus.Float32(self.cygnet4k.exposure))
                validate(self.trig_mode,
                         MDSplus.Uint8(self.cygnet4k.trig_mode))
                validate(self.binning, MDSplus.Int8(self.cygnet4k.binning))
                validate(self.roi_rect, MDSplus.Int16(self.cygnet4k.roi_rect))
                aoi = self._roi_rect
                cmos, pcb = self.cygnet4k.start_capture_stream(
                    self._num_frames, aoi, self._stream, self.frames,
                    self.frames_max)
                store_temp(self.temp_cmos, cmos)
                store_temp(self.temp_pcb, pcb)
            except CygnetExcConnect:
                raise MDSplus.DevOFFLINE
            except CygnetExcValue:
                raise MDSplus.DevINV_SETUP
            except CygnetExcComm:
                raise MDSplus.DevIO_STUCK
Ejemplo n.º 3
0
 def testmds(expt='test', shot=1):
     import gc
     gc.collect()
     MDSplus.setenv('test_path', '/tmp')
     from LocalDevices.cygnet4k import CYGNET4K
     with MDSplus.Tree(expt, shot, 'NEW') as t:
         dev = CYGNET4K.Add(t, "CYGNET4K")
         t.write()
         dev.conf_file.no_write_shot = False
         dev.conf_file = "/etc/xcap_cygnet4k.fmt"
         dev.roi_rect.no_write_shot = False
         dev.roi_rect = MDSplus.Int32([500, 500, 1000, 1000])
     old = MDSplus.Device.debug
     MDSplus.Device.debug = 0  #max(1,old)
     t.open()
     try:
         dev.init()
         sleep(1)
         dev.start()
         sleep(1)
         dev.stop()
     finally:
         dev.deinit()
         print(dev.frames_max.getRecord(None))
         t.close()
         MDSplus.Device.debug = old
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def addfun(name,code,_file_=__file__):
    """
    can be used to add customized python functions to the tdi environment
    e.g.:
        >>> ADDFUN("myfun","def myfun(a): print(a)")
        "MYFUN"
        >>> MYFUN(3)
        3
        *
    in order to prevent the function to load more than once use:
        >>> IF_ERROR(PUBLIC("MYFUN2"),ADDFUN("myfun2","def myfun2(a): print(a)"))
        "MYFUN2"
    """
    name   = str( name .data() if isinstance( name ,MDSplus.Data) else  name )
    _file_ = str(_file_.data() if isinstance(_file_,MDSplus.Data) else _file_)
    mdsname = name.upper()
    if not modulename in sys.modules:
       sys.modules[modulename] = types.ModuleType(modulename)
    code = MDSplus.Data.data(code)
    env = {}
    exec(compile(code,"TDI/%s"%(name,),'exec'),env,env)
    module_dict = sys.modules[modulename].__dict__
    module_dict[mdsname] = env[name]
    module_dict["__file__%s"%mdsname] = _file_
    mdsname = MDSplus.String(mdsname)
    return MDSplus.EQUALS(MDSplus.PUBLIC(mdsname),mdsname).evaluate()
Ejemplo n.º 6
0
def main(argv):
    timesleep = 60  #secs
    tree = MDSplus.Tree('daqtest', -1)
    node = tree.ACQ_161.NODE.data()

    print("Open daqtest tree {} {}".format(tree, node))
    tree = MDSplus.Tree('daqtest', -1)

    time.sleep(1)
    shot = int(sys.argv[1])
    print("Shot # {}".format(shot))
    tree.setCurrent(shot)
    tree.createPulse(0)
    tree = MDSplus.Tree('daqtest', 0)

    tree.ACQ_161.init()

    for remaining in range(timesleep, 0, -1):
        sys.stdout.write("\r")
        sys.stdout.write("{:2d} seconds remaining.".format(remaining))
        sys.stdout.flush()
        time.sleep(1)

    sys.stdout.write("\n\rShot Complete!\n")

    tree.ACQ_161.stop()
    tree.close()
    time.sleep(5)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def create_tree(tree_path):
    if not os.path.exists(tree_path):
        os.mkdir(tree_path)
    os.environ["test_path"] = tree_path
    for shot_number in xrange(1, 4):
        t = MDSplus.Tree("test", shot_number, mode="NEW")
        t.addNode("node_A")
        t.addNode("node_B")

        node_a = t.getNode("node_A")
        node_a.setUsage("SIGNAL")
        node_a.addTag("tag_A")

        node_a.addNode("node_AA")
        node_a.addNode("node_AB")

        mds_arr = MDSplus.makeArray(numpy.random.poisson(lam=10, size=SIGNAL_LENGTH))
        mds_dim = MDSplus.makeArray(0.1 * numpy.arange(SIGNAL_LENGTH))
        sig = MDSplus.Signal(mds_arr, None, mds_dim)
        node_a.putData(sig)

        node_aa = t.getNode("\\test::top.node_A.node_AA")
        node_aa.addTag("tag_AA")
        node_aa.addNode("node_AAA")

        t.setCurrent("test", shot_number)
        t.write()
Ejemplo n.º 9
0
def setNode(treename='test', shot=3):
    import MDSplus
    with MDSplus.Tree(treename, shot) as tree:
        node = tree.getNode('opt')
        MDSplus.TdiExecute('_time=*')
        node.putData(
            MDSplus.TdiCompile(b'opttest($,IF_ERROR(_time,*))', (node, )))
Ejemplo n.º 10
0
 def addField(node,name,v):
     k = _sup.fixname12(name)
     if isinstance(v, (_ver.basestring, )):
         pn = node.addNode(k, 'TEXT').putData(_ver.tobytes(v))
     elif isinstance(v, (int, float)):
         pn = node.addNode(k, 'NUMERIC').putData(v)
     elif isinstance(v, (list,)):
         if isinstance(v[0], _ver.numbers):
             pn = node.addNode(k, 'NUMERIC').putData(_mds.makeArray(v))
         else:
             pn = node.addNode(k, 'ANY').putData(v)
     elif isinstance(v, (dict,)):
         if '['+str(len(v)-1)+']' in v.keys():
             v = [v['['+str(i)+']'] for i in _ver.xrange(len(v))]
             if all(isinstance(vi, _ver.numbers) for vi in v):
                 pn = node.addNode(k, 'NUMERIC').putData(_mds.makeArray(v))
             else:
                 try:
                     pn = node.addNode(k, 'ANY').putData(v)
                 except:
                     pn.putData([str(i) for i in v])
         else:
             try:
                 pn = node.addNode(k,'TEXT')
                 for vk,vv in v.items():
                     addField(pn,vk,vv)
                 try: pn.setUsage('STRUCTURE')
                 except: _sup.debug(pn.minpath,2)
             except:
                 pn.putData(str(v))
     pn.addNode('$NAME','TEXT').record = name
Ejemplo n.º 11
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,
                    )
Ejemplo n.º 12
0
        def run(self):
            def lcm(a,b):
                from fractions import gcd
                return (a * b / gcd(int(a), int(b)))

            def lcma(arr):
                ans = 1.
                for e in arr:
                    ans = lcm(ans, e)
                return int(ans)

            if self.dev.debug:
                print("MDSWorker running")

            event_name = self.dev.seg_event.data()

            trig = self.dev.trigger.data()
            if self.dev.hw_filter.length > 0:
                dt = 1./self.dev.freq.data() * 2 ** self.dev.hw_filter.data()
            else:
                dt = 1./self.dev.freq.data()

            decimator = lcma(self.decim)

            if self.seg_length % decimator:
                self.seg_length = (self.seg_length // decimator + 1) * decimator

            self.dims = []
            for i in range(self.nchans):
                self.dims.append(MDSplus.Range(0., (self.seg_length-1)*dt, dt*self.decim[i]))

            self.device_thread.start()

            segment = 0
            first = True
            running = self.dev.running
            max_segments = self.dev.max_segments.data()
            while running.on and segment < max_segments:
                try:
                    buf = self.full_buffers.get(block=True, timeout=1)
                except Queue.Empty:
                    continue

                buffer = np.right_shift(np.frombuffer(buf, dtype='int32') , 8)
                i = 0
                for c in self.chans:
                    if c.on:
                        b = buffer[i::self.nchans*self.decim[i]]
                        c.makeSegment(self.dims[i].begin, self.dims[i].ending, self.dims[i], b)
                        self.dims[i] = MDSplus.Range(self.dims[i].begin + self.seg_length*dt, self.dims[i].ending + self.seg_length*dt, dt*self.decim[i])
                    i += 1
                segment += 1
                MDSplus.Event.setevent(event_name)

                self.empty_buffers.put(buf)

            self.dev.trig_time.record = self.device_thread.trig_time - ((self.device_thread.io_buffer_size / np.int32(0).nbytes) * dt)
            self.device_thread.stop()
Ejemplo n.º 13
0
    def _pre_store(self):
        board_addr = self._get_board_addr()
        board_site = self._get_board_site()
        uut_sys = UUT(board_addr, self._sys_port, debug=self._debugging())
        uut_mod = UUT(board_addr,
                      self._sys_port + board_site,
                      debug=self._debugging())

        # check if arming was performed in a different shot
        if self.tree.shot != int(uut_mod.send('shot')):
            raise MDSplus.mdsExceptions.DevWRONG_SHOT

        # check if device is still armed
        nums = uut_sys.send('state').split(' ')
        state = int(nums[0])
        if state == 1 or state == 2:
            raise MDSplus.mdsExceptions.DevNOT_TRIGGERED(
                'device was armed but not triggered')

        # wait for STOP
        for i in range(self._store_retries):
            if state == 0:
                break
            time.sleep(1)
            nums = uut_sys.send('state').split(' ')
            state = int(nums[0])
        if state != 0:
            print('warning: device not ready')

        # read samples
        pre_trig = int(nums[1])
        post_trig = int(nums[2])
        if pre_trig + post_trig == 0:
            print('error: device was not armed')
            raise MDSplus.mdsExceptions.DevNOT_TRIGGERED(
                'device was not armed')

        # read and store clocks
        intclk = float(uut_mod.send('sysclkhz'))
        mbclk = float(uut_sys.send('SIG:CLK_MB:FREQ').split(' ')[1])
        clk = float(
            uut_sys.send('SIG:CLK_S%d:FREQ' % board_site).split(' ')[1])
        try:
            self.int_clock.record = MDSplus.Range(None, None, 1. / intclk)
            self.sys_clock.record = MDSplus.Range(None, None, 1. / mbclk)
            # TODO: handle module internal clock
            self.clock.record = MDSplus.Range(None, None, 1. / clk)
        except MDSplus.mdsExceptions.TreeNOOVERWRITE:
            print('warning: retrying store method')

        # compute channel offset due to lower-numbered sites
        offset = 0
        for i in range(1, board_site):
            offset += int(uut_sys.send('get.site %d NCHAN' % i))
        if self._debugging():
            print(('pre_store(): channel offset = %d' % offset))

        return (pre_trig, post_trig, offset)
Ejemplo n.º 14
0
def get_mds_active_probes(shot, tunnel=True):
    """
    Get the probes that were active during the shot. Used in main function.
        shot: the shot you want
    """

    # MDSplus connection to atlas where the data is store on the "LANGMUIR" tree.
    if tunnel:
        conn = mds.Connection("localhost")
    else:
        conn = mds.Connection('atlas.gat.com')
    conn.openTree("LANGMUIR", shot)

    tmin = conn.get("\LANGMUIR::TOP.TMIN").data()
    tmax = conn.get("\LANGMUIR::TOP.TMAX").data()
    runid = conn.get("\LANGMUIR::TOP.RUNID").data()

    mds_index = []
    found_probes = []
    for mds_pnum in range(1, 85):

        # Make sure probe name is in correct formart: 001, 002, ... , 084, 085.
        if mds_pnum < 10:
            probe = "00" + str(mds_pnum)
        else:
            probe = "0" + str(mds_pnum)

        # The complete path name to the lp. PNUM is the probe number, which does
        # not match its number in mdsplus (001 - 085).
        pname = "\LANGMUIR::TOP.PROBE_" + probe + ".PNUM"

        # Get the actual probe number if it is there. Not all MDS probes are used.
        try:
            check_pnum = conn.get(pname).data()
        except:
            pass
            #print "No data in probe " + str(probe) + "."

        # It will be '0' or blank if the MDS entry isn;t used. Otherwise it will
        # have the actual probe number in it.
        if check_pnum > 0:
            print("Probe " + str(check_pnum) + " is MDS probe " +
                  str(mds_pnum))
            mds_index.append(mds_pnum)
            found_probes.append(check_pnum)

    number_of_probes = len(found_probes)
    print("Found data for " + str(number_of_probes) + " probes.")

    # Store in dictionary and return it.
    active = {}
    active["tmin"] = tmin
    active["tmax"] = tmax
    active["runid"] = runid
    active["probes"] = found_probes
    active["mds_index"] = mds_index

    return active
Ejemplo n.º 15
0
 def _stream(dim, data, node, nodemax):
     nodemax.makeSegment(dim, dim, MDSplus.Float32([dim]),
                         MDSplus.Uint16([numpy.max(data)]))
     if MDSplus.Device.debug:
         print('storeFrame: %s, %s, %s' %
               (node.minpath, dim, data.shape))
     dims = MDSplus.Float32([dim]).setUnits('s')
     data = MDSplus.Uint16([data])
     node.makeSegment(dim, dim, dims, data)
Ejemplo n.º 16
0
        def run(self):
            def lcm(a,b):
                from fractions import gcd
                return (a * b / gcd(int(a), int(b)))

            def lcma(arr):
                ans = 1.
                for e in arr:
                    ans = lcm(ans, e)
                return int(ans)

            if self.dev.debug:
                print("MDSWorker running")

            event_name = self.dev.seg_event.data()

            trig = self.dev.trigger.data()
            if self.dev.hw_filter.length > 0:
                dt = 1./self.dev.freq.data() * 2 ** self.dev.hw_filter.data()
            else:
                dt = 1./self.dev.freq.data()

            decimator = lcma(self.decim)
             
            self.device_thread.start()

            segment = 0
            begin   = 0.0
            first = True
            running = self.dev.running
            max_segments = self.dev.max_segments.data()

            while running.on and segment < max_segments:
                try:
                    buf = self.full_buffers.get(block=True, timeout=1)
                except Empty:
                    continue

                buffer = np.right_shift(np.frombuffer(buf, dtype='int32') , 8)
                i = 0
                for c in self.chans:
                    if c.on:
                        b = buffer[i::self.nchans*self.decim[i]]
                        
                        dim_limits=[begin, begin + self.seg_length*dt - 1]
                        cull_dim  =MDSplus.CULL(dim_limits, None, MDSplus.Range(begin, begin + self.seg_length*dt -1, dt*self.decim[i]))
                        c.makeSegment(begin, begin + self.seg_length*dt, cull_dim, b)

                    i += 1
                segment += 1
                begin   += self.seg_length*dt
                MDSplus.Event.setevent(event_name)

                self.empty_buffers.put(buf)

            self.dev.trig_time.record = self.device_thread.trig_time - ((self.device_thread.io_buffer_size / np.int32(0).nbytes) * dt)
            self.device_thread.stop()
Ejemplo n.º 17
0
 def tdiPythonInterface(self):
     self._doTdiTest("Py('a=None')", 1)
     self._doTdiTest("Py('a=None','a')", None)
     self._doTdiTest("Py('a=123','a')", 123)
     self._doTdiTest("Py('import MDSplus;a=MDSplus.Uint8(-1)','a')",
                     m.Uint8(255))
     self._doTdiTest("pyfun('Uint8','MDSplus',-1)", m.Uint8(255))
     self._doTdiTest("pyfun('Uint8',*,-1)", m.Uint8(255))
     self._doTdiTest("pyfun('str',*,123)", m.String("123"))
Ejemplo n.º 18
0
def getVSP(shot):
    VSP = []
    VSP += [
        MDSplus.Tree('dtacq0', shot).getNode('.CH93').getData().data().mean()
    ]
    VSP += [
        MDSplus.Tree('dtacq0', shot).getNode('.Ch94').getData().data().mean()
    ]
    return VSP
Ejemplo n.º 19
0
 def difftree(treename1, shot1, treename2, shot2, exclude):
     import MDSplus as _mds
     """
     dd = difftree('W7X', -1, 'W7X', 100, '\ARCHIVE::TOP')
     pprint(dd[0])
     """
     treedict1 = treeToDict(_mds.Tree(treename1, shot1), exclude)
     treedict2 = treeToDict(_mds.Tree(treename2, shot2), exclude)
     treediff = DeepDiff(treedict1, treedict2)
     return treediff, _sup.obj(treedict1), _sup.obj(treedict2)
Ejemplo n.º 20
0
 def sendU(self):
     if self.sim_index >= len(self.u):
         self.sim_index = 0
         self.sim_time = 0.0
     MDSplus.Event.stream(0, 'U', MDSplus.Float32(self.sim_time),
                          MDSplus.Float64(self.u[self.sim_index]))
     self.ui.Ulabel.setText(str(self.u[self.sim_index]))
     self.sim_index += 1
     self.ui.UNextlabel.setText(str(self.u[self.sim_index]))
     self.sim_time += .01
Ejemplo n.º 21
0
def writedata(data, dims, nodepath, expt, shot):
    """ data: list of images """
    """ dims: array of double seconds based on T1 """
    tree = _mds.Tree(expt, shot)
    node = tree.getNode(nodepath)
    node.deleteData()
    for i in range(len(data)):
        dim = _mds.Float64Array(dims[i])
        dim.setUnits('s')
        node.makeSegment(dims[i], dims[i], dim, _mds.makeArray(data[i]), -1)
Ejemplo n.º 22
0
 def dicttotree(dic, node):
     for k, v in dic.items():
         print(node.getPath() + ':' + k[0:12])
         newnode = node.getNode(k[0:12])
         if isinstance(v, dict):
             dicttotree(v, newnode)
         elif isinstance(v, (tuple, list)):
             newnode.putData(_mds.makeArray(v))
         else:
             newnode.putData(_mds.makeScalar(v))
Ejemplo n.º 23
0
 def dicttotree(dic, node):
     for k,v in dic.items():
         print(node.getPath()+':'+k[0:12])
         newnode = node.getNode(k[0:12])
         if isinstance(v, dict):
             dicttotree(v, newnode)
         elif isinstance(v, (tuple, list)):
             newnode.putData(_mds.makeArray(v))
         else:
             newnode.putData(_mds.makeScalar(v))
Ejemplo n.º 24
0
def modECE(tree='archive', shot=-1):
    with _mds.Tree(tree, shot, 'edit') as arc:
        stream = arc.CDSD16007.DRPD17547
        for i in range(32):
            node = stream.getNode('CH%d' % i)
            try:
                ece = node.addNode('$ECE', 'SIGNAL')
            except:
                ece = node.getNode('$ECE')
            ece.record = _mds.TdiCompile('ECE($)', (node, ))
        arc.write()
Ejemplo n.º 25
0
 def _stream(dim, data, dev):
     dev.tree.open()
     dev.frames_percentile.makeSegment(
         dim, dim, MDSplus.Float32([dim]),
         MDSplus.Uint16([numpy.percentile(data, 99)]))
     if MDSplus.Device.debug & 1:
         print('storeFrame: %s, %s, %s' %
               (dev.minpath, dim, data.shape))
     dims = MDSplus.Float32([dim]).setUnits('s')
     data = MDSplus.Uint16([data])
     dev.frames.makeSegment(dim, dim, dims, data)
Ejemplo n.º 26
0
 def getSubTrees(expt='W7X',
                 shot=-1,
                 excludelist=('ARCHIVE', ),
                 excludereg=('.*_EVAL', )):
     rematch = tuple(_re.compile(reg) for reg in excludereg)
     tree = _mds.Tree(expt, shot)
     subtrees = [
         _mds.TreeNode(c.nid, tree) for c in tree.top.getChildren()
         if c.usage == 'SUBTREE' and not (c.node_name in excludelist)
         and all(re.match(str(c.node_name)) is None for re in rematch)
     ]
     return subtrees
Ejemplo n.º 27
0
    def toMds(self):

        if not self.amend:
            Model = mds.Tree('tcv_topic21')
            Model.createPulse(self.shot)
            del Model
        self.saveTree = mds.Tree('tcv_topic21', self.shot)
        if not self.amend:
            self._Lp2Mds()
            self._Lambda2Mds()
        self._Fp2Mds()
        self.saveTree.quit()
Ejemplo n.º 28
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)")
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
def get_mds_lp_data(shot, mds_index, tunnel=True):
    """
    Get LP data for a single probe. Used in main function.
        shot: the shot you want
        mds_index: a number 1-85 that corresponds to the mds node. These do not
            match the probe number (which is PNUM).
    """

    # MDS connection required through atlas tunnel.
    if tunnel:
        conn = mds.Connection("localhost")
    else:
        conn = mds.Connection("atlas.gat.com")
    conn.openTree("LANGMUIR", shot)

    # Use correct form of probe name.
    if mds_index < 10:
        probe = "00" + str(mds_index)
    else:
        probe = "0" + str(mds_index)

    pname = "\LANGMUIR::TOP.PROBE_" + probe

    # All the data stored in a dictionary. All the data is in the subtree
    # indicated in pname. Just specify the node and grab the data.
    lp_data = {}
    lp_data["time"] = conn.get(pname + ":TIME").data()
    lp_data["rprobe"] = conn.get(pname + ":R").data()
    lp_data["zprobe"] = conn.get(pname + ":Z").data()
    lp_data["label"] = conn.get(pname + ":LABEL").data()
    lp_data["ntimes"] = conn.get(pname + ":NTIMES").data()
    lp_data["pnum"] = conn.get(pname + ":PNUM").data()
    lp_data["isat"] = conn.get(pname + ":ISAT").data()
    lp_data["jsat"] = conn.get(pname + ":JSAT").data()
    lp_data["temp"] = conn.get(pname + ":TEMP").data()
    lp_data["dens"] = conn.get(pname + ":DENS").data()
    lp_data["pot"] = conn.get(pname + ":POT").data()
    lp_data["psin"] = conn.get(pname + ":PSIN").data()
    lp_data["angle"] = conn.get(pname + ":ANGLE").data()
    lp_data["area"] = conn.get(pname + ":AREA").data()
    lp_data["delrsepout"] = conn.get(pname + ":DELRSEPOUT").data()
    lp_data["delrsepin"] = conn.get(pname + ":DELRSEPIN").data()
    lp_data["delzsepout"] = conn.get(pname + ":DELZSEPOUT").data()
    lp_data["delzsepin"] = conn.get(pname + ":DELZSEPIN").data()
    lp_data["csq"] = conn.get(pname + ":CSQ").data()
    lp_data["res_err"] = conn.get(pname + ":RES_ERR").data()
    lp_data["heatflux"] = conn.get(pname + ":HEATFLUX").data()
    lp_data["pnum"] = conn.get(pname + ":PNUM").data()

    #print "Data stored for probe " + str(lp_data["pnum"]) + " (MDS index " + str(mds_index) + ")."

    return lp_data
Ejemplo n.º 31
0
 def update(node, new):
     if isinstance(new, (float, )): new = MDSplus.Float32(new)
     elif isinstance(new, (int, )): new = MDSplus.Uint16(new)
     else: return
     rec = node.getRecord(None)
     if rec is None: rec = MDSplus.Array([new, new])
     elif len(rec) != 1: return
     else: rec = MDSplus.Array([rec[0], new])
     node.write_once = node.no_write_shot = False
     try:
         node.record = rec
     finally:
         node.write_once = node.no_write_shot = True
Ejemplo n.º 32
0
    def handle(self):
        data = self.request.recv(1024)
        #cur_thread = threading.current_thread()
        com = data[0]
        param = data[1:]

        response = ''
        print(("Request ", data))
        if com == 'c':  # connection request
            tree, shot, node = param.split(',')
            try:
                self.t = MDSplus.Tree(tree, int(shot))
                tn = self.t.getNode(node)
                self.t.setDefault(tn)
                response = 'ok'
            except Exception:
                response = str(sys.exc_info()[1]) + ',' + str(
                    sys.exc_info()[2])

        if com == 'f':  # connection request
            a = param.split(',')
            tree = a[0]
            shot = a[1]
            node = a[2]
            expr = ','.join(a[3:])
            try:
                self.t = MDSplus.Tree(tree, int(shot))
                if node.strip() != '':
                    tn = self.t.getNode(node)
                    self.t.setDefault(tn)
                r = MDSplus.Data.compile(expr).evaluate().data()
                sr = pickle.dumps(r)
                response = binascii.b2a_hex(sr)
                print(("sending data (length)", len(response), 'original :',
                       type(sr)))
                print(type(binascii.a2b_hex(response)))

            except Exception:
                response = str(sys.exc_info()[1]) + ',' + str(
                    sys.exc_info()[2])

        if com == 'v':  # mdsvalue
            r = MDSplus.Data.compile(param).evaluate().data()
            sr = pickle.dumps(r)
            response = binascii.b2a_hex(sr)
            print(("sending data (length)", len(response), 'original :',
                   type(sr)))
            print(type(binascii.a2b_hex(response)))
        #response = "{}: {}".format(cur_thread.name, data)

        self.request.sendall(response + '\n')
Ejemplo n.º 33
0
 def tdiPythonInterface(self):
     self._doTdiTest("Py('a=None')",1)
     self._doTdiTest("Py('a=None','a')",None)
     self._doTdiTest("Py('a=123','a')",123)
     self._doTdiTest("Py('import MDSplus;a=MDSplus.Uint8(-1)','a')",m.Uint8(255))
     self._doTdiTest("pyfun('Uint8','MDSplus',-1)",m.Uint8(255))
     self._doTdiTest("pyfun('Uint8',*,-1)",m.Uint8(255))
     self._doTdiTest("pyfun('str',*,123)",m.String("123"))
     self._doTdiTest('_l=list(*,1,2,3)', m.List([1,2,3]))
     self._doTdiTest('_l=list(_l,4,5)', m.List([1,2,3,4,5]))
     self._doTdiTest('apdrm(_l,1,3)',  m.List([1,3,5]))
     self._doTdiTest('_d=dict(*,1,"1",2,"2")', m.Dictionary([1,'1',2,'2']))
     self._doTdiTest('_d=dict(_d,3,"3")',     m.Dictionary([1,'1',2,'2',3,"3"]))
     self._doTdiTest('apdrm(_d,2)',          m.Dictionary([1,'1',3,"3"]))
Ejemplo n.º 34
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')
Ejemplo n.º 35
0
    def __init__(self, shot, gas='D2', Lp='Div'):
        """

        Parameters
        ----------
        shot :
            Shot number
        gas :
            String indicating the gas. 'D2','H','He'
        Lp :
            String indicating if the parallel connection
            length should be considered from target to
            midplane 'Mid' or from target to X-point
            'Div'

        """
        self.shot = shot
        self.Lp = Lp
        # globally define the gas
        self.gas = gas
        if gas == 'D2':
            self.Z = 1
            self.mu = 2
        elif gas == 'H':
            self.Z = 1
            self.mu = 1
        elif gas == 'He':
            self.Z = 4
            self.mu = 4
        else:
            print('Gas not found, assuming Deuterium')
            self.gas = 'D2'
            self.Z = 1
            self.mu = 2
        # equilibrium quantities
        self._eq = eqtools.TCVLIUQETree(self.shot)
        # this is the iP in the time bases of LIUQE
        self._tLiuqe = self._eq.getTimeBase()
        self.BtSign = np.sign(self._eq.getBtVac().mean())
        # now define the tree where the probe data are saved
        self._filament = mds.Tree('tcv_topic21', shot)
        # this is for different quantities
        self._tree = mds.Tree('tcv_shot', shot)
        # this can be done one single time and then accordingly
        # to analysis region we choose the appropriate timing
        try:
            self.Target = langmuir.LP(self.shot)
        except:
            print('Langmuir probe data not found')
            self.Target = None
Ejemplo n.º 36
0
    def createSignal(dat, dim, t0, unit=None, addim=[], units=[], help=None, value=None, scaling=None,**kwargs):
        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()

        def _addim(dim, units='unknown'):
            if len(dim):
                dim  = _mds.Dimension(None, tonumpy(dim))
                dim.setUnits(Units(units))#
                return dim
            else:
                return None

        if isinstance(dat, (list,)):
            dat = tonumpy(dat)
        dat = _mds.makeArray(dat)
        dim = _dim(dim,t0)
        for i in _ver.xrange(len(addim)):
            addim[i] = _addim(addim[i], units[i])
        if unit is not None:
            dat.setUnits(unit)
        if scaling is None and value is None:
            value = dat
            dat = None
        else:
            if value is None: value='$VALUE'
            if scaling is None:
                if isinstance(value, _ver.basestring):
                    value = _mds.Data.compile(value)
            else:
                if not isinstance(value, _ver.basestring):
                    value = value.decompile()
                value = _mds.Data.compile(value.replace('$VALUE',' polyval($VALUE,'+_mds.makeArray(scaling).decompile()+') '))
        sig = _mds.Signal(value, dat, dim, *addim)
        if help:
            sig.setHelp(help)
        return sig
Ejemplo n.º 37
0
def writedata(data, dims, nodepath, expt, shot):
    """ data: list of images """
    """ dims: array of double seconds based on T1 """
    tree   = _mds.Tree(expt, shot)
    node = tree.getNode(nodepath)
    node.deleteData()
    for i in range(len(data)):
        dim = _mds.Float64Array(dims[i])
        dim.setUnits('s')
        node.makeSegment(dims[i], dims[i], dim, _mds.makeArray(data[i]), -1)
Ejemplo n.º 38
0
def writedata(nodename, data, dims, shot=0):
    """ data: list of images """
    """ dims: array of double seconds based on T1 """
    w7x   = _mds.Tree('W7X', shot)
    triax  = w7x.getNode('.QSQ.HARDWARE.TRIAX')
    node = triax.getNode(nodename)
    node.deleteData()
    for i in range(len(data)):
        dim = _mds.Float64Array(dims[i])
        dim.setUnits('s')
        node.makeSegment(dims[i], dims[i], dim, _mds.makeArray(data[i]), -1)
Ejemplo n.º 39
0
def write_MDSplus(put_data, t):
    node = t.getNode('.log.machine:timing')
    data = MDSplus.makeData(put_data)
    node.putData(data)
Ejemplo n.º 40
0
        #create pulse and perform init phase
        print '='*5,'Current_shot: %d, executing shot: %d'%(cur_shot, executing_shot),'='*5
        dispatch_cmd('set tree %s' % tree, destination)
        dispatch_cmd('create pulse %d' % executing_shot, destination)

        time.sleep(3)
        #print 'press enter.......'
        #raw_input()

        #maybe remove this???!
        if tree=='h1data':
            tmp_tree = MDSplus.Tree('h1data', executing_shot)
            #print 'opened tree'
            pulse_created_node = tmp_tree.getNode('.log.statistics:init_done')
            #print 'told tree it has been created'
            pulse_created_node.putData(MDSplus.makeData('1'))
            #print 'told tree it has been created'


        dispatch_cmd('dispatch /build', destination)
        tmp_time = time.time()
        print "sending event"
	# only send EXECUTING_SHOT as CURRENT_SHOT is EXECUTING_SHOT -1
        MDSplus.Event.setevent("EXECUTING_SHOT",executing_shot)
        dispatch_cmd('dispatch /phase INIT', destination)
        print '--> time to perform INIT %.2fs'%(time.time() - tmp_time)

        #SH 20May2013 - testing abort phase
        # print 'Init command has finished for some reason....'
        # print 'press any key to redo the INIT phase'
        # raw_input()
Ejemplo n.º 41
0
    def storeftp(self, arg):

 	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=self.clock_src.record.getOriginalPartName().getString()[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