def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'nexusFileName': obj_ = XSDataString() obj_.build(child_) self.setNexusFileName(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'instrument': obj_ = XSDataString() obj_.build(child_) self.setInstrument(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'energy': obj_ = XSDataArray() obj_.build(child_) self.setEnergy(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dataArray': obj_ = XSDataArray() obj_.build(child_) self.setDataArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pathToEnergyArray': obj_ = XSDataFile() obj_.build(child_) self.setPathToEnergyArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pathToDataArray': obj_ = XSDataFile() obj_.build(child_) self.setPathToDataArray(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'outputMatrix': obj_ = XSDataArray() obj_.build(child_) self.setOutputMatrix(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'data': obj_ = XSDataArray() obj_.build(child_) self.setData(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def unitTestArraytoXsdNoNumpy(self): """ test the execution of detectNumberOfCPUs """ EDVerbose.DEBUG("EDTestCaseEDUtilsArray.unitTestArraytoXsdNoNumpy") EDAssert.strAlmostEqual(XSDataArray.parseString(self.strXSDataArrayNoNumpy).marshal(), EDUtilsArray.arrayToXSData(self.arrayNumpy, _bForceNoNumpy=True).marshal(), _strComment="XSDataArray from (numpyArray) are the same (forced No Numpy)") EDAssert.strAlmostEqual(XSDataArray.parseString(self.strXSDataArrayNoNumpy).marshal(), EDUtilsArray.arrayToXSData(self.arrayNoNumpy, _bForceNoNumpy=True).marshal(), _strComment="XSDataArray from (list of lists) are the same (forced No Numpy)")
def unitTestArraytoXsd(self): """ test the execution of xsDataToArray static method """ EDVerbose.DEBUG("EDTestCaseEDUtilsArray.unitTestArraytoXsd") if numpy is not None: EDAssert.strAlmostEqual(XSDataArray.parseString(self.strXSDataArrayNumpy).marshal(), EDUtilsArray.arrayToXSData(self.arrayNumpy).marshal(), _strComment="XSDataArray from (numpyArray) are the same") else: EDAssert.strAlmostEqual(XSDataArray.parseString(self.strXSDataArrayNoNumpy).marshal(), EDUtilsArray.arrayToXSData(self.arrayNumpy).marshal(), _strComment="XSDataArray from (Non numpy Array) are the same")
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'lineStyle': value_ = '' for text__content_ in child_.childNodes: if text__content_.nodeValue is not None: value_ += text__content_.nodeValue self.__lineStyle = value_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'lineWidth': if child_.firstChild: sval_ = child_.firstChild.nodeValue try: fval_ = float(sval_) except ValueError: raise ValueError('requires float (or double) -- %s' % child_.toxml()) self.__lineWidth = fval_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'lineColor': value_ = '' for text__content_ in child_.childNodes: if text__content_.nodeValue is not None: value_ += text__content_.nodeValue self.__lineColor = value_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'label': value_ = '' for text__content_ in child_.childNodes: if text__content_.nodeValue is not None: value_ += text__content_.nodeValue self.__label = value_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'markerType': value_ = '' for text__content_ in child_.childNodes: if text__content_.nodeValue is not None: value_ += text__content_.nodeValue self.__markerType = value_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'markerColor': value_ = '' for text__content_ in child_.childNodes: if text__content_.nodeValue is not None: value_ += text__content_.nodeValue self.__markerColor = value_ elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'data': obj_ = XSDataArray() obj_.build(child_) self.setData(obj_) XSData.buildChildren(self, child_, nodeName_)
def testCheckParameters(self): xsDataInput = XSDataInputWriteMatrix() xsDataInput.setInputMatrix(XSDataArray()) xsDataInput.setOutputMatrixFile(XSDataFile()) edPluginExecMatrixWrite = self.createPlugin() edPluginExecMatrixWrite.setDataInput(xsDataInput) edPluginExecMatrixWrite.checkParameters()
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'title': obj_ = XSDataString() obj_.build(child_) self.setTitle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'long_name': obj_ = XSDataString() obj_.build(child_) self.setLong_name(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axis': obj_ = XSDataNexusAxis() obj_.build(child_) self.axis.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'data': obj_ = XSDataArray() obj_.build(child_) self.setData(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'signal': obj_ = XSDataInteger() obj_.build(child_) self.setSignal(obj_) XSData.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'title': obj_ = XSDataString() obj_.build(child_) self.setTitle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axis': obj_ = XSDataInteger() obj_.build(child_) self.setAxis(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'primary': obj_ = XSDataInteger() obj_.build(child_) self.setPrimary(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'units': obj_ = XSDataString() obj_.build(child_) self.setUnits(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'long_name': obj_ = XSDataString() obj_.build(child_) self.setLong_name(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axisData': obj_ = XSDataArray() obj_.build(child_) self.setAxisData(obj_) XSData.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'energy': obj_ = XSDataArray() obj_.build(child_) self.setEnergy(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dataArray': obj_ = XSDataArray() obj_.build(child_) self.setDataArray(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'edge': obj_ = XSDataDouble() obj_.build(child_) self.setEdge(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'slope': obj_ = XSDataDouble() obj_.build(child_) self.setSlope(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'jump': obj_ = XSDataDouble() obj_.build(child_) self.setJump(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'hwl': obj_ = XSDataDouble() obj_.build(child_) self.setHwl(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'ewl': obj_ = XSDataDouble() obj_.build(child_) self.setEwl(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort92': obj_ = XSDataArray() obj_.build(child_) self.setFort92(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort95': obj_ = XSDataArray() obj_.build(child_) self.setFort95(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort96': obj_ = XSDataArray() obj_.build(child_) self.setFort96(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort97': obj_ = XSDataArray() obj_.build(child_) self.setFort97(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort98': obj_ = XSDataArray() obj_.build(child_) self.setFort98(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fort99': obj_ = XSDataArray() obj_.build(child_) self.setFort99(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def __init__(self, _strTestName=None): EDTestCase.__init__(self, "EDUtilsArray") self.strXSDataArrayNumpy = """<?xml version="1.0" ?> <XSDataArray> <shape>10</shape> <shape>10</shape> <size>100</size> <dtype>uint8</dtype> <data>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw==</data> <coding><value>base64</value></coding> <md5sum><value>7acedd1a84a4cfcb6e7a16003242945e</value></md5sum> </XSDataArray>""" self.xsDataArrayNumpy = XSDataArray.parseString( self.strXSDataArrayNumpy) self.strXSDataArrayNoNumpy = """<?xml version="1.0" ?> <XSDataArray> <shape>10</shape> <shape>10</shape> <size>100</size> <dtype>int64</dtype> <data>AAAAAAAAAAABAAAAAAAAAAIAAAAAAAAAAwAAAAAAAAAEAAAAAAAAAAUAAAAAAAAABgAAAAAAAAAHAAAAAAAAAAgAAAAAAAAACQAAAAAAAAAKAAAAAAAAAAsAAAAAAAAADAAAAAAAAAANAAAAAAAAAA4AAAAAAAAADwAAAAAAAAAQAAAAAAAAABEAAAAAAAAAEgAAAAAAAAATAAAAAAAAABQAAAAAAAAAFQAAAAAAAAAWAAAAAAAAABcAAAAAAAAAGAAAAAAAAAAZAAAAAAAAABoAAAAAAAAAGwAAAAAAAAAcAAAAAAAAAB0AAAAAAAAAHgAAAAAAAAAfAAAAAAAAACAAAAAAAAAAIQAAAAAAAAAiAAAAAAAAACMAAAAAAAAAJAAAAAAAAAAlAAAAAAAAACYAAAAAAAAAJwAAAAAAAAAoAAAAAAAAACkAAAAAAAAAKgAAAAAAAAArAAAAAAAAACwAAAAAAAAALQAAAAAAAAAuAAAAAAAAAC8AAAAAAAAAMAAAAAAAAAAxAAAAAAAAADIAAAAAAAAAMwAAAAAAAAA0AAAAAAAAADUAAAAAAAAANgAAAAAAAAA3AAAAAAAAADgAAAAAAAAAOQAAAAAAAAA6AAAAAAAAADsAAAAAAAAAPAAAAAAAAAA9AAAAAAAAAD4AAAAAAAAAPwAAAAAAAABAAAAAAAAAAEEAAAAAAAAAQgAAAAAAAABDAAAAAAAAAEQAAAAAAAAARQAAAAAAAABGAAAAAAAAAEcAAAAAAAAASAAAAAAAAABJAAAAAAAAAEoAAAAAAAAASwAAAAAAAABMAAAAAAAAAE0AAAAAAAAATgAAAAAAAABPAAAAAAAAAFAAAAAAAAAAUQAAAAAAAABSAAAAAAAAAFMAAAAAAAAAVAAAAAAAAABVAAAAAAAAAFYAAAAAAAAAVwAAAAAAAABYAAAAAAAAAFkAAAAAAAAAWgAAAAAAAABbAAAAAAAAAFwAAAAAAAAAXQAAAAAAAABeAAAAAAAAAF8AAAAAAAAAYAAAAAAAAABhAAAAAAAAAGIAAAAAAAAAYwAAAAAAAAA=</data> <coding><value>base64</value></coding> <md5sum><value>13e5d157161f66d98fe0b75ce51c982b</value></md5sum> </XSDataArray>""" self.arrayNoNumpy = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49], [50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69], [70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, 87, 88, 89], [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]] if numpy is not None: self.arrayNumpy = numpy.arange(100, dtype="uint8").reshape( (10, 10)) else: self.arrayNumpy = self.arrayNoNumpy
def __init__(self, _strTestName=None): EDTestCase.__init__(self, "EDUtilsArray") self.strXSDataArrayNumpy = """<?xml version="1.0" ?> <XSDataArray> <shape>10</shape> <shape>10</shape> <size>100</size> <dtype>uint8</dtype> <data>AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw==</data> <coding><value>base64</value></coding> <md5sum><value>7acedd1a84a4cfcb6e7a16003242945e</value></md5sum> </XSDataArray>""" self.xsDataArrayNumpy = XSDataArray.parseString(self.strXSDataArrayNumpy) self.strXSDataArrayNoNumpy = """<?xml version="1.0" ?> <XSDataArray> <shape>10</shape> <shape>10</shape> <size>100</size> <dtype>int64</dtype> <data>AAAAAAAAAAABAAAAAAAAAAIAAAAAAAAAAwAAAAAAAAAEAAAAAAAAAAUAAAAAAAAABgAAAAAAAAAHAAAAAAAAAAgAAAAAAAAACQAAAAAAAAAKAAAAAAAAAAsAAAAAAAAADAAAAAAAAAANAAAAAAAAAA4AAAAAAAAADwAAAAAAAAAQAAAAAAAAABEAAAAAAAAAEgAAAAAAAAATAAAAAAAAABQAAAAAAAAAFQAAAAAAAAAWAAAAAAAAABcAAAAAAAAAGAAAAAAAAAAZAAAAAAAAABoAAAAAAAAAGwAAAAAAAAAcAAAAAAAAAB0AAAAAAAAAHgAAAAAAAAAfAAAAAAAAACAAAAAAAAAAIQAAAAAAAAAiAAAAAAAAACMAAAAAAAAAJAAAAAAAAAAlAAAAAAAAACYAAAAAAAAAJwAAAAAAAAAoAAAAAAAAACkAAAAAAAAAKgAAAAAAAAArAAAAAAAAACwAAAAAAAAALQAAAAAAAAAuAAAAAAAAAC8AAAAAAAAAMAAAAAAAAAAxAAAAAAAAADIAAAAAAAAAMwAAAAAAAAA0AAAAAAAAADUAAAAAAAAANgAAAAAAAAA3AAAAAAAAADgAAAAAAAAAOQAAAAAAAAA6AAAAAAAAADsAAAAAAAAAPAAAAAAAAAA9AAAAAAAAAD4AAAAAAAAAPwAAAAAAAABAAAAAAAAAAEEAAAAAAAAAQgAAAAAAAABDAAAAAAAAAEQAAAAAAAAARQAAAAAAAABGAAAAAAAAAEcAAAAAAAAASAAAAAAAAABJAAAAAAAAAEoAAAAAAAAASwAAAAAAAABMAAAAAAAAAE0AAAAAAAAATgAAAAAAAABPAAAAAAAAAFAAAAAAAAAAUQAAAAAAAABSAAAAAAAAAFMAAAAAAAAAVAAAAAAAAABVAAAAAAAAAFYAAAAAAAAAVwAAAAAAAABYAAAAAAAAAFkAAAAAAAAAWgAAAAAAAABbAAAAAAAAAFwAAAAAAAAAXQAAAAAAAABeAAAAAAAAAF8AAAAAAAAAYAAAAAAAAABhAAAAAAAAAGIAAAAAAAAAYwAAAAAAAAA=</data> <coding><value>base64</value></coding> <md5sum><value>13e5d157161f66d98fe0b75ce51c982b</value></md5sum> </XSDataArray>""" self.arrayNoNumpy = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49], [50, 51, 52, 53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69], [70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, 87, 88, 89], [90, 91, 92, 93, 94, 95, 96, 97, 98, 99]] if numpy is not None: self.arrayNumpy = numpy.arange(100, dtype="uint8").reshape((10, 10)) else: self.arrayNumpy = self.arrayNoNumpy
def arrayToXSData(cls, _array, _bIncludeMd5sum=True, _bForceNoNumpy=False): """ convert a numpy array or a list of list into an XSDataArray object @param _array: numpy array or array-like list @param _bIncludeMd5sum: should the md5sum be added to the XSDataArray instance. It is useful when sending object through the network It is a problem for testing @param _bForceNoNumpy: enables tests without numpy @type includeMd5sum: boolean @return: XSDataArray instance """ if True: # with cls.semArrayToXSData: xsdArray = XSDataArray() stringArray = "" shape = None dtype = None sizeDtype = None if bHaveNumpy is True and _bForceNoNumpy is False: EDVerbose.DEBUG("EDUtilsArray.arrayToXSData with numpy") # Enforce little Endianness if sys.byteorder == "big": _array.byteswap(True) stringArray = _array.tostring() shape = _array.shape dtype = str(_array.dtype) sizeDtype = len(numpy.zeros(1, dtype=_array.dtype).tostring()) else: EDVerbose.DEBUG("EDUtilsArray.arrayToXSData without numpy") sizeDtype = 8 # We enforce either double (float64) or int64 shape = [] subarray = _array while True: try: l = len(subarray) except TypeError: break shape.append(l) if l > 0: subarray = subarray[0] else: break if len(shape) == 1: if isinstance(_array[0], floatType): dtype = "float64" stringArray = struct.pack("<" + "d" * shape[0], *_array) else: dtype = "int64" stringArray = struct.pack("<" + "l" * shape[0], *_array) elif len(shape) == 2: if isinstance(_array[0][0], floatType): dtype = "float64" lineshape = "<" + "d" * shape[-1] else: dtype = "int64" lineshape = "<" + "q" * shape[-1] for subarray in _array: stringArray += struct.pack(lineshape, *subarray) elif len(shape) == 3: if isinstance(_array[0][0][0], floatType): dtype = "float64" lineshape = "<" + "d" * shape[-1] else: dtype = "int64" lineshape = "<" + "q" * shape[-1] for subarray in _array: for subsubarray in subarray: stringArray += struct.pack(lineshape, *subsubarray) else: EDVerbose.WARNING("EDUtilsArray.arrayToXSDataArray: Array too large %s " % (shape)) xsdArray.setData(base64.b64encode(stringArray)) xsdArray.setCoding(XSDataString("base64")) xsdArray.setShape(list(shape)) xsdArray.setDtype(dtype) size = 1 for i in shape: size *= i xsdArray.setSize(size) EDAssert.equal(size * sizeDtype, len(stringArray), "string representing the array has the right size") if _bIncludeMd5sum is True: xsdArray.setMd5sum(XSDataString(hashlib.md5(stringArray).hexdigest())) return xsdArray
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlTRExafsv1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") # Load from disk if necessary if self.dataInput.energy is None: if self.dataInput.pathToEnergyArray is None: strErrorMessage = "Data Input 'energy' is None" self.addErrorMessage(strErrorMessage) self.setFailure() return else: strXmlArray = EDUtilsFile.readFile( self.dataInput.pathToEnergyArray.path.value) self.dataInput.energy = XSDataArray.parseString(strXmlArray) if self.dataInput.dataArray is None: if self.dataInput.pathToDataArray is None: strErrorMessage = "Data Input 'dataArray' is None" self.addErrorMessage(strErrorMessage) self.setFailure() return else: strXmlArray = EDUtilsFile.readFile( self.dataInput.pathToDataArray.path.value) self.dataInput.dataArray = XSDataArray.parseString(strXmlArray) self.checkMandatoryParameters(self.dataInput.dataArray, "Data Input 'dataArray' is None") # numpyDataArray = EDUtilsArray.xsDataToArray(self.dataInput.dataArray) numpyEnergyCalibrationArray = EDUtilsArray.xsDataToArray( self.dataInput.energy) numpySpectraArray = numpy.arange((numpyDataArray.shape[1])) # Launch Jesf listEdPluginExecJesf = self.launchJesfPlugins( numpyDataArray, numpyEnergyCalibrationArray) # Create nexus file xsDataInputWriteNexusFile = XSDataInputWriteNexusFile() xsDataInputWriteNexusFile.instrument = self.dataInput.instrument xsDataInputWriteNexusFile.outputFileName = self.dataInput.nexusFileName # Raw data xsDataNexusArrayGroupRawData = self.createNexusGroup( _numpyDataArray=numpyDataArray, _groupTitle="Raw data", _groupLongName="Raw data", _numpyXAxisDataArray=numpyEnergyCalibrationArray, _xAxisTitle="e", _xAxisLongName="Energy", _xAxisUnit="kev", _numpyYAxisDataArray=numpySpectraArray, _yAxisTitle="n", _yAxisLongName="Spectra", _yAxisUnit="") xsDataInputWriteNexusFile.addNexusGroup(xsDataNexusArrayGroupRawData) # Create result data arrays dictResultArrays = self.createResultArrays(listEdPluginExecJesf) # Add results arrays to nexus file self.addResultArraysToNexusFile(dictResultArrays, xsDataInputWriteNexusFile) # edPluginExecWriteNexusData = self.loadPlugin( self.strWriteNexusFilePluginName) edPluginExecWriteNexusData.dataInput = xsDataInputWriteNexusFile edPluginExecWriteNexusData.executeSynchronous() xsDataResultTRExafs = XSDataResultTRExafs() if not edPluginExecWriteNexusData.isFailure(): xsDataNexusFile = edPluginExecWriteNexusData.dataOutput.outputFilePath xsDataResultTRExafs.nexusFile = xsDataNexusFile # self.dataOutput = xsDataResultTRExafs
def process(self, _edObject = None): EDPluginControl.process(self) self.DEBUG("EDPluginControlTRExafsv1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") # Load from disk if necessary if self.dataInput.energy is None: if self.dataInput.pathToEnergyArray is None: strErrorMessage = "Data Input 'energy' is None" self.addErrorMessage(strErrorMessage) self.setFailure() return else: strXmlArray = EDUtilsFile.readFile(self.dataInput.pathToEnergyArray.path.value) self.dataInput.energy = XSDataArray.parseString(strXmlArray) if self.dataInput.dataArray is None: if self.dataInput.pathToDataArray is None: strErrorMessage = "Data Input 'dataArray' is None" self.addErrorMessage(strErrorMessage) self.setFailure() return else: strXmlArray = EDUtilsFile.readFile(self.dataInput.pathToDataArray.path.value) self.dataInput.dataArray = XSDataArray.parseString(strXmlArray) self.checkMandatoryParameters(self.dataInput.dataArray, "Data Input 'dataArray' is None") # numpyDataArray = EDUtilsArray.xsDataToArray(self.dataInput.dataArray) numpyEnergyCalibrationArray = EDUtilsArray.xsDataToArray(self.dataInput.energy) numpySpectraArray = numpy.arange((numpyDataArray.shape[0])) # Launch Jesf listEdPluginExecJesf = self.launchJesfPlugins(numpyDataArray, numpyEnergyCalibrationArray) # Create nexus file xsDataInputWriteNexusFile = XSDataInputWriteNexusFile() xsDataInputWriteNexusFile.instrument = self.dataInput.instrument xsDataInputWriteNexusFile.outputFileName = self.dataInput.nexusFileName # Raw data xsDataNexusArrayGroupRawData = self.createNexusGroup( _numpyDataArray = numpyDataArray, _groupTitle = "Raw data", _groupLongName = "Raw data", _numpyXAxisDataArray = numpyEnergyCalibrationArray, _xAxisTitle = "e", _xAxisLongName = "Energy", _xAxisUnit = "kev", _numpyYAxisDataArray = numpySpectraArray, _yAxisTitle = "n", _yAxisLongName = "Spectra", _yAxisUnit = "") xsDataInputWriteNexusFile.addNexusGroup(xsDataNexusArrayGroupRawData) # Create result data arrays dictResultArrays = self.createResultArrays(listEdPluginExecJesf) # Add results arrays to nexus file self.addResultArraysToNexusFile(dictResultArrays, xsDataInputWriteNexusFile) # edPluginExecWriteNexusData = self.loadPlugin(self.strWriteNexusFilePluginName) edPluginExecWriteNexusData.dataInput = xsDataInputWriteNexusFile edPluginExecWriteNexusData.executeSynchronous() xsDataResultTRExafs = XSDataResultTRExafs() if not edPluginExecWriteNexusData.isFailure(): xsDataNexusFile = edPluginExecWriteNexusData.dataOutput.outputFilePath xsDataResultTRExafs.nexusFile = xsDataNexusFile # self.dataOutput = xsDataResultTRExafs
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'title': obj_ = XSDataString() obj_.build(child_) self.setTitle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataQ': obj_ = XSDataDouble() obj_.build(child_) self.experimentalDataQ.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataQArray': obj_ = XSDataArray() obj_.build(child_) self.setExperimentalDataQArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataValues': obj_ = XSDataDouble() obj_.build(child_) self.experimentalDataValues.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataIArray': obj_ = XSDataArray() obj_.build(child_) self.setExperimentalDataIArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataStdDev': obj_ = XSDataDouble() obj_.build(child_) self.experimentalDataStdDev.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataStdArray': obj_ = XSDataArray() obj_.build(child_) self.setExperimentalDataStdArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalDataFile': obj_ = XSDataFile() obj_.build(child_) self.setExperimentalDataFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'rMaxSearchSettings': obj_ = XSDataSolutionScatteringSettings() obj_.build(child_) self.setRMaxSearchSettings(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'angularUnits': obj_ = XSDataInteger() obj_.build(child_) self.setAngularUnits(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'symmetry': obj_ = XSDataString() obj_.build(child_) self.setSymmetry(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'mode': obj_ = XSDataString() obj_.build(child_) self.setMode(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'iNbThreads': obj_ = XSDataInteger() obj_.build(child_) self.setINbThreads(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'onlyGnom': obj_ = XSDataBoolean() obj_.build(child_) self.setOnlyGnom(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'plotFit': obj_ = XSDataBoolean() obj_.build(child_) self.setPlotFit(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'qMin': obj_ = XSDataDouble() obj_.build(child_) self.setQMin(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'qMax': obj_ = XSDataDouble() obj_.build(child_) self.setQMax(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'corelationFitValues': obj_ = XSDataDouble() obj_.build(child_) self.corelationFitValues.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fitFile': obj_ = XSDataFile() obj_.build(child_) self.setFitFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'lineProfileFitQuality': obj_ = XSDataDouble() obj_.build(child_) self.setLineProfileFitQuality(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'logFile': obj_ = XSDataFile() obj_.build(child_) self.setLogFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pdbMoleculeFile': obj_ = XSDataFile() obj_.build(child_) self.setPdbMoleculeFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pdbSolventFile': obj_ = XSDataFile() obj_.build(child_) self.setPdbSolventFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scatteringFitQ': obj_ = XSDataDouble() obj_.build(child_) self.scatteringFitQ.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scatteringFitValues': obj_ = XSDataDouble() obj_.build(child_) self.scatteringFitValues.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scatteringFitQArray': obj_ = XSDataArray() obj_.build(child_) self.setScatteringFitQArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scatteringFitIarray': obj_ = XSDataArray() obj_.build(child_) self.setScatteringFitIarray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'meanNSD': obj_ = XSDataDouble() obj_.build(child_) self.setMeanNSD(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'variationNSD': obj_ = XSDataDouble() obj_.build(child_) self.setVariationNSD(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def arrayToXSData(cls, _array, _bIncludeMd5sum=True, _bForceNoNumpy=False, _bUseAsserts=False): """ convert a numpy array or a list of list into an XSDataArray object @param _array: numpy array or array-like list @param _bIncludeMd5sum: should the md5sum be added to the XSDataArray instance. It is useful when sending object through the network It is a problem for testing @param _bForceNoNumpy: enables tests without numpy @type includeMd5sum: boolean @return: XSDataArray instance """ stringArray = "" shape = None dtype = None sizeDtype = None if bHaveNumpy is True and _bForceNoNumpy is False: EDVerbose.DEBUG("EDUtilsArray.arrayToXSData with numpy") # Enforce little Endianness if sys.byteorder == "big": _array.byteswap(True) stringArray = _array.tostring() shape = _array.shape dtype = str(_array.dtype) sizeDtype = len(numpy.zeros(1, dtype=_array.dtype).tostring()) else: EDVerbose.DEBUG("EDUtilsArray.arrayToXSData without numpy") sizeDtype = 8 # We enforce either double (float64) or int64 shape = [] subarray = _array while True: try: l = len(subarray) except TypeError: break shape.append(l) if l > 0: subarray = subarray[0] else: break if len(shape) == 1: if isinstance(_array[0], floatType): dtype = "float64" stringArray = struct.pack("<" + "d" * shape[0], *_array) else: dtype = "int64" stringArray = struct.pack("<" + "l" * shape[0], *_array) elif len(shape) == 2: if isinstance(_array[0][0], floatType): dtype = "float64" lineshape = "<" + "d" * shape[-1] else: dtype = "int64" lineshape = "<" + "q" * shape[-1] for subarray in _array: stringArray += struct.pack(lineshape, *subarray) elif len(shape) == 3: if isinstance(_array[0][0][0], floatType): dtype = "float64" lineshape = "<" + "d" * shape[-1] else: dtype = "int64" lineshape = "<" + "q" * shape[-1] for subarray in _array: for subsubarray in subarray: stringArray += struct.pack(lineshape, *subsubarray) else: EDVerbose.WARNING( "EDUtilsArray.arrayToXSDataArray: Array too large %s " % (shape)) size = 1 for i in shape: size *= i xsdArray = XSDataArray(data=base64.b64encode(stringArray), coding=XSDataString("base64"), shape=list(shape), dtype=dtype, size=size) if _bUseAsserts: EDAssert.equal(size * sizeDtype, len(stringArray), "string representing the array has the right size") if _bIncludeMd5sum is True: xsdArray.setMd5sum( XSDataString(hashlib.md5(stringArray).hexdigest())) return xsdArray
def testCheckParameters(self): xsDataInput = XSDataInputMatrixInvert() xsDataInput.setInputMatrix(XSDataArray()) edPluginExecMatrixInvert = self.createPlugin() edPluginExecMatrixInvert.setDataInput(xsDataInput) edPluginExecMatrixInvert.checkParameters()