Beispiel #1
0
    def __getArrayInfo(self, array):
        info = {}
        info["SourceType"] = SOURCE_TYPE
        info["SourceName"] = self.name
        info["Key"] = array

        arrayinfo = sps.getarrayinfo(self.name, array)
        info["rows"] = arrayinfo[0]
        info["cols"] = arrayinfo[1]
        info["type"] = arrayinfo[2]
        info["flag"] = arrayinfo[3]
        counter = sps.updatecounter(self.name, array)
        info["updatecounter"] = counter

        envdict = {}
        keylist = sps.getkeylist(self.name, array + "_ENV")
        for i in keylist:
            val = sps.getenv(self.name, array + "_ENV", i)
            envdict[i] = val
        info["envdict"] = envdict
        scantest = (info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN
        if (array in ["SCAN_D"]) or scantest:
            if 'axistitles' in info["envdict"]:
                info["LabelNames"] = self._buildLabelsList(info['envdict']['axistitles'])
            if 'H' in info["envdict"]:
                if 'K' in info["envdict"]:
                    if 'L' in info["envdict"]:
                        info['hkl'] = [envdict['H'],
                                       envdict['K'],
                                       envdict['L']]
        calibarray = array + "_PARAM"
        if calibarray in sps.getarraylist(self.name):
            try:
                data = sps.getdata(self.name, calibarray)
                updc = sps.updatecounter(self.name, calibarray)
                info["EnvKey"] = calibarray
                # data is an array
                info["McaCalib"] = data.tolist()[0]
                info["env_updatecounter"] = updc
            except:
                # Some of our C modules return NULL without setting
                # an exception ...
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray = "XIA_DET"
            if envarray in sps.getarraylist(self.name):
                try:
                    data = sps.getdata(self.name, envarray)
                    updc = sps.updatecounter(self.name, envarray)
                    info["EnvKey"] = envarray
                    info["Detectors"] = data.tolist()[0]
                    info["env_updatecounter"] = updc
                except:
                    pass
        return info
Beispiel #2
0
    def __GetArrayInfo(self,array):
        info={}
        info["SourceType"]=SOURCE_TYPE
        info["SourceName"]=self.SourceName
        info["Key"]=array
        info["Source"]=self.Source
        
        arrayinfo=sps.getarrayinfo (self.SourceName,array)
        info["rows"]=arrayinfo[0]
        info["cols"]=arrayinfo[1]
        info["type"]=arrayinfo[2]
        info["flag"]=arrayinfo[3]
        counter=sps.updatecounter (self.SourceName,array)
        info["updatecounter"]=counter

        envdict={}
        keylist=sps.getkeylist (self.SourceName,array+"_ENV")
        for i in keylist:
            val=sps.getenv(self.SourceName,array+"_ENV",i)
            envdict[i]=val
        info["envdict"]=envdict

        calibarray= array + "_PARAM"
        if calibarray in sps.getarraylist(self.SourceName):
            try:
                data= sps.getdata(self.SourceName, calibarray)
                updc= sps.updatecounter(self.SourceName, calibarray)
                info["EnvKey"]= calibarray
                info["McaCalib"]= data.tolist()[0]
                info["env_updatecounter"]= updc
            except:
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray= "XIA_DET"
            if envarray in sps.getarraylist(self.SourceName):
                try:
                    data= sps.getdata(self.SourceName, envarray)
                    updc= sps.updatecounter(self.SourceName, envarray)
                    info["EnvKey"]= envarray
                    info["Detectors"]= data.tolist()[0]
                    info["env_updatecounter"]= updc
                except:
                    pass
	
        return info
Beispiel #3
0
    def __GetArrayInfo(self,array):
        info={}
        info["SourceType"]=SOURCE_TYPE
        info["SourceName"]=self.SourceName
        info["Key"]=array
        info["Source"]=self.Source

        arrayinfo=sps.getarrayinfo (self.SourceName,array)
        info["rows"]=arrayinfo[0]
        info["cols"]=arrayinfo[1]
        info["type"]=arrayinfo[2]
        info["flag"]=arrayinfo[3]
        counter=sps.updatecounter (self.SourceName,array)
        info["updatecounter"]=counter

        envdict={}
        keylist=sps.getkeylist (self.SourceName,array+"_ENV")
        for i in keylist:
            val=sps.getenv(self.SourceName,array+"_ENV",i)
            envdict[i]=val
        info["envdict"]=envdict

        calibarray= array + "_PARAM"
        if calibarray in sps.getarraylist(self.SourceName):
            try:
                data= sps.getdata(self.SourceName, calibarray)
                updc= sps.updatecounter(self.SourceName, calibarray)
                info["EnvKey"]= calibarray
                info["McaCalib"]= data.tolist()[0]
                info["env_updatecounter"]= updc
            except:
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray= "XIA_DET"
            if envarray in sps.getarraylist(self.SourceName):
                try:
                    data= sps.getdata(self.SourceName, envarray)
                    updc= sps.updatecounter(self.SourceName, envarray)
                    info["EnvKey"]= envarray
                    info["Detectors"]= data.tolist()[0]
                    info["env_updatecounter"]= updc
                except:
                    pass

        return info
Beispiel #4
0
    def __RefreshPageOrig (source_obj,self,page):
        """
        Virtual method, implements seeking for changes in data.
        Returns non-zero if the page was changed.
        If not implemented in the derived class, this class doesn't
        support dinamic changes monitoring.
        As pages can be copied to different Data objects, and can
        store the original RefreshPage method for updating, source_obj
        refers to the object that was origin of the page data, while
        self indicates the object that actually owns the page
        with index page.
        It was done this way because if it is stored the reference to
        the unbound method, python doesn't allow you to call it with
        an object of different data type.

        Important:
        Derived classes shall update the page:   self.Pages[page]
        but not:   source_obj.Pages[page]
        """       
        if (self.GetItemPageInfo("SourceType",page)==SOURCE_TYPE):
            specname=self.GetItemPageInfo("SourceName",page)
            arrayname=self.GetItemPageInfo("Key",page)
            updatecounter=self.GetItemPageInfo("updatecounter",page)
            if (updatecounter!=None) and (arrayname!=None) and (specname!=None):
                if specname in sps.getspeclist():
                    if arrayname in sps.getarraylist(specname):
                        counter=sps.updatecounter (specname,arrayname)
                        if (counter != updatecounter):
                            info=self.GetPageInfo(page)
                            info.update(self.__GetArrayInfo(arrayname))
                            if   info["row"]!="ALL": data= sps.getdatarow(specname,arrayname,info["row"])
                            elif info["col"]!="ALL": data= sps.getdatacol(specname,arrayname,info["col"])
                            else: data=sps.getdata (specname,arrayname)                            
                            self.Pages[page].Array=data
                            return 1
            infoname= self.GetItemPageInfo("EnvKey")
            infoupdc= self.GetItemPageInfo("env_updatecounter")
            if (infoupdc!=None) and (infoname!=None) and (specname!=None):
                if infoname in sps.getarraylist(specname):
                    counter= sps.updatecounter(specname,infoname)
                    if (counter!=infoupdc):
                        info= self.GetPageInfo(page)
                        info.update(self.__GetArrayInfo(arrayname))
                        return 1
        return 0
Beispiel #5
0
    def __RefreshPageOrig (source_obj,self,page):
        """
        Virtual method, implements seeking for changes in data.
        Returns non-zero if the page was changed.
        If not implemented in the derived class, this class doesn't
        support dinamic changes monitoring.
        As pages can be copied to different Data objects, and can
        store the original RefreshPage method for updating, source_obj
        refers to the object that was origin of the page data, while
        self indicates the object that actually owns the page
        with index page.
        It was done this way because if it is stored the reference to
        the unbound method, python doesn't allow you to call it with
        an object of different data type.

        Important:
        Derived classes shall update the page:   self.Pages[page]
        but not:   source_obj.Pages[page]
        """
        if (self.GetItemPageInfo("SourceType",page)==SOURCE_TYPE):
            specname=self.GetItemPageInfo("SourceName",page)
            arrayname=self.GetItemPageInfo("Key",page)
            updatecounter=self.GetItemPageInfo("updatecounter",page)
            if (updatecounter!=None) and (arrayname!=None) and (specname!=None):
                if specname in sps.getspeclist():
                    if arrayname in sps.getarraylist(specname):
                        counter=sps.updatecounter (specname,arrayname)
                        if (counter != updatecounter):
                            info=self.GetPageInfo(page)
                            info.update(self.__GetArrayInfo(arrayname))
                            if   info["row"]!="ALL": data= sps.getdatarow(specname,arrayname,info["row"])
                            elif info["col"]!="ALL": data= sps.getdatacol(specname,arrayname,info["col"])
                            else: data=sps.getdata (specname,arrayname)
                            self.Pages[page].Array=data
                            return 1
            infoname= self.GetItemPageInfo("EnvKey")
            infoupdc= self.GetItemPageInfo("env_updatecounter")
            if (infoupdc!=None) and (infoname!=None) and (specname!=None):
                if infoname in sps.getarraylist(specname):
                    counter= sps.updatecounter(specname,infoname)
                    if (counter!=infoupdc):
                        info= self.GetPageInfo(page)
                        info.update(self.__GetArrayInfo(arrayname))
                        return 1
        return 0
Beispiel #6
0
 def LoadSource(self,key_list="ALL",append=0,invalidate=1,row="ALL",col="ALL"):
     """
     Creates a given number of pages, getting data from the actual
     source (set by SetSource)
     Parameters:
     key_list: list of all keys to be read from source. It is a list of
              string, shared memory array names, to be read from the file.
              It can be also one single string, if only one array is to be read.
     append: If non-zero appends to the end of page list.
             Otherwise, initializes the page list                
     invalidate: if non-zero performas an invalidade call after
                 loading
     row: If set to an integer, loads a single row (0-based indexed)
     col: If set to an integer, loads a single column (0-based indexed)
     """
     #AS if append==0: Data.Delete(self)        
     if type(key_list) == type(" "): key_list=(key_list,)
     output =[]
     if self.SourceName in sps.getspeclist():
         if key_list == "ALL":
             key_list = sps.getarraylist(self.SourceName)
         for array in key_list:
             if array in sps.getarraylist(self.SourceName):
                 info = self.__GetArrayInfo(array)
                 info["row"] = row
                 info["col"] = col
                 if info["row"]!="ALL":
                     data= sps.getdatarow(self.SourceName, array,info["row"])
                     if data is not None:
                         data=numpy.reshape(data,(1, data.shape[0]))
                 elif info["col"]!="ALL":
                     data= sps.getdatacol(self.SourceName, array, info["col"])
                     if data is not None:
                         data=numpy.reshape(data, (data.shape[0], 1))
                 else:
                     data=sps.getdata (self.SourceName, array)
                 #self.AppendPage(info,data)
                 output.append([info,data])
     if len(output) == 1:
         return output[0]
     else:
         return output
Beispiel #7
0
 def LoadSource(self,key_list="ALL",append=0,invalidate=1,row="ALL",col="ALL"):
     """
     Creates a given number of pages, getting data from the actual
     source (set by SetSource)
     Parameters:
     key_list: list of all keys to be read from source. It is a list of
              string, shared memory array names, to be read from the file.
              It can be also one single string, if only one array is to be read.
     append: If non-zero appends to the end of page list.
             Otherwise, initializes the page list
     invalidate: if non-zero performas an invalidade call after
                 loading
     row: If set to an integer, loads a single row (0-based indexed)
     col: If set to an integer, loads a single column (0-based indexed)
     """
     #AS if append==0: Data.Delete(self)
     if type(key_list) == type(" "): key_list=(key_list,)
     output =[]
     if self.SourceName in sps.getspeclist():
         if key_list == "ALL":
             key_list = sps.getarraylist(self.SourceName)
         for array in key_list:
             if array in sps.getarraylist(self.SourceName):
                 info = self.__GetArrayInfo(array)
                 info["row"] = row
                 info["col"] = col
                 if info["row"]!="ALL":
                     data= sps.getdatarow(self.SourceName, array,info["row"])
                     if data is not None:
                         data=numpy.reshape(data,(1, data.shape[0]))
                 elif info["col"]!="ALL":
                     data= sps.getdatacol(self.SourceName, array, info["col"])
                     if data is not None:
                         data=numpy.reshape(data, (data.shape[0], 1))
                 else:
                     data=sps.getdata (self.SourceName, array)
                 #self.AppendPage(info,data)
                 output.append([info,data])
     if len(output) == 1:
         return output[0]
     else:
         return output
Beispiel #8
0
 def getDataObject(self, key_list, selection=None):
     if type(key_list) != types.ListType:
         nolist = True
         key_list = [key_list]
     else:
         output = []
         nolist = False
     if self.name in sps.getspeclist():
         sourcekeys = self.getSourceInfo()['KeyList']
         for key in key_list:
             #a key corresponds to an array name
             if key not in sourcekeys:
                 raise KeyError("Key %s not in source keys" % key)
             #array = key
             #create data object
             data = DataObject.DataObject()
             data.info = self.__getArrayInfo(key)
             data.info['selection'] = selection
             data.data = sps.getdata(self.name, key)
             if nolist:
                 if selection is not None:
                     scantest = (data.info['flag'] &
                                 sps.TAG_SCAN) == sps.TAG_SCAN
                     if ((key in ["SCAN_D"]) or scantest) \
                         and 'cntlist' in selection:
                         data.x = None
                         data.y = None
                         data.m = None
                         if 'nopts' in data.info:
                             nopts = data.info['nopts']
                         elif 'nopts' in data.info['envdict']:
                             nopts = int(data.info['envdict']['nopts']) + 1
                         else:
                             nopts = data.info['rows']
                         if not 'LabelNames' in data.info:
                             data.info['LabelNames'] =\
                                 selection['cntlist'] * 1
                         newMemoryProblem = len(data.info['LabelNames']) != len(selection['cntlist'])
                         # check the current information is up-to-date
                         # (new HKL handling business)
                         actualLabelSelection = {'x':[], 'y':[], 'm':[]}
                         for tmpKey in ['x', 'y', 'm']:
                             if tmpKey in selection:
                                 for labelIndex in selection[tmpKey]:
                                     actualLabelSelection[tmpKey].append( \
                                                 selection['cntlist'][labelIndex])
                         if 'x' in selection:
                             for labelindex in selection['x']:
                                 #label = selection['cntlist'][labelindex]
                                 label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.x is None: data.x = []
                                 data.x.append(data.data[:nopts, index])
                         if 'y' in selection:
                             #for labelindex in selection['y']:
                             for label in actualLabelSelection['y']:                                
                                 #label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.y is None: data.y = []
                                 data.y.append(data.data[:nopts, index])
                         if 'm' in selection:
                             #for labelindex in selection['m']:
                             for label in actualLabelSelection['m']:                                
                                 #label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.m is None: data.m = []
                                 data.m.append(data.data[:nopts, index])
                         data.info['selectiontype'] = "1D"
                         data.info['scanselection'] = True
                         if newMemoryProblem:
                             newSelection = copy.deepcopy(selection)
                             for tmpKey in ['x', 'y', 'm']:
                                 if tmpKey in selection:
                                     for i in range(len(selection[tmpKey])):
                                         if tmpKey == "x":
                                             label = data.info['LabelNames'][selection[tmpKey][i]]
                                         else:
                                             label = selection['cntlist'][selection[tmpKey][i]]
                                         newSelection[tmpKey][i] = data.info['LabelNames'].index(label)
                             data.info['selection'] = newSelection
                             data.info['selection']['cntlist'] = data.info['LabelNames']
                             selection = newSelection
                         data.data = None
                         return data
                     if (key in ["XIA_DATA"]) and 'XIA' in selection:
                         if selection["XIA"]:
                             if 'Detectors' in data.info:
                                 for i in range(len(selection['rows']['y'])):
                                     selection['rows']['y'][i] = \
                                         data.info['Detectors'].index(selection['rows']['y'][i]) + 1
                                 del selection['XIA']
                     return data.select(selection)
                 else:
                     if data.data is not None:
                         data.info['selectiontype'] = "%dD" % len(data.data.shape)
                         if data.info['selectiontype'] == "2D":
                             data.info["imageselection"] = True
                     return data
             else:
                 output.append(data.select(selection))
         return output
     else:
         return None
Beispiel #9
0
    def __getArrayInfo(self, array):
        info = {}
        info["SourceType"] = SOURCE_TYPE
        info["SourceName"] = self.name
        info["Key"] = array

        arrayinfo = sps.getarrayinfo(self.name, array)
        info["rows"] = arrayinfo[0]
        info["cols"] = arrayinfo[1]
        info["type"] = arrayinfo[2]
        info["flag"] = arrayinfo[3]
        counter = sps.updatecounter(self.name, array)
        info["updatecounter"] = counter


        envdict = {}
        keylist = sps.getkeylist(self.name, array + "_ENV")
        for i in keylist:
            val = sps.getenv(self.name, array + "_ENV", i)
            envdict[i] = val
        info["envdict"] = envdict
        scantest = (info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN
        metdata = None
        if array in ["SCAN_D"]:
            # try to get new style SCAN_D metadata
            metadata = sps.getmetadata(self.name, array)
            if metadata is not None:
                motors, metadata = metadata
                #info["LabelNames"] = metadata["allcounters"].split(";")
                labels = list(motors.keys())
                labels.sort()
                if len(labels):
                    info["LabelNames"] = [motors[x] for x in labels]
                if len(metadata["allmotorm"]):
                    info["MotorNames"] = metadata["allmotorm"].split(";")
                    info["MotorValues"] = [float(x) \
                                for x in metadata["allpositions"].split(";")]
                info["nopts"] = int(metadata["npts"])
                supplied_info = sps.getinfo(self.name, array)
                if len(supplied_info):
                    info["nopts"] = int(supplied_info[0]) 
                if 'hkl' in metadata:
                    if len(metadata["hkl"]):
                        info['hkl'] = [float(x) \
                                for x in metadata["hkl"].split(";")]
                # current SCAN
                info["scanno"] = int(metadata["scanno"])
                # current SPEC file
                info["datafile"] = metadata["datafile"]
                # put any missing information
                info["selectedcounters"] = [x \
                                for x in metadata["selectedcounters"].split()]
                # do not confuse with unhandled keys ...
                #for key in metadata:
                #    if key not in info:
                #        info[key] = metadata[key]
        if (metdata is None) and ((array in ["SCAN_D"]) or scantest):
            # old style SCAN_D metadata
            if 'axistitles' in info["envdict"]:
                info["LabelNames"] = self._buildLabelsList(info['envdict']['axistitles'])
            if 'H' in info["envdict"]:
                if 'K' in info["envdict"]:
                    if 'L' in info["envdict"]:
                        info['hkl'] = [envdict['H'],
                                       envdict['K'],
                                       envdict['L']]
        calibarray = array + "_PARAM"
        if calibarray in sps.getarraylist(self.name):
            try:
                data = sps.getdata(self.name, calibarray)
                updc = sps.updatecounter(self.name, calibarray)
                info["EnvKey"] = calibarray
                # data is an array
                info["McaCalib"] = data.tolist()[0]
                info["env_updatecounter"] = updc
            except:
                # Some of our C modules return NULL without setting
                # an exception ...
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray = "XIA_DET"
            if envarray in sps.getarraylist(self.name):
                try:
                    data = sps.getdata(self.name, envarray)
                    updc = sps.updatecounter(self.name, envarray)
                    info["EnvKey"] = envarray
                    info["Detectors"] = data.tolist()[0]
                    info["env_updatecounter"] = updc
                except:
                    pass
        return info
Beispiel #10
0
 def getDataObject(self, key_list, selection=None):
     if type(key_list) not in [type([])]:
         nolist = True
         key_list = [key_list]
     else:
         output = []
         nolist = False
     if self.name in sps.getspeclist():
         sourcekeys = self.getSourceInfo()['KeyList']
         for key in key_list:
             #a key corresponds to an array name
             if key not in sourcekeys:
                 raise KeyError("Key %s not in source keys" % key)
             #array = key
             #create data object
             data = DataObject.DataObject()
             data.info = self.__getArrayInfo(key)
             data.info['selection'] = selection
             data.data = sps.getdata(self.name, key)
             if nolist:
                 if selection is not None:
                     scantest = (data.info['flag']
                                 & sps.TAG_SCAN) == sps.TAG_SCAN
                     if ((key in ["SCAN_D"]) or scantest) \
                         and 'cntlist' in selection:
                         data.x = None
                         data.y = None
                         data.m = None
                         if 'nopts' in data.info:
                             nopts = data.info['nopts']
                         elif 'nopts' in data.info['envdict']:
                             nopts = int(data.info['envdict']['nopts']) + 1
                         else:
                             nopts = data.info['rows']
                         if not 'LabelNames' in data.info:
                             data.info['LabelNames'] =\
                                 selection['cntlist'] * 1
                         newMemoryProblem = len(
                             data.info['LabelNames']) != len(
                                 selection['cntlist'])
                         # check the current information is up-to-date
                         # (new HKL handling business)
                         actualLabelSelection = {'x': [], 'y': [], 'm': []}
                         for tmpKey in ['x', 'y', 'm']:
                             if tmpKey in selection:
                                 for labelIndex in selection[tmpKey]:
                                     actualLabelSelection[tmpKey].append( \
                                                 selection['cntlist'][labelIndex])
                         if 'x' in selection:
                             for labelindex in selection['x']:
                                 #label = selection['cntlist'][labelindex]
                                 label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError(
                                         "Label %s not in scan labels" %
                                         label)
                                 index = data.info['LabelNames'].index(
                                     label)
                                 if data.x is None: data.x = []
                                 data.x.append(data.data[:nopts, index])
                         if 'y' in selection:
                             #for labelindex in selection['y']:
                             for label in actualLabelSelection['y']:
                                 #label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError(
                                         "Label %s not in scan labels" %
                                         label)
                                 index = data.info['LabelNames'].index(
                                     label)
                                 if data.y is None: data.y = []
                                 data.y.append(data.data[:nopts, index])
                         if 'm' in selection:
                             #for labelindex in selection['m']:
                             for label in actualLabelSelection['m']:
                                 #label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError(
                                         "Label %s not in scan labels" %
                                         label)
                                 index = data.info['LabelNames'].index(
                                     label)
                                 if data.m is None: data.m = []
                                 data.m.append(data.data[:nopts, index])
                         data.info['selectiontype'] = "1D"
                         data.info['scanselection'] = True
                         if newMemoryProblem:
                             newSelection = copy.deepcopy(selection)
                             for tmpKey in ['x', 'y', 'm']:
                                 if tmpKey in selection:
                                     for i in range(len(selection[tmpKey])):
                                         if tmpKey == "x":
                                             label = data.info[
                                                 'LabelNames'][
                                                     selection[tmpKey][i]]
                                         else:
                                             label = selection['cntlist'][
                                                 selection[tmpKey][i]]
                                         newSelection[tmpKey][
                                             i] = data.info[
                                                 'LabelNames'].index(label)
                             data.info['selection'] = newSelection
                             data.info['selection']['cntlist'] = data.info[
                                 'LabelNames']
                             selection = newSelection
                         data.data = None
                         return data
                     if (key in ["XIA_DATA"]) and 'XIA' in selection:
                         if selection["XIA"]:
                             if 'Detectors' in data.info:
                                 for i in range(len(
                                         selection['rows']['y'])):
                                     selection['rows']['y'][i] = \
                                         data.info['Detectors'].index(selection['rows']['y'][i]) + 1
                                 del selection['XIA']
                     return data.select(selection)
                 else:
                     if data.data is not None:
                         data.info['selectiontype'] = "%dD" % len(
                             data.data.shape)
                         if data.info['selectiontype'] == "2D":
                             data.info["imageselection"] = True
                     return data
             else:
                 output.append(data.select(selection))
         return output
     else:
         return None
