Beispiel #1
0
def getpaths(tree):
    """Server side support of getpaths(host,tree) to fetch tree path definitions from data
       server."""
    from MDSplus import Tree, Data, StringArray
    import os
    import socket

    def fixpath(path):
        plist = path.split(';')
        if len(plist) > 1:
            for i in range(len(plist)):
                plist[i] = fixpath(plist[i])
            path = ';'.join(plist)
        else:
            parts = path.split(':')
            if len(parts) == 1:
                path = "%s::%s" % (socket.gethostname(), path)
            else:
                parts[0] = socket.gethostbyaddr(parts[0])[0]
                path = ':'.join(parts)
        return path

    trees = []
    paths = []
    try:
        t = Tree(tree, -1)
        treenames = t.findTags('top')
        for treename in treenames:
            try:
                path = os.environ[treename[1:-5].lower() + '_path']
                trees.append(treename[1:-5])
                paths.append(fixpath(path))
            except:
                pass
    except:
        pass
    ans = {'tree': StringArray(trees), 'path': StringArray(paths)}
    return Data.makeData(ans).serialize()
Beispiel #2
0
def ECEcalib(node, _unit=None, _freq=None, _calib=None):
    from archive import calibrations
    from MDSplus import Ident, String, Float32, StringArray
    sig = node.evaluate()
    ecechannel = int(node.getNode('$IDX').data()) + 1
    offset, factor, unit, info = calibrations.ECEcalib(sig, ecechannel)
    if offset is None: return
    # construct output
    if isinstance(_unit, Ident):
        String(unit).setTdiVar(_unit.name)
    if isinstance(_freq, Ident):
        Float32(info['freq']).setUnits('GHz').setTdiVar(_freq.name)
    if isinstance(_calib, Ident):
        StringArray([info['cfg'], info['cal'],
                     info['par']]).setTdiVar(_calib.name)
    return [offset, factor]