Beispiel #11
0
    def __getArrayInfo(self, array):
        info = {}
        info["SourceType"] = SOURCE_TYPE
        info["SourceName"] = self.name
        info["Key"] = array

        arrayinfo = sps.getarrayinfo(self.name, array)
        info["rows"] = arrayinfo[0]
        info["cols"] = arrayinfo[1]
        info["type"] = arrayinfo[2]
        info["flag"] = arrayinfo[3]
        counter = sps.updatecounter(self.name, array)
        info["updatecounter"] = counter

        envdict = {}
        keylist = sps.getkeylist(self.name, array + "_ENV")
        for i in keylist:
            val = sps.getenv(self.name, array + "_ENV", i)
            envdict[i] = val
        info["envdict"] = envdict
        scantest = (info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN
        metadata = None
        if (array in ["SCAN_D"]) or scantest:
            # try to get new style SCAN_D metadata
            metadata = sps.getmetadata(self.name, array)
            if metadata is not None:
                motors, metadata = metadata
                #info["LabelNames"] = metadata["allcounters"].split(";")
                labels = list(motors.keys())
                try:
                    labels = [(int(x), x) for x in labels]
                except:
                    _logger.warning(
                        "SpsDataSource error reverting to old behavior")
                    labels = [(x, x) for x in labels]
                labels.sort()
                if len(labels):
                    info["LabelNames"] = [motors[x[1]] for x in labels]
                if len(metadata["allmotorm"]):
                    info["MotorNames"] = metadata["allmotorm"].split(";")
                    info["MotorValues"] = [float(x) \
                                for x in metadata["allpositions"].split(";")]
                info["nopts"] = int(metadata["npts"])
                supplied_info = sps.getinfo(self.name, array)
                if len(supplied_info):
                    info["nopts"] = int(supplied_info[0])
                if 'hkl' in metadata:
                    if len(metadata["hkl"]):
                        info['hkl'] = [float(x) \
                                for x in metadata["hkl"].split(";")]
                # current SCAN
                if 'scanno' in metadata:
                    envdict["scanno"] = int(metadata["scanno"])
                # current SPEC file and title
                for key in ["datafile", "title"]:
                    if key in metadata:
                        envdict[key] = metadata[key]
                # put any missing information
                if "selectedcounters" in metadata:
                    info["selectedcounters"] = [x \
                                for x in metadata["selectedcounters"].split()]
                # do not confuse with unhandled keys ...
                #for key in metadata:
                #    if key not in info:
                #        info[key] = metadata[key]
        if (metadata is None) and ((array in ["SCAN_D"]) or scantest):
            # old style SCAN_D metadata
            if 'axistitles' in info["envdict"]:
                info["LabelNames"] = self._buildLabelsList(
                    info['envdict']['axistitles'])
            if 'H' in info["envdict"]:
                if 'K' in info["envdict"]:
                    if 'L' in info["envdict"]:
                        info['hkl'] = [
                            envdict['H'], envdict['K'], envdict['L']
                        ]
        calibarray = array + "_PARAM"
        if calibarray in sps.getarraylist(self.name):
            try:
                data = sps.getdata(self.name, calibarray)
                updc = sps.updatecounter(self.name, calibarray)
                info["EnvKey"] = calibarray
                # data is an array
                info["McaCalib"] = data.tolist()[0]
                info["env_updatecounter"] = updc
            except:
                # Some of our C modules return NULL without setting
                # an exception ...
                pass

        if array in ["XIA_DATA", "XIA_BASELINE"]:
            envarray = "XIA_DET"
            if envarray in sps.getarraylist(self.name):
                try:
                    data = sps.getdata(self.name, envarray)
                    updc = sps.updatecounter(self.name, envarray)
                    info["EnvKey"] = envarray
                    info["Detectors"] = data.tolist()[0]
                    info["env_updatecounter"] = updc
                except:
                    pass
        return info
Beispiel #12
0
 def getDataObject(self, key_list, selection=None):
     if type(key_list) != types.ListType:
         nolist = True
         key_list = [key_list]
     else:
         output = []
         nolist = False
     if self.name in sps.getspeclist():
         sourcekeys = self.getSourceInfo()['KeyList']
         for key in key_list:
             #a key corresponds to an array name
             if key not in sourcekeys:
                 raise KeyError("Key %s not in source keys" % key)
             #array = key
             #create data object
             data = DataObject.DataObject()
             data.info = self.__getArrayInfo(key)
             data.info['selection'] = selection
             data.data = sps.getdata(self.name, key)
             if nolist:
                 if selection is not None:
                     scantest = (data.info['flag'] &
                                 sps.TAG_SCAN) == sps.TAG_SCAN
                     if ((key in ["SCAN_D"]) or scantest) \
                         and 'cntlist' in selection:
                         data.x = None
                         data.y = None
                         data.m = None
                         if 'nopts' in data.info['envdict']:
                             nopts = int(data.info['envdict']['nopts']) + 1
                         else:
                             nopts = data.info['rows']
                         if not 'LabelNames' in data.info:
                             data.info['LabelNames'] =\
                                 selection['cntlist'] * 1
                         if 'x' in selection:
                             for labelindex in selection['x']:
                                 label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.x is None: data.x = []
                                 data.x.append(data.data[:nopts, index])
                         if 'y' in selection:
                             for labelindex in selection['y']:
                                 label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.y is None: data.y = []
                                 data.y.append(data.data[:nopts, index])
                         if 'm' in selection:
                             for labelindex in selection['m']:
                                 label = data.info['LabelNames'][labelindex]
                                 if label not in data.info['LabelNames']:
                                     raise ValueError("Label %s not in scan labels" % label)
                                 index = data.info['LabelNames'].index(label)
                                 if data.m is None: data.m = []
                                 data.m.append(data.data[:nopts, index])
                         data.info['selectiontype'] = "1D"
                         data.info['scanselection'] = True
                         data.data = None
                         return data
                     if (key in ["XIA_DATA"]) and 'XIA' in selection:
                         if selection["XIA"]:
                             if 'Detectors' in data.info:
                                 for i in range(len(selection['rows']['y'])):
                                     selection['rows']['y'][i] = \
                                         data.info['Detectors'].index(selection['rows']['y'][i]) + 1
                                 del selection['XIA']
                     return data.select(selection)
                 else:
                     if data.data is not None:
                         data.info['selectiontype'] = "%dD" % len(data.data.shape)
                         if data.info['selectiontype'] == "2D":
                             data.info["imageselection"] = True
                     return data
             else:
                 output.append(data.select(selection))
         return output
     else:
         return None