Beispiel #3
0
    def load_config(self):

        #print sys.version_info
        
        from openpyxl import load_workbook

        try:
            configurationFile = self.config_file.data()
        except Exception as e :
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Cannot read configuration file' + str(e) )
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            print ('Loading data from excel configuration file [%s] ...'%(configurationFile),  )          

            param='configurationFile'
            wb = load_workbook(configurationFile, data_only=True)

            sheet=wb['INFO']
            config_date = str(sheet['C1'].value)
            config_comment = str(sheet['C2'].value)
          
            sheet=wb['CONFIG']

            param = 'label_arr'
            #Set column range for all read column. Diect access, with value fild, on the first col value dosen't work
            col=sheet['B2:B%d'%(self.PROBES_NUM+1)]
            col=sheet['B']
            label_arr = [str( c.value if c != None else "") for c in col[1:len(col):1]]

            param = 'front_end_arr'
            col=sheet['C']
            front_end_arr = [str(  c.value if c.value != None else "" ) for c in col[1:len(col):1]]

            param = 'front_end_ch_arr'
            col=sheet['D']
            front_end_ch_arr = [str( c.value if  c.value != None else "") for c in col[1:len(col):1]]

            param = 'adc_slow_arr'
            col=sheet['E']
            adc_slow_arr = [str( c.value if c.value != None else "") for c in col[1:len(col):1]]

            param = 'adc_slow_con_arr'
            col=sheet['F']
            adc_slow_con_arr = [str( c.value if c.value != None else "") for c in col[1:len(col):1]]

            param = 'adc_fast_arr'
            col=sheet['G']
            adc_fast_arr = [str( c.value if  c.value != None else "") for c in col[1:len(col):1]]

            param = 'calib_RV_arr'
            col=sheet['H']
            calib_RV_arr = [float(c.value if c.value != None and (type(c.value) == long or type(c.value) == float) else -1) for c in col[1:len(col):1]]
            calib_RV_str_arr = [str( c.value if c.value != None and (type(c.value) == long or type(c.value) == float)  else "") for c in col[1:len(col):1]]

            param = 'calib_RI_high_arr'
            col=sheet['I']
            calib_RI_high_arr = [float(c.value if c.value != None and (type(c.value) == long or type(c.value) == float)  else -1) for c in col[1:len(col):1]]
            calib_RI_high_str_arr = [str( c.value if c.value != None and (type(c.value) == long or type(c.value) == float)  else "") for c in col[1:len(col):1]]

            param = 'calib_RI_low_arr'
            col=sheet['J']
            calib_RI_low_arr = [float(c.value if c.value != None and (type(c.value) == long or type(c.value) == float)  else -1) for c in col[1:len(col):1]]
            calib_RI_low_str_arr = [str( c.value if c.value != None and (type(c.value) == long or type(c.value) == float)  else "") for c in col[1:len(col):1]]

            param = 'note_arr'
            col=sheet['K']
            note_arr = [str( c.value if  c.value != None else "") for c in col[1:len(col):1]]

            wb.close()

            print (' data loaded')            


        except Exception as e :
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Cannot read or invalid probes param : [%s] configuration file : %s '%(param,str(e)) )
            raise mdsExceptions.TclFAILED_ESSENTIAL
        
        try:
            self.comment.putData(config_comment)
        except Exception as e :
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing comment field ' + str(e) )
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            self.config_date.putData(config_date)
        except Exception as e :
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing configuration date field ' + str(e) )
            raise mdsExceptions.TclFAILED_ESSENTIAL


        try:
            field = 'label'
            self.cfg_probes_label.putData(StringArray(label_arr))
            field = 'front_end'
            self.cfg_probes_front_end.putData(StringArray(front_end_arr))
            field = 'front_end_ch'
            self.cfg_probes_front_end_ch.putData(StringArray(front_end_ch_arr))
            field = 'adc_slow'
            self.cfg_probes_adc_slow.putData(StringArray(adc_slow_arr))
            field = 'adc_slow_con'
            self.cfg_probes_adc_slow_con.putData(StringArray(adc_slow_con_arr))
            field = 'adc_fast'
            self.cfg_probes_adc_fast.putData(StringArray(adc_fast_arr))
            field = 'calib_RV'
            self.cfg_probes_calib_rv.putData(StringArray(calib_RV_str_arr))
            field = 'calib_RI_high'
            self.cfg_probes_calib_ri_h.putData(StringArray(calib_RI_high_str_arr))
            field = 'calib_RI_low'
            self.cfg_probes_calib_ri_l.putData(StringArray(calib_RI_low_str_arr))
            field = 'note'
            self.cfg_probes_note.putData(StringArray(note_arr))
        except Exception as e :
            Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing param %s probes : %s '%(field, str(e)) )
            raise mdsExceptions.TclFAILED_ESSENTIAL


        # Set off oll channel of the ADC module fast and slow defined in the configuration. 
        # ADC Channel is set ON if it is used. Thi is done to not acquire not usefull signals  

        adcSet = []
        for adc in adc_slow_arr :
            adc = adc.strip()
            if len(adc) == 0 :
                continue
            if not (adc in adcSet) :
                adcSet.append(adc)
                for i in range(1,33):
                    self.__setNodeState('\\%s.CHANNEL_%d'%(adc, i), False)
        del adcSet

        adcSet = []
        for adc in adc_fast_arr :
            adc = adc.strip()
            if len(adc) == 0 :
                continue
            if not (adc in adcSet) :
                adcSet.append(adc)
                for i in range(1,17):
                    self.__setNodeState('\\%s.CHANNEL_%d'%(adc, i), False)


        for i in range(0, self.PROBES_NUM):


            if  len( label_arr[i].strip() ) == 0 or label_arr[i].strip() == 'None' :
                continue

            print ('[%0.2d] Configuration for probe %s : '%(i+1, label_arr[i]),) 

            #print "Save probes %d %s"%(i+1, label_arr[i])

            try:
                getattr(self, 'probe_%02d_label'%(i+1)).putData(label_arr[i])
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing label field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL


            try:
                getattr(self, 'probe_%02d_note'%(i+1)).putData(note_arr[i])
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing note field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL


            if  len( front_end_arr[i].strip() ) == 0 or  front_end_arr[i].strip() == 'None':
                #print label_arr[i] + " probe reset data and set off"
                getattr(self, 'probe_%02d'%(i+1)).setOn(False)
                getattr(self, 'probe_%02d_front_end'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_front_end_ch'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_adc_slow'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_adc_slow_con'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_adc_fast'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_calib_rv'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_calib_ri_h'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_calib_ri_l'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_bias_source'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_bias'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_irange'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_data_sv'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_help_sv'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_data_si'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_help_si'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_data_fv'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_help_fv'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_data_fi'%(i+1)).deleteData()
                getattr(self, 'probe_%02d_help_fi'%(i+1)).deleteData()

                try :
                   self.__getattr__('\\%sSV'%(label_arr[i]) ).setOn(False)
                   self.__getattr__('\\%sSI'%(label_arr[i]) ).setOn(False)
                   self.__getattr__('\\%sFV'%(label_arr[i]) ).setOn(False)
                   self.__getattr__('\\%sFI'%(label_arr[i]) ).setOn(False)
                except Exception :
                   print ('WARNING : The configuration excel file added the probe %s.\nThe updateSignalsProbes command MUST be execute'%(label_arr[i]) )  

                print ('[set OFF]')

                continue 
            else :
                print ('[set ON]')
                getattr(self, 'probe_%02d'%(i+1)).setOn(True)

            try:
                getattr(self, 'probe_%02d_front_end'%(i+1)).putData(front_end_arr[i])
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing front end field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'probe_%02d_front_end_ch'%(i+1)).putData(Int32(int(front_end_ch_arr[i])))
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), '---Error writing front end channel field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:                
                getattr(self, 'probe_%02d_adc_slow'%(i+1)).putData(adc_slow_arr[i])
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing adc slow field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                if adc_slow_con_arr[i] == "CON_0" or adc_slow_con_arr[i] == "CON_1" : 
                    getattr(self, 'probe_%02d_adc_slow_con'%(i+1)).putData(adc_slow_con_arr[i])
                else:
                    Data.execute('DevLogErr($1,$2)', self.getNid(), 'Invalid value on adc slow connection field on probe %d, valid values CON_0, CON 1 '%(i+1) )
                    raise mdsExceptions.TclFAILED_ESSENTIAL
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing adc slow connection field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'probe_%02d_adc_fast'%(i+1)).putData(adc_fast_arr[i])
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing adc fast field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'probe_%02d_calib_rv'%(i+1)).putData(Float32(calib_RV_arr[i]))
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing resistence voltage calibration field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'probe_%02d_calib_ri_h'%(i+1)).putData(Float32(calib_RI_high_arr[i]))
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing high current resistence calibration field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'probe_%02d_calib_ri_l'%(i+1)).putData(Float32(calib_RI_low_arr[i]))
            except Exception as e :
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error writing low current resistence calibration field on probe %d : %s '%(i+1 , str(e)) )
                raise mdsExceptions.TclFAILED_ESSENTIAL


            try:
               #Reset current link

               node = self.__getattr__('\\%s.CH_%02d:SOURCE'%(front_end_arr[i], int( front_end_ch_arr[i])));
               expr_val = Data.compile('build_path($)', node.getFullPath())	
               getattr(self, 'probe_%02d_bias_source'%(i+1)).putData( expr_val )
          
               """
               node = self.__getattr__('\\%s.CH_%02d:BIAS'%(front_end_arr[i], int( front_end_ch_arr[i])));
	       expr_val = Data.compile('build_path($)', node.getFullPath())	
               getattr(self, 'probe_%02d_bias'%(i+1)).putData( expr_val ) 
               """

               node = self.__getattr__('\\%s.CH_%02d:IRANGE'%(front_end_arr[i], int( front_end_ch_arr[i])));
               expr_val = Data.compile('build_path($)', node.getFullPath())
               irange_node = getattr(self, 'probe_%02d_irange'%(i+1)) 	
               irange_node.putData( expr_val )

               calib_rv_node = getattr(self, 'probe_%02d_calib_rv'%(i+1))
               calib_ri_high_node = getattr(self, 'probe_%02d_calib_ri_h'%(i+1))
               calib_ri_low_node = getattr(self, 'probe_%02d_calib_ri_l'%(i+1))
	
        
               if len( adc_slow_arr[i].strip() ) != 0 and adc_slow_arr[i].strip() != 'None' :

                   if adc_slow_con_arr[i] == "CON_0" :
                       adc_slow_i_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_slow_arr[i], int( front_end_ch_arr[i])) )
                       self.__setNodeState('\\%s.CHANNEL_%d'%(adc_slow_arr[i], int( front_end_ch_arr[i])), True)
                       adc_slow_v_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_slow_arr[i], int( front_end_ch_arr[i])+8 ))
                       self.__setNodeState('\\%s.CHANNEL_%d'%(adc_slow_arr[i], int( front_end_ch_arr[i])+8), True)
                   elif adc_slow_con_arr[i] == "CON_1" :
                       adc_slow_i_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_slow_arr[i], int( front_end_ch_arr[i])+16 ))
                       self.__setNodeState('\\%s.CHANNEL_%d'%(adc_slow_arr[i], int( front_end_ch_arr[i])+16), True)
                       adc_slow_v_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_slow_arr[i], int( front_end_ch_arr[i])+24 ))
                       self.__setNodeState('\\%s.CHANNEL_%d'%(adc_slow_arr[i], int( front_end_ch_arr[i])+24), True)
                   else:
                       Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error invalid slow adc commector for probe %d (%s)'%(i+1, label_arr[i]) )
                       raise mdsExceptions.TclFAILED_ESSENTIAL



                   expr_slow_v = Data.compile('build_path($) *  build_path($)', calib_rv_node.getFullPath()  , adc_slow_v_node.getFullPath()) 
                   expr_slow_i = Data.compile("(build_path($) == 'LOW'  ?  build_path($) : build_path($) ) *  Build_path($)", irange_node.getFullPath() , calib_ri_low_node.getFullPath(), calib_ri_high_node.getFullPath()  , adc_slow_i_node.getFullPath()) 

                   getattr(self, 'probe_%02d_data_sv'%(i+1)).putData(expr_slow_v);
                   getattr(self, 'probe_%02d_help_sv'%(i+1)).putData('%s slow acquisition voltage'%(label_arr[i]));

                   getattr(self, 'probe_%02d_data_si'%(i+1)).putData(expr_slow_i);
                   getattr(self, 'probe_%02d_help_si'%(i+1)).putData('%s slow acquisition current'%(label_arr[i]));

                   getattr(self, 'probe_%02d_data_sv'%(i+1)).setOn(True)
                   getattr(self, 'probe_%02d_data_si'%(i+1)).setOn(True)

                   print ('[slow adc %s %s]'%(adc_slow_arr[i], adc_slow_con_arr[i]),)

                   try :
                      self.__getattr__('\\%sSV'%(label_arr[i]) ).setOn(True)
                      self.__getattr__('\\%sSI'%(label_arr[i]) ).setOn(True)
                   except Exception :
                      print ('\nWARNING : The configuration excel file added the probe %s.\nThe updateSignalsProbes command MUST be execute'%(label_arr[i]) )  

               else :
                   print (' ')
                   getattr(self, 'probe_%02d_data_sv'%(i+1)).deleteData()
                   getattr(self, 'probe_%02d_data_sv'%(i+1)).setOn(False)
                   getattr(self, 'probe_%02d_data_si'%(i+1)).deleteData()
                   getattr(self, 'probe_%02d_data_si'%(i+1)).setOn(False)
                   try :
                      self.__getattr__('\\%sSV'%(label_arr[i]) ).setOn(False)
                      self.__getattr__('\\%sSI'%(label_arr[i]) ).setOn(False)
                   except Exception :
                      print ('\nWARNING : The configuration excel file added the probe %s.\nThe updateSignalsProbes command MUST be execute'%(label_arr[i]))   


               if len( adc_fast_arr[i].strip() ) != 0 and adc_fast_arr[i].strip() != 'None' :


                   getattr(self, 'probe_%02d_data_fv'%(i+1)).setOn(True);
                   getattr(self, 'probe_%02d_data_fi'%(i+1)).setOn(True);

                   adc_fast_i_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_fast_arr[i], int( front_end_ch_arr[i]) ))
                   self.__setNodeState('\\%s.CHANNEL_%d'%(adc_fast_arr[i], int( front_end_ch_arr[i])), True)
                   adc_fast_v_node = self.__getattr__('\\%s.CHANNEL_%d:DATA'%(adc_fast_arr[i], int( front_end_ch_arr[i])+8 ))
                   self.__setNodeState('\\%s.CHANNEL_%d'%(adc_fast_arr[i], int( front_end_ch_arr[i])+8), True)

                   expr_fast_v = Data.compile('build_path($) *  build_path($)', calib_rv_node.getFullPath()  , adc_fast_v_node.getFullPath()) 
                   expr_fast_i = Data.compile("(build_path($) == 'LOW'  ?  build_path($) : build_path($) ) *  Build_path($)", irange_node.getFullPath() , calib_ri_low_node.getFullPath(), calib_ri_high_node.getFullPath()  , adc_fast_i_node.getFullPath()) 

                   getattr(self, 'probe_%02d_data_fv'%(i+1)).putData(expr_fast_v);
                   getattr(self, 'probe_%02d_help_fv'%(i+1)).putData('%s fast acquisition voltage'%(label_arr[i]));

                   getattr(self, 'probe_%02d_data_fi'%(i+1)).putData(expr_fast_i);
                   getattr(self, 'probe_%02d_help_fi'%(i+1)).putData('%s fast acquisition current'%(label_arr[i]));

                   print ('[fast adc %s]'%(adc_fast_arr[i]))

                   try :
                      self.__getattr__('\\%sFV'%(label_arr[i]) ).setOn(True)
                      self.__getattr__('\\%sFI'%(label_arr[i]) ).setOn(True)
                   except Exception :
                      print ('\nWARNING : The configuration excel file added the probe %s.\nThe updateSignalsProbes command MUST be execute'%(label_arr[i]))   

               else :
                   print (' ')
                   getattr(self, 'probe_%02d_data_fv'%(i+1)).deleteData();
                   getattr(self, 'probe_%02d_data_fv'%(i+1)).setOn(False);
                   getattr(self, 'probe_%02d_data_fi'%(i+1)).deleteData();
                   getattr(self, 'probe_%02d_data_fi'%(i+1)).setOn(False);
                   try :
                      self.__getattr__('\\%sFV'%(label_arr[i]) ).setOn(False)
                      self.__getattr__('\\%sFI'%(label_arr[i]) ).setOn(False)
                   except Exception :
                      print ('WARNING : The configuration excel file added the probe %s.\nThe updateSignalsProbes command MUST be execute'%(label_arr[i]) ) 

            except Exception as e:
                traceback.print_exc()
                Data.execute('DevLogErr($1,$2)', self.getNid(), 'Error setting link for probe %d (%s) to Front End %s ch %s : %s'%(i+1, label_arr[i], front_end_arr[i], front_end_ch_arr[i] ,str(e)))
                raise mdsExceptions.TclFAILED_ESSENTIAL

        return 1
Beispiel #4
0
    def load_config(self):

        print(sys.version_info)

        from openpyxl import load_workbook

        try:
            configurationFile = self.config_file.data()
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Cannot read configuration file' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            param = 'configurationFile'
            wb = load_workbook(configurationFile, data_only=True)

            sheet = wb['INFO']
            config_date = str(sheet['C1'].value)
            config_comment = str(sheet['C2'].value)

            sheet = wb['CONFIG']

            param = 'label_arr'
            # Set column range for all read column. Diect access, with value fild, on the first col value dosen't work
            col = sheet['B2:B%d' % (self.LOS_NUM + 1)]
            col = sheet['B']
            label_arr = [
                str(c.value if c != None else "") for c in col[1:len(col):1]
            ]

            param = 'telescope_arr'
            col = sheet['C']
            telescope_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'c_patch_arr'
            col = sheet['D']
            c_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'b_patch_arr'
            col = sheet['E']
            b_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'or_pannel_arr'
            col = sheet['F']
            or_pannel_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'a_patch_arr'
            col = sheet['G']
            a_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'diameter_str_arr'
            col = sheet['H']
            diameter_arr = [
                float(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else -1)
                for c in col[1:len(col):1]
            ]
            diameter_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'diaphragm_str_arr'
            col = sheet['I']
            diaphragm_arr = [
                float(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else -1)
                for c in col[1:len(col):1]
            ]
            diaphragm_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'P0_str_arr'
            matrix = sheet['J2':'L%d' % (self.LOS_NUM + 1)]
            data_arr = [
                c.value for c in np.asarray(matrix).reshape(3 * self.LOS_NUM)
            ]
            P0_arr = np.array(data_arr, 'float32').reshape([self.LOS_NUM, 3])
            P0_str_arr = [str(c) for c in P0_arr]

            param = 'P1_str_arr'
            matrix = sheet['M2':'O%d' % (self.LOS_NUM + 1)]
            data_arr = [
                c.value for c in np.asarray(matrix).reshape(3 * self.LOS_NUM)
            ]
            P1_arr = np.array(data_arr, 'float32').reshape([self.LOS_NUM, 3])
            P1_str_arr = [str(c) for c in P1_arr]

            param = 'roi_str_arr'
            col = sheet['P']
            roi_arr = [
                int(
                    str(c.value if c.value != None and (
                        type(c.value) == long or type(c.value) == float
                    ) else -1)) for c in col[1:len(col):1]
            ]
            roi_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'spec_arr'
            col = sheet['Q']
            spec_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'note_arr'
            col = sheet['R']
            note_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'calib_flag_arr'
            col = sheet['S']
            calib_flag_arr = [
                str(c.value if c.value != None else "false").lower()
                for c in col[1:len(col):1]
            ]

            wb.close()

        except Exception as e:
            Data.execute(
                'DevLogErr($1,$2)', self.getNid(),
                'Cannot read or invalid spectro param %s configuration file : %s '
                % (param, str(e)))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            self.comment.putData(config_comment)
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing comment field ' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            self.config_date.putData(config_date)
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing configuration date field ' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            field = 'label'
            self.config_los_label.putData(StringArray(label_arr))
            field = 'telescope'
            self.config_los_telescope.putData(StringArray(telescope_arr))
            field = 'a_patch'
            self.config_los_a_patch.putData(StringArray(a_patch_arr))
            field = 'b_patch'
            self.config_los_b_patch.putData(StringArray(b_patch_arr))
            field = 'c_patch'
            self.config_los_c_patch.putData(StringArray(c_patch_arr))
            field = 'or_pannel'
            self.config_los_or_pannel.putData(StringArray(or_pannel_arr))
            field = 'diameter'
            self.config_los_diameter.putData(StringArray(diameter_str_arr))
            field = 'diaphragm'
            self.config_los_diaphragm.putData(StringArray(diaphragm_str_arr))
            field = 'P0'
            self.config_los_p0.putData(StringArray(P0_str_arr))
            field = 'P1'
            self.config_los_p1.putData(StringArray(P1_str_arr))
            field = 'roi'
            self.config_los_roi.putData(StringArray(roi_str_arr))
            field = 'spectrometer'
            self.config_los_spectrometer.putData(StringArray(spec_arr))
            field = 'note'
            self.config_los_note.putData(StringArray(note_arr))
            field = 'calib_flag'
            self.config_los_calib_flag.putData(StringArray(calib_flag_arr))
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing %s on LoS  : %s ' % (field, str(e)))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        spectrometer_list = []
        for i in range(0, self.LOS_NUM):

            try:
                getattr(self, 'los_%03d_label' % (i + 1)).putData(label_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing label field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_telescope' % (i + 1)).putData(
                    telescope_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing telescope field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_c_patch' % (i + 1)).putData(c_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing C patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_b_patch' % (i + 1)).putData(b_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing B patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_or_pannel' % (i + 1)).putData(
                    or_pannel_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing OR pannel field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_a_patch' % (i + 1)).putData(a_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing A patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_diameter' % (i + 1)).putData(diameter_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing diameter field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_diaphragm' % (i + 1)).putData(
                    diaphragm_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing diaphragm field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_p0' % (i + 1)).putData(
                    Float32Array(P0_arr[i]))
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing start point P0 field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_p1' % (i + 1)).putData(
                    Float32Array(P1_arr[i]))
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing end point P1 field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_roi' % (i + 1)).putData(roi_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing roi field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_spectrometer' % (i + 1)).putData(spec_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing spectrometer field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_note' % (i + 1)).putData(note_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing note field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_calib_flag' % (i + 1)).putData(
                    calib_flag_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing calib flag field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                if label_arr[i] == 'None':
                    continue

                if len(spec_arr[i].strip()) == 0:
                    print(self.bcolors.OKBLUE +
                          'Info LoS %d (%s) acquisition not configured ' %
                          (i + 1, label_arr[i]) + self.bcolors.ENDC)
                    continue

                if self.getDeviceName(self.__getattr__(
                        '\\%s' % (spec_arr[i]))) == 'PI_SCT320':
                    # Set link LOS_xxx spectra to ROI_xx spectrometer
                    try:
                        # Reset current link
                        getattr(self,
                                'los_%03d_spectra_ref' % (i + 1)).deleteData()
                        if len(spec_arr[i]) > 0 and not (spec_arr[i]
                                                         in spectrometer_list):
                            for r in range(1, 25):
                                self.__getattr__(
                                    '\\%s.ROIS.ROI_%02d:LOS_PATH' %
                                    (spec_arr[i], r)).deleteData()
                            # Register spectrometer already reset
                            spectrometer_list.append(spec_arr[i])

                        if roi_arr[i] == -1:
                            continue

                        spectraRoiNode = self.__getattr__(
                            '\\%s.ROIS.ROI_%02d:SPECTRA' %
                            (spec_arr[i], roi_arr[i]))
                        getattr(self, 'los_%03d_spectra_ref' %
                                (i + 1)).putData(spectraRoiNode)
                        self.__getattr__('\\%s.ROIS.ROI_%02d:LOS_PATH' %
                                         (spec_arr[i], roi_arr[i])).putData(
                                             label_arr[i])

                        print(
                            self.bcolors.OKGREEN +
                            'Info LoS %d (%s) SPECTRO acquisition configured on Spectrometer %s Roi %d'
                            % (i + 1, label_arr[i], spec_arr[i], roi_arr[i]) +
                            self.bcolors.ENDC)

                    except Exception as e:
                        Data.execute(
                            'DevLogErr($1,$2)', self.getNid(),
                            'Error setting link from LoS %d (%s) to ROI %d on spectrometer %s : %s'
                            % (i + 1, label_arr[i], roi_arr[i], spec_arr[i],
                               str(e)))

                # spec_arr for photodiode is the Front End device BOARD
                elif self.getDeviceName(
                        self.__getattr__('\\%s' % (spec_arr[i]))) == 'PLFE':
                    # Set link LOS_xxx photodiode to Front End
                    try:
                        # Reset photodiode acquisitio channel link
                        getattr(self,
                                'los_%03d_photodiode' % (i + 1)).deleteData()

                        # ROI for phothodiode is the Front End Board channel and adc channel coded as NXX
                        # where N is the BOARD channel 1 or 2 and XX is adc channel from 1 to 32
                        if roi_arr[i] == -1:
                            continue

                        # From FE board path retrives FE BOARD index form 1 to 6
                        feBoardIdx = int(spec_arr[i][-1:])
                        if feBoardIdx < 1 or feBoardIdx > 6:
                            raise Exception(
                                'Invalid board index, valid values from 1 to 6'
                            )
                        code = int(roi_arr[i])

                        feBoardCh = code / 100  # ROI for front end identify the FE board channl 1 or 2
                        if feBoardCh != 1 and feBoardCh != 2:
                            raise Exception(
                                'Invalid board channel, valid values 1 or 2')

                        adcChan = code - feBoardCh * 100
                        if adcChan < 1 or adcChan > 32:
                            raise Exception(
                                'Invalid adc channel number %d for adc device define in front end device, valid values are from 1 to 32'
                                % (adcChan))

                        fePath = self.getDevice(
                            self.__getattr__('\\%s' %
                                             (spec_arr[i]))).getMinPath()
                        adcPath = (self.__getattr__(
                            '%s:ADC' % (fePath))).getData().getMinPath()

                        expr = Data.compile(
                            '%s.CHANNEL_%d:DATA / (%s.BOARD_%02d.SETUP.CHANNEL_%02d.WR:GAIN * (%s.BOARD_%02d.SETUP.CHANNEL_%02d.WR:TRANS == 0 ? 1 : 100))'
                            % (adcPath, adcChan, fePath, feBoardIdx, feBoardCh,
                               fePath, feBoardIdx, feBoardCh))

                        getattr(self,
                                'los_%03d_photodiode' % (i + 1)).putData(expr)

                        print(
                            self.bcolors.OKGREEN +
                            'Info LoS %d (%s) PHOTODIODE acquisition configured on Adc %s ch %d Front End %s Board %d Ch %d'
                            % (i + 1, label_arr[i], adcPath, adcChan, fePath,
                               feBoardIdx, feBoardCh) + self.bcolors.ENDC)

                    except Exception as e:
                        Data.execute(
                            'DevLogErr($1,$2)', self.getNid(),
                            'Error setting link from LoS %d (%s) to front end board %s : %s'
                            % (i + 1, label_arr[i], spec_arr[i], str(e)))
                else:
                    Data.execute(
                        'DevLogErr($1,$2)', self.getNid(),
                        'Invalid definition of spectrometer/front-end device (%s) for LoS %d (%s)'
                        % (spec_arr[i], i + 1, label_arr[i]))
            except Exception as e:
                print(str(e))
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error definition of spectrometer/front-end device (%s) for LoS %d (%s) : %s'
                    % (spec_arr[i], i + 1, label_arr[i], str(e)))
        return 1
Beispiel #5
0
    def load_config(self):

        print(sys.version_info)

        from openpyxl import load_workbook

        try:
            configurationFile = self.config_file.data()
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Cannot read configuration file' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            param = 'configurationFile'
            wb = load_workbook(configurationFile, data_only=True)

            sheet = wb['INFO']
            config_date = str(sheet['C1'].value)
            config_comment = str(sheet['C2'].value)

            sheet = wb['CONFIG']

            param = 'label_arr'
            #Set column range for all read column. Diect access, with value fild, on the first col value dosen't work
            col = sheet['B2:B%d' % (self.LOS_NUM + 1)]
            col = sheet['B']
            label_arr = [
                str(c.value if c != None else "") for c in col[1:len(col):1]
            ]

            param = 'telescope_arr'
            col = sheet['C']
            telescope_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'c_patch_arr'
            col = sheet['D']
            c_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'b_patch_arr'
            col = sheet['E']
            b_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'or_pannel_arr'
            col = sheet['F']
            or_pannel_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'a_patch_arr'
            col = sheet['G']
            a_patch_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'diameter_str_arr'
            col = sheet['H']
            diameter_arr = [
                float(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else -1)
                for c in col[1:len(col):1]
            ]
            diameter_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'diaphragm_str_arr'
            col = sheet['I']
            diaphragm_arr = [
                float(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else -1)
                for c in col[1:len(col):1]
            ]
            diaphragm_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'P0_str_arr'
            matrix = sheet['J2':'L%d' % (self.LOS_NUM + 1)]
            data_arr = [
                c.value for c in np.asarray(matrix).reshape(3 * self.LOS_NUM)
            ]
            P0_arr = np.array(data_arr, 'float32').reshape([self.LOS_NUM, 3])
            P0_str_arr = [str(c) for c in P0_arr]

            param = 'P1_str_arr'
            matrix = sheet['M2':'O%d' % (self.LOS_NUM + 1)]
            data_arr = [
                c.value for c in np.asarray(matrix).reshape(3 * self.LOS_NUM)
            ]
            P1_arr = np.array(data_arr, 'float32').reshape([self.LOS_NUM, 3])
            P1_str_arr = [str(c) for c in P1_arr]

            param = 'roi_str_arr'
            col = sheet['P']
            roi_arr = [
                int(
                    str(c.value if c.value != None and (
                        type(c.value) == long or type(c.value) == float
                    ) else -1)) for c in col[1:len(col):1]
            ]
            roi_str_arr = [
                str(c.value if c.value != None and (
                    type(c.value) == long or type(c.value) == float) else "")
                for c in col[1:len(col):1]
            ]

            param = 'spec_arr'
            col = sheet['Q']
            spec_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'note_arr'
            col = sheet['R']
            note_arr = [
                str(c.value if c.value != None else "")
                for c in col[1:len(col):1]
            ]

            param = 'calib_flag_arr'
            col = sheet['S']
            calib_flag_arr = [
                str(c.value if c.value != None else "false").lower()
                for c in col[1:len(col):1]
            ]

            wb.close()

        except Exception as e:
            Data.execute(
                'DevLogErr($1,$2)', self.getNid(),
                'Cannot read or invalid spectro param %s configuration file : %s '
                % (param, str(e)))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            self.comment.putData(config_comment)
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing comment field ' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            self.config_date.putData(config_date)
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing configuration date field ' + str(e))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        try:
            field = 'label'
            self.config_los_label.putData(StringArray(label_arr))
            field = 'telescope'
            self.config_los_telescope.putData(StringArray(telescope_arr))
            field = 'a_patch'
            self.config_los_a_patch.putData(StringArray(a_patch_arr))
            field = 'b_patch'
            self.config_los_b_patch.putData(StringArray(b_patch_arr))
            field = 'c_patch'
            self.config_los_c_patch.putData(StringArray(c_patch_arr))
            field = 'or_pannel'
            self.config_los_or_pannel.putData(StringArray(or_pannel_arr))
            field = 'diameter'
            self.config_los_diameter.putData(StringArray(diameter_str_arr))
            field = 'diaphragm'
            self.config_los_diaphragm.putData(StringArray(diaphragm_str_arr))
            field = 'P0'
            self.config_los_p0.putData(StringArray(P0_str_arr))
            field = 'P1'
            self.config_los_p1.putData(StringArray(P1_str_arr))
            field = 'roi'
            self.config_los_roi.putData(StringArray(roi_str_arr))
            field = 'spectrometer'
            self.config_los_spectrometer.putData(StringArray(spec_arr))
            field = 'note'
            self.config_los_note.putData(StringArray(note_arr))
            field = 'calib_flag'
            self.config_los_calib_flag.putData(StringArray(calib_flag_arr))
        except Exception as e:
            Data.execute('DevLogErr($1,$2)', self.getNid(),
                         'Error writing %s on LoS  : %s ' % (field, str(e)))
            raise mdsExceptions.TclFAILED_ESSENTIAL

        spectrometer_list = []
        for i in range(0, self.LOS_NUM):

            try:
                getattr(self, 'los_%03d_label' % (i + 1)).putData(label_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing label field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_telescope' % (i + 1)).putData(
                    telescope_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing telescope field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_c_patch' % (i + 1)).putData(c_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing C patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_b_patch' % (i + 1)).putData(b_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing B patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_or_pannel' % (i + 1)).putData(
                    or_pannel_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing OR pannel field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_a_patch' % (i + 1)).putData(a_patch_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing A patch field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_diameter' % (i + 1)).putData(diameter_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing diameter field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_diaphragm' % (i + 1)).putData(
                    diaphragm_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing diaphragm field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_p0' % (i + 1)).putData(
                    Float32Array(P0_arr[i]))
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing start point P0 field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_p1' % (i + 1)).putData(
                    Float32Array(P1_arr[i]))
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing end point P1 field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_roi' % (i + 1)).putData(roi_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing roi field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self,
                        'los_%03d_spectrometer' % (i + 1)).putData(spec_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing spectrometer field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_note' % (i + 1)).putData(note_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing note field on LoS %s ' % (i + 1) + str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            try:
                getattr(self, 'los_%03d_calib_flag' % (i + 1)).putData(
                    calib_flag_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error writing calib flag field on LoS %s ' % (i + 1) +
                    str(e))
                raise mdsExceptions.TclFAILED_ESSENTIAL

            #Set link LOS_xxx spectra to ROI_xx spectrometer
            try:
                #Reset current link

                getattr(self, 'los_%03d_spectra_ref' % (i + 1)).deleteData()
                if len(spec_arr[i]) > 0 and not (spec_arr[i]
                                                 in spectrometer_list):
                    for r in range(1, 25):
                        self.__getattr__('\\%s.ROIS.ROI_%02d:LOS_PATH' %
                                         (spec_arr[i], r)).deleteData()
                    spectrometer_list.append(spec_arr[i])

                if roi_arr[i] == -1:
                    continue

                spectraRoiNode = self.__getattr__(
                    '\\%s.ROIS.ROI_%02d:SPECTRA' % (spec_arr[i], roi_arr[i]))
                getattr(self, 'los_%03d_spectra_ref' %
                        (i + 1)).putData(spectraRoiNode)
                self.__getattr__('\\%s.ROIS.ROI_%02d:LOS_PATH' %
                                 (spec_arr[i], roi_arr[i])).putData(
                                     label_arr[i])
            except Exception as e:
                Data.execute(
                    'DevLogErr($1,$2)', self.getNid(),
                    'Error setting link from LoS %d (%s) to ROI %d on spectrometer %s : %s'
                    % (i + 1, label_arr[i], roi_arr[i], spec_arr[i], str(e)))

        return 1