def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecShiftImagev1_0.preProcess") sdi = self.dataInput if sdi.inputImage is not None: self.npaImage = numpy.array(EDUtilsArray.getArray(sdi.inputImage)) elif sdi.inputArray is not None: self.npaImage = EDUtilsArray.xsDataToArray(sdi.getInputArray()) else: self.ERROR( "EDPluginExecShiftImagev1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError offset = sdi.offset if len(offset) == 2: self.tOffset = (offset[0].value, offset[1].value) elif len(offset) == 1: self.tOffset = (offset[0].value, offset[0].value) if sdi.outputImage is not None: if sdi.outputImage.path is not None: self.strOutputType = "file" self.strOutputImage = sdi.outputImage.path.value if sdi.outputImage.shared is not None: self.strOutputType = "shared" self.strOutputImage = sdi.outputImage.shared.value if sdi.outputImage.array is not None: self.strOutputType = "array"
def testExecute(self): """ """ self.run() plugin = self.getPlugin() # Checking obtained results xsDataResult = plugin.getDataOutput() xsDataRef = XSDataResult1DPowderEDF.parseString( self.readAndParseFile(self.getReferenceDataOutputFile())) # EDAssert.strAlmostEqual(XSDataResult1DPowderEDF.parseString(self.readAndParseFile(self.getReferenceDataOutputFile())).marshal(), xsDataResult.marshal(), _strComment="XML structures are the same") tthref = EDUtilsArray.xsDataToArray(xsDataRef.getTwoTheta(), _bCheckMd5sum=False) tthobt = EDUtilsArray.xsDataToArray(xsDataResult.getTwoTheta(), _bCheckMd5sum=False) Iref = EDUtilsArray.xsDataToArray(xsDataRef.getIntensity(), _bCheckMd5sum=False) Iobt = EDUtilsArray.xsDataToArray(xsDataResult.getIntensity(), _bCheckMd5sum=False) EDAssert.arraySimilar(_npaValue=tthobt, _npaRef=tthref, _fAbsMaxDelta=0.1, _strComment="2theta arrays are the same") EDAssert.arraySimilar(_npaValue=Iobt, _npaRef=Iref, _fAbsMaxDelta=0.1, _strComment="Intensity arrays are the same")
def process(self, _edObject = None): EDPluginExec.process(self) self.DEBUG("EDPluginExecReadDataID24v1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") self.checkMandatoryParameters(self.dataInput.inputFile, "Data Input 'inputFile' is None") self.checkMandatoryParameters(self.dataInput.energyCalibration, "Data Input 'energyuCalibration' is None") self.checkMandatoryParameters(self.dataInput.energyCalibration.a, "Data Input 'energyCalibration a' is None") self.checkMandatoryParameters(self.dataInput.energyCalibration.b, "Data Input 'energyCalibration b' is None") # Load input data listNumpyArray = [] iNumberOfSPectra = 0 iNumberOfEnergies = 0 for xsDataFile in self.dataInput.inputFile: numpyDataArray = self.loadInputData(xsDataFile.path.value) # print numpyDataArray.shape listNumpyArray.append(numpyDataArray) iNumberOfEnergies = numpyDataArray.shape[0] iNumberOfSPectra += numpyDataArray.shape[1] numpyTotalDataArray = numpy.zeros((iNumberOfEnergies,iNumberOfSPectra)) # print numpyTotalDataArray.shape iIndex = 0 for numpyDataArray in listNumpyArray: iSpectra = numpyDataArray.shape[1] numpyTotalDataArray[:,iIndex:iIndex+iSpectra] = numpyDataArray iIndex += iSpectra # Create energy calibration array numpyEnergyCalibrationArray = self.createEnergyCalibrationArray(numpyTotalDataArray.shape[0], self.dataInput.energyCalibration) # Create some output data xsDataResultReadDataID24 = XSDataResultReadDataID24() xsDataResultReadDataID24.energy = EDUtilsArray.arrayToXSData(numpyEnergyCalibrationArray) xsDataResultReadDataID24.dataArray = EDUtilsArray.arrayToXSData(numpyTotalDataArray) self.setDataOutput(xsDataResultReadDataID24)
def createNexusGroup(self, _numpyDataArray,_groupTitle, _groupLongName, _numpyXAxisDataArray=None, _xAxisTitle=None, _xAxisLongName=None, _xAxisUnit=None, _numpyYAxisDataArray=None, _yAxisTitle=None, _yAxisLongName=None, _yAxisUnit=None, ): # Create entry for data arrays in nexus file xsDataNexusArrayGroup = XSDataNexusArrayGroup() xsDataNexusArrayGroup.title = XSDataString(_groupTitle) xsDataNexusArrayGroup.long_name = XSDataString(_groupLongName) xsDataNexusArrayGroup.data = EDUtilsArray.arrayToXSData(_numpyDataArray) xsDataNexusArrayGroup.signal = XSDataInteger(1) if _numpyXAxisDataArray is not None: xsDataNexusAxisX = XSDataNexusAxis() xsDataNexusAxisX.title = XSDataString(_xAxisTitle) xsDataNexusAxisX.long_name = XSDataString(_xAxisLongName) xsDataNexusAxisX.primary = XSDataInteger(1) xsDataNexusAxisX.axis = XSDataInteger(0) xsDataNexusAxisX.units = XSDataString(_xAxisUnit) xsDataNexusAxisX.axisData = EDUtilsArray.arrayToXSData(_numpyXAxisDataArray) xsDataNexusArrayGroup.addAxis(xsDataNexusAxisX) if _numpyYAxisDataArray is not None: xsDataNexusAxisY = XSDataNexusAxis() xsDataNexusAxisY.title = XSDataString(_yAxisTitle) xsDataNexusAxisY.long_name = XSDataString(_yAxisLongName) xsDataNexusAxisY.primary = XSDataInteger(2) xsDataNexusAxisY.axis = XSDataInteger(1) xsDataNexusAxisY.units = XSDataString(_yAxisUnit) xsDataNexusAxisY.axisData = EDUtilsArray.arrayToXSData(_numpyYAxisDataArray) xsDataNexusArrayGroup.addAxis(xsDataNexusAxisY) # print xsDataInputWriteNexusFile.marshal() return xsDataNexusArrayGroup
def preProcess(self, _edObject=None): EDPluginHDF5.preProcess(self) self.DEBUG("EDPluginHDF5StackImagesv10.preProcess") for onefile in self.dataInput.inputImageFile: if onefile is None: self.ERROR("Please investigate why EDPluginHDF5StackImagesv10.dataInput.inputImageFile is a list containing None !!!!") self.setFailure() continue if onefile.path is not None: self.listImageFilenames.append(onefile.path.value) if onefile.date is not None: self.listImageDates.append(onefile.date.value) if onefile.number is not None: self.listForcedPositions.append(onefile.number.value) self.listArray.append(EDUtilsArray.getArray(onefile)) for oneArray in self.dataInput.inputArray: self.listArray.append(EDUtilsArray.xsDataToArray(oneArray)) if self.dataInput.index != []: self.listForcedPositions = [i.value for i in self.dataInput.index] if self.dataInput.getDeleteInputImage() is not None: self.bDeleteImage = bool(self.dataInput.deleteInputImage.value) if self.listForcedPositions != []: EDAssert.equal(len(self.listForcedPositions), max(len(self.listImageFilenames), len(self.listArray)), "Forced position list has a good length") if self.listImageDates != []: EDAssert.equal(len(self.listImageDates) , len(self.listImageFilenames), "listImageDates has the same size as listImageFilenames") self.hdf5group = EDPluginHDF5.createStructure(self.strHDF5Filename, self.strHDF5Path, self.dictExtraAttributes)
def preProcess(self, _edObject=None): EDPluginHDF5.preProcess(self) self.DEBUG("EDPluginHDF5StackImagesv10test.preProcess") for onefile in self.dataInput.inputImageFile: if onefile.path is not None: self.listImageFilenames.append(onefile.path.value) if onefile.date is not None: self.listImageDates.append(onefile.date.value) if onefile.number is not None: self.listForcedPositions.append(onefile.number.value) self.listArray.append(EDUtilsArray.getArray(onefile)) for oneArray in self.dataInput.getInputArray(): self.listArray.append(EDUtilsArray.xsDataToArray(oneArray)) if self.dataInput.index != []: self.listForcedPositions = [i.value for i in self.dataInput.index] if self.dataInput.getDeleteInputImage() is not None: self.bDeleteImage = bool(self.dataInput.deleteInputImage.value) if self.listForcedPositions != []: EDAssert.equal(len(self.listForcedPositions), max(len(self.listImageFilenames), len(self.listArray)), "Forced position list has a good length") if self.listImageDates != []: EDAssert.equal(len(self.listImageDates) , len(self.listImageFilenames), "listImageDates has the same size as listImageFilenames")
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecShiftImagev1_0.preProcess") sdi = self.dataInput if sdi.inputImage is not None: self.npaImage = numpy.array(EDUtilsArray.getArray(sdi.inputImage)) elif sdi.inputArray is not None: self.npaImage = EDUtilsArray.xsDataToArray(sdi.getInputArray()) else: self.ERROR("EDPluginExecShiftImagev1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError offset = sdi.offset if len(offset) == 2: self.tOffset = (offset[0].value, offset[1].value) elif len(offset) == 1: self.tOffset = (offset[0].value, offset[0].value) if sdi.outputImage is not None: if sdi.outputImage.path is not None: self.strOutputType = "file" self.strOutputImage = sdi.outputImage.path.value if sdi.outputImage.shared is not None: self.strOutputType = "shared" self.strOutputImage = sdi.outputImage.shared.value if sdi.outputImage.array is not None: self.strOutputType = "array"
def testExecute(self): """ """ self.run() # plugin = self.getPlugin() strExpectedOutput = self.readAndParseFile( self.getReferenceDataOutputFile()) strObtainedOutput = self.readAndParseFile( self.m_edObtainedOutputDataFile) EDVerbose.DEBUG("Checking obtained result...") xsDataResultReference = XSDataResultNormalize.parseString( strExpectedOutput) xsDataResultObtained = XSDataResultNormalize.parseString( strObtainedOutput) #EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "Result XML are the same") npaReference = EDUtilsArray.getArray(xsDataResultReference.output) npaObtained = EDUtilsArray.getArray(xsDataResultObtained.output) EDAssert.arraySimilar(npaReference, npaObtained, "Arrays are the same", _fAbsMaxDelta=1e-6) EDAssert.equal(npaReference.dtype, npaObtained.dtype, "Datatypes are the same")
def testExecute(self): """ """ self.run() plugin = self.getPlugin() # Checking obtained results xsDataResult = plugin.getDataOutput() xsDataRef = XSDataResult1DPowderEDF.parseString( self.readAndParseFile(self.getReferenceDataOutputFile())) # EDAssert.strAlmostEqual(XSDataResult1DPowderEDF.parseString(self.readAndParseFile(self.getReferenceDataOutputFile())).marshal(), xsDataResult.marshal(), _strComment="XML structures are the same") tthref = EDUtilsArray.xsDataToArray( xsDataRef.getTwoTheta(), _bCheckMd5sum=False) tthobt = EDUtilsArray.xsDataToArray( xsDataResult.getTwoTheta(), _bCheckMd5sum=False) Iref = EDUtilsArray.xsDataToArray( xsDataRef.getIntensity(), _bCheckMd5sum=False) Iobt = EDUtilsArray.xsDataToArray( xsDataResult.getIntensity(), _bCheckMd5sum=False) EDAssert.arraySimilar( _npaValue=tthobt, _npaRef=tthref, _fAbsMaxDelta=0.1, _strComment="2theta arrays are the same") EDAssert.arraySimilar( _npaValue=Iobt, _npaRef=Iref, _fAbsMaxDelta=0.1, _strComment="Intensity arrays are the same")
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecShiftImagev1_0.postProcess") # Create some output data xsDataResult = XSDataResultShiftImage() if self.strOutputType is None: xsDataResult.setOutputArray( EDUtilsArray.arrayToXSData(self.npaImage)) elif self.strOutputType == "file": image = edfimage(data=self.npaImage, header={ "Offset_1": self.tOffset[0], "Offset_2": self.tOffset[1], "Max_Offset": self.MAX_OFFSET_VALUE }) image.write(self.strOutputImage, force_type=self.npaImage.dtype) xsdimg = XSDataImageExt(path=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "shared": EDShare[self.strOutputImage] = self.npaImage xsdimg = XSDataImageExt(shared=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "array": xsdimg = XSDataImageExt( array=EDUtilsArray.arrayToXSData(self.npaImage)) xsDataResult.outputImage = xsdimg self.setDataOutput(xsDataResult) self.npaImage = None
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecShiftImagev1_0.postProcess") # Create some output data xsDataResult = XSDataResultShiftImage() if self.strOutputType is None: xsDataResult.setOutputArray(EDUtilsArray.arrayToXSData(self.npaImage)) elif self.strOutputType == "file": image = edfimage( data=self.npaImage, header={"Offset_1": self.tOffset[0], "Offset_2": self.tOffset[1], "Max_Offset": self.MAX_OFFSET_VALUE}, ) image.write(self.strOutputImage, force_type=self.npaImage.dtype) xsdimg = XSDataImageExt(path=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "shared": EDShare[self.strOutputImage] = self.npaImage xsdimg = XSDataImageExt(shared=XSDataString(self.strOutputImage)) xsDataResult.outputImage = xsdimg elif self.strOutputType == "array": xsdimg = XSDataImageExt(array=EDUtilsArray.arrayToXSData(self.npaImage)) xsDataResult.outputImage = xsdimg self.setDataOutput(xsDataResult) self.npaImage = None
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecPyFAIv1_0.preProcess") sdi = self.dataInput ai = pyFAI.AzimuthalIntegrator() if sdi.geometryFit2D is not None: xsGeometry = sdi.geometryFit2D detector = self.getDetector(xsGeometry.detector) d = {"direct": EDUtilsUnit.getSIValue(xsGeometry.distance) * 1000, #fit2D takes the distance in mm "centerX": xsGeometry.beamCentreInPixelsX.value , "centerY":xsGeometry.beamCentreInPixelsY.value , "tilt": xsGeometry.angleOfTilt.value, "tiltPlanRotation": xsGeometry.tiltRotation.value} d.update(detector.getFit2D()) ai.setFit2D(**d) elif sdi.geometryPyFAI is not None: xsGeometry = sdi.geometryPyFAI detector = self.getDetector(xsGeometry.detector) d = {"dist": EDUtilsUnit.getSIValue(xsGeometry.sampleDetectorDistance), "poni1": EDUtilsUnit.getSIValue(xsGeometry.pointOfNormalIncidence1), "poni2": EDUtilsUnit.getSIValue(xsGeometry.pointOfNormalIncidence2), "rot1": EDUtilsUnit.getSIValue(xsGeometry.rotation1), "rot2": EDUtilsUnit.getSIValue(xsGeometry.rotation2), "rot3": EDUtilsUnit.getSIValue(xsGeometry.rotation3)} d.update(detector.getPyFAI()) ai.setPyFAI(**d) else: strError = "Geometry definition in %s, not recognized as a valid geometry%s %s" % (sdi, os.linesep, sdi.marshal()) self.ERROR(strError) raise RuntimeError(strError) ######################################################################## # Choose the azimuthal integrator ######################################################################## with self.__class__._sem: if tuple(ai.param) in self.__class__._dictGeo: self.ai = self.__class__._dictGeo[tuple(ai.param)] else: self.__class__._dictGeo[tuple(ai.param)] = ai self.ai = ai self.data = EDUtilsArray.getArray(self.dataInput.input).astype(float) if sdi.dark is not None: self.data -= EDUtilsArray.getArray(sdi.dark) if sdi.flat is not None: self.data /= EDUtilsArray.getArray(sdi.flat) if sdi.mask is not None: self.mask = EDUtilsArray.getArray(sdi.mask) if sdi.wavelength is not None: self.ai.wavelength = EDUtilsUnit.getSIValue(sdi.wavelength) if sdi.output is not None: self.strOutputFile = sdi.output.path.value if sdi.dummy is not None: self.dummy = sdi.dummy.value if sdi.deltaDummy is not None: self.delta_dummy = sdi.deltaDummy.value if sdi.nbPt: self.nbPt = sdi.nbPt.value
def process(self, _edObject = None): EDPluginExec.process(self) self.DEBUG("EDPluginExecWriteNexusFilev1_0.process") xsDataInput = self.getDataInput() # print xsDataInput.marshal() fileName = str(xsDataInput.outputFileName.value) if xsDataInput.outputFileDirectory is None: fileDir = self.getWorkingDirectory() else: fileDir = str(xsDataInput.outputFileDirectory.value) # timestamp = "2010-10-18T17:17:04-0500" timestamp = datetime.datetime.now().isoformat() instrument = str(xsDataInput.instrument.value) # Create nexus file nexusFile = self.makeFile(os.path.join(fileDir, fileName), file_name=fileName, file_time=timestamp, instrument=instrument, creator="EDPluginExecWriteNexusFilev1_0", NeXus_version="4.3.0", HDF5_Version=h5py.version.hdf5_version, h5py_version=h5py.version.version) # Write main data nxentry = self.makeGroup(nexusFile, "Result", "NXentryResult") for nexusGroup in xsDataInput.nexusGroup: groupTitle = str(nexusGroup.title.value) long_name = str(nexusGroup.long_name.value) nxdata = self.makeGroup(nxentry, groupTitle, "NXdata", long_name=long_name) # First add the axes - if any... listAxisNames = [] for xsDataNexusAxis in nexusGroup.axis: numpyAxisArray = EDUtilsArray.xsDataToArray(xsDataNexusAxis.axisData) self.makeDataset(nxdata, str(xsDataNexusAxis.title.value), numpyAxisArray, axis=xsDataNexusAxis.axis.value, primary=xsDataNexusAxis.primary.value, units=str(xsDataNexusAxis.units.value), long_name=str(xsDataNexusAxis.long_name.value)) listAxisNames.append(str(xsDataNexusAxis.title.value)) numpyDataArray = EDUtilsArray.xsDataToArray(nexusGroup.data) strAxisNames = "" bFirst = True for strAxisName in listAxisNames: if bFirst: strAxisNames += strAxisName bFirst = False else: strAxisNames += ":"+strAxisName self.makeDataset(nxdata, groupTitle, numpyDataArray.transpose(), signal='1', # Y axis of default plot axes=strAxisNames, # name of X and Y axes long_name=long_name) pass xsDataResult = XSDataResultWriteNexusFile() xsDataResult.outputFilePath = XSDataFile(XSDataString(os.path.join(fileDir, fileName))) self.setDataOutput(xsDataResult)
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecNormalizeImagev1_2.preProcess") sdi = self.getDataInput() if sdi.dataScaleFactor is not None: self.scaleData = sdi.dataScaleFactor.value if sdi.darkScaleFactor is not None: self.scaleDark = sdi.darkScaleFactor.value if sdi.flatScaleFactor is not None: self.scaleFlat = sdi.flatScaleFactor.value if sdi.data == []: strError = "You should either provide at least ONE input filename or an array, you provided: %s" % sdi.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) else: for inputData in sdi.data: if inputData.exposureTime is None: self.WARNING("You did not provide an exposure time for DATA... using default: 1") self.listDataExposure.append(1.0) else: self.listDataExposure.append(EDUtilsUnit.getSIValue(inputData.exposureTime)) self.listDataArray.append(EDUtilsArray.getArray(inputData) / self.scaleData) for inputFlat in sdi.flat: if inputFlat.exposureTime is None: self.WARNING("You did not provide an exposure time for FLAT... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputFlat.exposureTime) self.listFlatExposure.append(expTime) self.listFlatArray.append(EDUtilsArray.getArray(inputFlat) / self.scaleFlat) with self.__class__.semaphore: for inputDark in sdi.dark: if inputDark.exposureTime is None: self.WARNING("You did not provide an exposure time for Dark... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputDark.exposureTime) # strMeanDarkKey = "/".join((self.getClassName(), "MeanDark%6.3f" % expTime)) if str(expTime) not in self.__class__.dictDark: self.listDarkExposure.append(expTime) self.listDarkArray.append(EDUtilsArray.getArray(inputDark) / self.scaleDark) if sdi.output is not None: if (sdi.output.path is not None): self.strOutputFilename = sdi.output.path.value elif (sdi.output.shared is not None): self.strOutputShared = sdi.output.shared.value # else export as array. EDAssert.equal(len(self.listDataArray), len(self.listDataExposure), _strComment="number of data images / exposure times ") EDAssert.equal(len(self.listFlatArray), len(self.listFlatExposure), _strComment="number of flat images / exposure times ") EDAssert.equal(len(self.listDarkArray), len(self.listDarkExposure), _strComment="number of dark images / exposure times ")
def process(self, _edObject = None): EDPluginExec.process(self) self.DEBUG("EDPluginExecWriteNexusFilev1_0.process") xsDataInput = self.getDataInput() # print xsDataInput.marshal() fileName = str(xsDataInput.outputFileName.value) if xsDataInput.outputFileDirectory is None: fileDir = self.getWorkingDirectory() else: fileDir = str(xsDataInput.outputFileDirectory.value) # timestamp = "2010-10-18T17:17:04-0500" timestamp = datetime.datetime.now().isoformat() instrument = str(xsDataInput.instrument.value) # Create nexus file nexusFile = self.makeFile(os.path.join(fileDir, fileName), file_name=fileName, file_time=timestamp, instrument=instrument, creator="EDPluginExecWriteNexusFilev1_0", NeXus_version="4.3.0", HDF5_Version=h5py.version.hdf5_version, h5py_version=h5py.version.version) # Write main data nxentry = self.makeGroup(nexusFile, "Result", "NXEntry") for nexusGroup in xsDataInput.nexusGroup: groupTitle = str(nexusGroup.title.value) long_name = str(nexusGroup.long_name.value) nxdata = self.makeGroup(nxentry, groupTitle, "NXdata", long_name=long_name, interpretation="spectrum") # First add the axes - if any... listAxisNames = [] for xsDataNexusAxis in nexusGroup.axis: numpyAxisArray = EDUtilsArray.xsDataToArray(xsDataNexusAxis.axisData) self.makeDataset(nxdata, str(xsDataNexusAxis.title.value), numpyAxisArray, axis=xsDataNexusAxis.axis.value, primary=xsDataNexusAxis.primary.value, units=str(xsDataNexusAxis.units.value), long_name=str(xsDataNexusAxis.long_name.value)) listAxisNames.append(str(xsDataNexusAxis.title.value)) numpyDataArray = EDUtilsArray.xsDataToArray(nexusGroup.data) strAxisNames = "" bFirst = True for strAxisName in listAxisNames: if bFirst: strAxisNames += strAxisName bFirst = False else: strAxisNames += ":"+strAxisName self.makeDataset(nxdata, groupTitle, numpyDataArray.transpose(), signal='1', # Y axis of default plot axes=strAxisNames, # name of X and Y axes long_name=long_name) pass xsDataResult = XSDataResultWriteNexusFile() xsDataResult.outputFilePath = XSDataFile(XSDataString(os.path.join(fileDir, fileName))) self.setDataOutput(xsDataResult)
def doSuccessProcessOneFile(self, _edPlugin=None): self.DEBUG("EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile") self.retrieveSuccessMessages(_edPlugin, "EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile") if _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary: self.lstExecutiveSummary.append(_edPlugin.dataOutput.status.executiveSummary.value) output = _edPlugin.dataOutput if not output.integratedCurve: strErr = "Edna plugin ProcessOneFile did not produce integrated curve" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.curve = output.integratedCurve.path.value if not os.path.exists(self.curve): strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!" self.ERROR(strErr) self.lstExecutiveSummary.append(strErr) self.setFailure() return self.xsDataResult.integratedCurve = output.integratedCurve self.xsDataResult.normalizedImage = output.normalizedImage self.xsDataResult.dataI = output.dataI self.xsDataResult.dataQ = output.dataQ self.xsDataResult.dataStdErr = output.dataStdErr self.intensity = EDUtilsArray.xsDataToArray(output.dataI) self.stdError = EDUtilsArray.xsDataToArray(output.dataStdErr) if output.experimentSetup and output.experimentSetup.timeOfFrame: startTime = output.experimentSetup.timeOfFrame.value else: try: startTime = float(fabio.openheader(self.dataInput.rawImage.path.value).header["time_of_day"]) except Exception: self.ERROR("Unable to read time_of_day in header of %s" % self.dataInput.rawImage.path.value) startTime = 0 if not self.hplc_run.first_curve: with self._sem: if True: #not self.hplc_run.first_curve: # Populate the buffer with the first curve if needed self.hplc_run.first_curve = self.curve self.hplc_run.start_time = startTime self.hplc_run.q = EDUtilsArray.xsDataToArray(output.dataQ) self.hplc_run.size = self.hplc_run.q.size self.hplc_run.buffer_I = self.intensity self.hplc_run.buffer_Stdev = self.stdError self.hplc_run.firstCurveIntensity = self.intensity self.hplc_run.for_buffer_sum_I = self.intensity self.hplc_run.for_buffer_sum_sigma2 = self.stdError ** 2 self.hplc_run.for_buffer.append(self.frameId) self.frame.curve = self.curve self.frame.time = startTime self.xsDataResult.timeStamp = XSDataTime(value=(startTime - self.hplc_run.start_time)) # self.calcIntensity() self.frame.sum_I = float(self.intensity.sum()) self.xsDataResult.summedIntensity = XSDataDouble(value=self.frame.sum_I)
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 preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecMeasureOffsetv1_0.preProcess") sdi = self.dataInput images = sdi.image arrays = sdi.array if len(images) == 2: self.npaIm1 = numpy.array(EDUtilsArray.getArray(images[0])) self.npaIm2 = numpy.array(EDUtilsArray.getArray(images[1])) elif len(arrays) == 2: self.npaIm1 = EDUtilsArray.xsDataToArray(arrays[0]) self.npaIm2 = EDUtilsArray.xsDataToArray(arrays[1]) else: strError = "EDPluginExecMeasureOffsetv1_0.preProcess: You should either provide two images or two arrays, but I got: %s" % sdi.marshal( )[:1000] self.ERROR(strError) self.setFailure() raise RuntimeError(strError) crop = sdi.cropBorders if len(crop) > 1: self.tCrop = tuple([i.value for i in crop]) elif len(crop) == 1: self.tCrop = (crop[0].value, crop[0].value) center = sdi.center if len(center) > 1: self.tCenter = tuple([i.value for i in center]) elif len(center) == 1: self.tCenter = (center[0].value, center[0].value) width = sdi.width if len(width) > 1: self.tWidth = tuple([i.value for i in width]) elif len(width) == 1: self.tWidth = (width[0].value, width[0].value) smooth = sdi.smoothBorders if len(smooth) == 2: self.tSmooth = (smooth[0].value, smooth[1].value) elif len(smooth) == 1: self.tSmooth = (smooth[0].value, smooth[0].value) if sdi.backgroundSubtraction is not None: self.bBackgroundsubtraction = (sdi.backgroundSubtraction.value in [1, True, "true"]) if sdi.sobelFilter is not None: self.sobel = (sdi.sobelFilter in [1, True, "true"]) EDAssert.equal(self.npaIm1.shape, self.npaIm2.shape, "Images have the same size")
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecMeasureOffsetv1_0.preProcess") sdi = self.getDataInput() images = sdi.getImage() arrays = sdi.getArray() if len(images) == 2: self.npaIm1 = numpy.array(EDUtilsArray.getArray(images[0])) self.npaIm2 = numpy.array(EDUtilsArray.getArray(images[1])) elif len(arrays) == 2: self.npaIm1 = EDUtilsArray.xsDataToArray(arrays[0]) self.npaIm2 = EDUtilsArray.xsDataToArray(arrays[1]) else: strError = ( "EDPluginExecMeasureOffsetv1_0.preProcess: You should either provide two images or two arrays, but I got: %s" % sdi.marshal()[:1000] ) self.ERROR(strError) self.setFailure() raise RuntimeError(strError) crop = sdi.getCropBorders() if len(crop) > 1: self.tCrop = tuple([i.getValue() for i in crop]) elif len(crop) == 1: self.tCrop = (crop[0].getValue(), crop[0].getValue()) center = sdi.getCenter() if len(center) > 1: self.tCenter = tuple([i.getValue() for i in center]) elif len(center) == 1: self.tCenter = (center[0].getValue(), center[0].getValue()) width = sdi.getWidth() if len(width) > 1: self.tWidth = tuple([i.getValue() for i in width]) elif len(width) == 1: self.tWidth = (width[0].getValue(), width[0].getValue()) smooth = sdi.getSmoothBorders() if len(smooth) == 2: self.tSmooth = (smooth[0].getValue(), smooth[1].getValue()) elif len(smooth) == 1: self.tSmooth = (smooth[0].getValue(), smooth[0].getValue()) if sdi.getBackgroundSubtraction() is not None: self.bBackgroundsubtraction = sdi.getBackgroundSubtraction().getValue() in [1, True, "true"] if sdi.getSobelFilter() is not None: self.sobel = sdi.getSobelFilter() in [1, True, "true"] EDAssert.equal(self.npaIm1.shape, self.npaIm2.shape, "Images have the same size")
def unitTestXsdToArray(self): """ test the execution of xsDataToArray static method """ EDVerbose.DEBUG("EDTestCaseEDUtilsArray.unitTestXsdToArray") if numpy is not None: EDAssert.arraySimilar(self.arrayNumpy, EDUtilsArray.xsDataToArray(self.xsDataArrayNumpy, _bForceNoNumpy=False), _strComment="Array are the same (Numpy used)") else: EDAssert.equal(self.arrayNoNumpy, EDUtilsArray.xsDataToArray(self.xsDataArrayNumpy, _bCheckMd5sum=True, _bForceNoNumpy=False), "Array are the same (no Numpy available)")
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 preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.preProcess") sdi = self.getDataInput() for ofImage in sdi.getInputImages(): if (ofImage.file is not None) and os.path.isfile( ofImage.file.path.value): self._lImages.append(EDUtilsArray.getArray(ofImage.file)) elif (ofImage.array is not None): self._lImages.append(EDUtilsArray.xsDataToArray(ofImage.array)) else: strError = "EDPluginExecStitchOffsetedImagev1_0.preProcess: You need to provide either an image file either an array; I got: %s !!!" % ofImage.marshal( ) self.ERROR(strError) raise RuntimeError(strError) dummy = [0.0, 0.001] if ofImage.dummyValue is not None: dummy[0] = ofImage.dummyValue.value if ofImage.deltaDummy is not None: dummy[1] = ofImage.deltaDummy.value self._lDummies.append(tuple(dummy)) if ofImage.offset not in [list(), None]: offset = [i.value for i in ofImage.offset] else: offset = [0, 0] self._lOffsets.append(tuple(offset)) if sdi.blending is not None: self._strBlending = sdi.blending.value if sdi.dummyValue is not None: self._fDummy = sdi.dummyValue.value if sdi.outputImage is not None: self._strOutFile = sdi.outputImage.path.value if sdi.autoscale is not None: self._bAutoscale = bool(sdi.autoscale.value) if sdi.mask is not None: self._strMask = sdi.mask.path.value if not os.path.isfile(self._strMask): self._strMask = None center = sdi.centerROI if len(center) > 1: self.tCenter = tuple([i.value for i in center]) elif len(center) == 1: self.tCenter = (center[0].value, center[0].value) width = sdi.widthROI if len(width) > 1: self.tWidth = tuple([i.value for i in width]) elif len(width) == 1: self.tWidth = (width[0].value, width[0].value)
def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) self.DEBUG("EDPluginExecGnomv0_2.postProcess") # Create some output data self.parseGnomOutputFile() xsDataResult = XSDataResultGnom(radiusOfGyration=XSDataDouble(self.fRadiusOfGir), arrayErr=EDUtilsArray.arrayToXSData(self.npaPRerr), arrayPr=EDUtilsArray.arrayToXSData(self.npaPR), arrayR=EDUtilsArray.arrayToXSData(self.npaR), scatteringFitIArray=EDUtilsArray.arrayToXSData(self.npaFitDataI), scatteringFitQArray=EDUtilsArray.arrayToXSData(self.npaFitDataQ), output=XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), "gnom.out"))), fitQuality=XSDataDouble(self.fFitQuality)) self.dataOutput = xsDataResult
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecAlignFramev1_0.preProcess") sdi = self.dataInput images = sdi.image arrays = sdi.array if len(images) == 2: self.npaIm1 = numpy.array(EDUtilsArray.getArray(images[0])) self.npaIm2 = numpy.array(EDUtilsArray.getArray(images[1])) elif len(arrays) == 2: self.npaIm1 = EDUtilsArray.xsDataToArray(arrays[0]) self.npaIm2 = EDUtilsArray.xsDataToArray(arrays[1]) else: strError = "EDPluginExecAlignFramev1_0.preProcess: You should either provide two images or two arrays, but I got: %s" % sdi.marshal()[:1000] self.ERROR(strError) self.setFailure() raise RuntimeError(strError) crop = sdi.cropBorders if len(crop) > 1 : self.tCrop = tuple([ i.value for i in crop ]) elif len(crop) == 1: self.tCrop = (crop[0].value, crop[0].value) center = sdi.center if len(center) > 1: self.tCenter = tuple([ i.value for i in center ]) elif len(center) == 1: self.tCenter = (center[0].value, center[0].value) width = sdi.width if len(width) > 1 : self.tWidth = tuple([i.value for i in width]) elif len(width) == 1: self.tWidth = (width[0].value, width[0].value) smooth = sdi.smoothBorders if len(smooth) == 2: self.tSmooth = (smooth[0].value, smooth[1].value) elif len(smooth) == 1: self.tSmooth = (smooth[0].value, smooth[0].value) if sdi.backgroundSubtraction is not None: self.bBackgroundsubtraction = (sdi.backgroundSubtraction.value in [1, True, "true"]) if sdi.sobelFilter is not None: self.sobel = (sdi.sobelFilter in [1, True, "true"]) EDAssert.equal(self.npaIm1.shape , self.npaIm2.shape, "Images have the same size")
def process(self, _edObject=None): EDPluginExec.process(self) self.DEBUG("EDPluginExecReadDataBM23v1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") self.checkMandatoryParameters(self.dataInput.inputFile, "Data Input 'inputFile' is None") iSkipHeaderLines = 0 if self.dataInput.nSkipHeader: iSkipHeaderLines = self.dataInput.nSkipHeader.value # Load input data numpyDataArray = numpy.genfromtxt(self.dataInput.inputFile.path.value, skip_header=iSkipHeaderLines) # Create output data xsDataResultReadDataBM23 = XSDataResultReadDataBM23() xsDataResultReadDataBM23.energy = EDUtilsArray.arrayToXSData(numpyDataArray[:, 0]) xsDataResultReadDataBM23.dataArray = EDUtilsArray.arrayToXSData(numpyDataArray[:, 1:]) self.setDataOutput(xsDataResultReadDataBM23)
def preProcess(self, _edObject=None): EDPluginExecProcessScript.preProcess(self) self.DEBUG("EDPluginExecGnomv0_2.preProcess") if self.dataInput.angularScale is not None: self.fAngularScale = self.dataInput.angularScale.value dataInput = self.dataInput inputFile = None if len(dataInput.experimentalDataQ) > 0: self.npaExperimentalDataQ = numpy.array( [i.value for i in dataInput.experimentalDataQ]) elif dataInput.experimentalDataQArray is not None: self.npaExperimentalDataQ = EDUtilsArray.xsDataToArray( dataInput.experimentalDataQArray) elif dataInput.experimentalDataFile is not None: inputFile = dataInput.experimentalDataFile.path.value else: strErrorMessage = "EDPluginExecGnomv0_2: input parameter is missing: experimentalDataQ or experimentalDataQArray or experimentalDataFile" self.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage if len(dataInput.experimentalDataValues) > 0: self.npaExperimentalDataI = numpy.array( [i.value for i in dataInput.experimentalDataValues]) elif dataInput.experimentalDataIArray is not None: self.npaExperimentalDataI = EDUtilsArray.xsDataToArray( dataInput.experimentalDataIArray) elif dataInput.experimentalDataFile is not None: inputFile = dataInput.experimentalDataFile.path.value else: strErrorMessage = "EDPluginExecGnomv0_2: input parameter is missing: experimentalDataValues or experimentalDataIArray or experimentalDataFile" self.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage if len(dataInput.experimentalDataStdDev) > 0: self.npaExperimentalDataStdDev = numpy.array( [i.value for i in dataInput.experimentalDataStdDev]) elif dataInput.experimentalDataStdArray is not None: self.npaExperimentalDataStdDev = EDUtilsArray.getArray( dataInput.experimentalDataStdArray) if inputFile: self.loadDataFile(inputFile) self.generateGnomConfigFile() self.generateGnomScript()
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.preProcess") sdi = self.getDataInput() for ofImage in sdi.getInputImages(): if (ofImage.file is not None) and os.path.isfile(ofImage.file.path.value): self._lImages.append(EDUtilsArray.getArray(ofImage.file)) elif (ofImage.array is not None): self._lImages.append(EDUtilsArray.xsDataToArray(ofImage.array)) else: strError = "EDPluginExecStitchOffsetedImagev1_0.preProcess: You need to provide either an image file either an array; I got: %s !!!" % ofImage.marshal() self.ERROR(strError) raise RuntimeError(strError) dummy = [0.0, 0.001] if ofImage.dummyValue is not None: dummy[0] = ofImage.dummyValue.value if ofImage.deltaDummy is not None: dummy[1] = ofImage.deltaDummy.value self._lDummies.append(tuple(dummy)) if ofImage.offset not in [list(), None]: offset = [i.value for i in ofImage.offset ] else: offset = [0, 0] self._lOffsets.append(tuple(offset)) if sdi.blending is not None: self._strBlending = sdi.blending.value if sdi.dummyValue is not None: self._fDummy = sdi.dummyValue.value if sdi.outputImage is not None: self._strOutFile = sdi.outputImage.path.value if sdi.autoscale is not None: self._bAutoscale = bool(sdi.autoscale.value) if sdi.mask is not None: self._strMask = sdi.mask.path.value if not os.path.isfile(self._strMask): self._strMask = None center = sdi.centerROI if len(center) > 1: self.tCenter = tuple([ i.value for i in center ]) elif len(center) == 1: self.tCenter = (center[0].value, center[0].value) width = sdi.widthROI if len(width) > 1 : self.tWidth = tuple([i.value for i in width]) elif len(width) == 1: self.tWidth = (width[0].value, width[0].value)
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExportAsciiPowderv1_0.postProcess") # Create some output data xsDataResult = XSDataResult1DPowderEDF() if self.outputFilename is None: xsDataResult.setTwoTheta(EDUtilsArray.arrayToXSData(self.npaTwoTheta)) xsDataResult.setIntensity(EDUtilsArray.arrayToXSData(self.npaIntensities)) else: xsdFile = XSDataFile() xsdFile.setPath(XSDataString(self.outputFilename)) xsDataResult.setOutputFile(xsdFile) self.setDataOutput(xsDataResult) self.npaTwoTheta = None self.npaIntensities = None self.inputArray = None
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) EDVerbose.DEBUG("EDPluginExecMatrixWritev1_0.preProcess") self.outputFile = self.getDataInput().getOutputMatrixFile().getPath( ).getValue() self.xsdMatIn = self.getDataInput().getInputMatrix() self.matIn = EDUtilsArray.xsDataToArray(self.xsdMatIn)
def preProcess(self, _edObject=None): EDPluginExecProcessScript.preProcess(self) self.DEBUG("EDPluginExecJesfv1_0.preProcess") numpyData = EDUtilsArray.xsDataToArray(self.dataInput.data) numpy.savetxt(os.path.join(self.getWorkingDirectory(), "spectra.dat"), numpyData) self.addListCommandExecution("spectra.dat")
def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) self.DEBUG("EDPluginExecGnomv0_2.postProcess") # Create some output data self.parseGnomOutputFile() xsDataResult = XSDataResultGnom( radiusOfGyration=XSDataDouble(self.fRadiusOfGir), arrayErr=EDUtilsArray.arrayToXSData(self.npaPRerr), arrayPr=EDUtilsArray.arrayToXSData(self.npaPR), arrayR=EDUtilsArray.arrayToXSData(self.npaR), scatteringFitIArray=EDUtilsArray.arrayToXSData(self.npaFitDataI), scatteringFitQArray=EDUtilsArray.arrayToXSData(self.npaFitDataQ), output=XSDataFile( XSDataString( os.path.join(self.getWorkingDirectory(), "gnom.out"))), fitQuality=XSDataDouble(self.fFitQuality)) self.dataOutput = xsDataResult
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExecMatrixInvertv1_0.postProcess") # Create some output data xsDataResult = XSDataResultMatrixInvert() xsdMatOut = EDUtilsArray.arrayToXSData(self.matOut, _bIncludeMd5sum=False) xsDataResult.setOutputMatrix(xsdMatOut) self.setDataOutput(xsDataResult)
def unitTestXsdToArrayNoNumpy(self): """ test the execution of detectNumberOfCPUs """ EDVerbose.DEBUG("EDTestCaseEDUtilsArray.unitTestXsdToArrayNoNumpy") EDAssert.equal(self.arrayNoNumpy, EDUtilsArray.xsDataToArray(self.xsDataArrayNumpy, _bForceNoNumpy=True), "Array are the same (forced No Numpy)")
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlAlignStackv1_0.preProcess") sdi = self.dataInput self.xsdHDF5File = sdi.HDF5File self.xsdHDF5Internal = sdi.internalHDF5Path self.hdf5ExtraAttributes = sdi.extraAttributes if sdi.dontAlign is not None: self.bDoAlign = not (bool(sdi.dontAlign.value)) self.iFrames = [xsd.value for xsd in sdi.index] for idx, oneXSDFile in enumerate(sdi.images): self.npArrays.append(EDUtilsArray.getArray(oneXSDFile)) if len(self.iFrames) <= idx: if (oneXSDFile.number is not None): self.iFrames.append(oneXSDFile.number.value) elif oneXSDFile.path is not None: number = "" filename = oneXSDFile.path.value basename = os.path.splitext(filename)[0] for i in basename[-1:0:-1]: if i.isdigit(): number = i + number else: break self.iFrames.append(int(number)) if self.npArrays == []: strError = "EDPluginControlAlignStackv1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal( ) self.ERROR(strError) self.setFailure() self.xsdMeasureOffset = sdi.measureOffset if self.xsdMeasureOffset.alwaysVersusRef is not None: self.bAlwaysMOvsRef = bool( self.xsdMeasureOffset.alwaysVersusRef.value) with self.__class__.__semaphore: if (self.__class__.__iRefFrame is None): self.DEBUG("reference Frame is: %s" % sdi.frameReference.value) if sdi.getFrameReference() is not None: self.__class__.__iRefFrame = sdi.frameReference.value else: self.__class__.__iRefFrame = 0 if len(self.iFrames) == len(self.npArrays): for i, j in zip(self.iFrames, self.npArrays): self.addFrame(i, j) else: self.ERROR( "EDPluginControlAlignStackv1_0.preProcess: You should either provide an images with a frame number or precise it in the XML ! I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError
def testExecute(self): """ """ self.run() # plugin = self.getPlugin() strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile()) strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile) EDVerbose.DEBUG("Checking obtained result...") xsDataResultReference = XSDataResultNormalize.parseString(strExpectedOutput) xsDataResultObtained = XSDataResultNormalize.parseString(strObtainedOutput) #EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "Result XML are the same") npaReference = EDUtilsArray.xsDataToArray(xsDataResultReference.output.array) npaObtained = EDUtilsArray.xsDataToArray(xsDataResultObtained.output.array) EDAssert.arraySimilar(npaReference, npaObtained, "Arrays are the same", _fAbsMaxDelta=1e-6) EDAssert.equal(npaReference.dtype, npaObtained.dtype, "Datatypes are the same")
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExecMatrixReadv1_0.postProcess") # Create some output data xsDataResult = XSDataResultReadMatrix() xsdMatOut = EDUtilsArray.arrayToXSData(self.matOut, _bIncludeMd5sum=False) xsDataResult.setOutputMatrix(xsdMatOut) self.setDataOutput(xsDataResult)
def process(self, _edObject=None): EDPluginExec.process(self) self.DEBUG("EDPluginExecReadDataID24v1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") self.checkMandatoryParameters(self.dataInput.inputFile, "Data Input 'inputFile' is None") self.checkMandatoryParameters( self.dataInput.energyCalibration, "Data Input 'energyuCalibration' is None") self.checkMandatoryParameters( self.dataInput.energyCalibration.a, "Data Input 'energyCalibration a' is None") self.checkMandatoryParameters( self.dataInput.energyCalibration.b, "Data Input 'energyCalibration b' is None") # Load input data listNumpyArray = [] iNumberOfSPectra = 0 iNumberOfEnergies = 0 for xsDataFile in self.dataInput.inputFile: numpyDataArray = self.loadInputData(xsDataFile.path.value) # print numpyDataArray.shape listNumpyArray.append(numpyDataArray) iNumberOfEnergies = numpyDataArray.shape[0] iNumberOfSPectra += numpyDataArray.shape[1] numpyTotalDataArray = numpy.zeros( (iNumberOfEnergies, iNumberOfSPectra)) # print numpyTotalDataArray.shape iIndex = 0 for numpyDataArray in listNumpyArray: iSpectra = numpyDataArray.shape[1] numpyTotalDataArray[:, iIndex:iIndex + iSpectra] = numpyDataArray iIndex += iSpectra # Create energy calibration array numpyEnergyCalibrationArray = self.createEnergyCalibrationArray( numpyTotalDataArray.shape[0], self.dataInput.energyCalibration) # Create some output data xsDataResultReadDataID24 = XSDataResultReadDataID24() xsDataResultReadDataID24.energy = EDUtilsArray.arrayToXSData( numpyEnergyCalibrationArray) xsDataResultReadDataID24.dataArray = EDUtilsArray.arrayToXSData( numpyTotalDataArray) self.setDataOutput(xsDataResultReadDataID24)
def testCheckParameters(self): xsDataInputJesf = XSDataInputJesf() numpyData = numpy.genfromtxt(os.path.join(self.getPluginTestsDataHome(),"spectra.dat")) xsDataArray = EDUtilsArray.arrayToXSData(numpyData) xsDataInputJesf.setData(xsDataArray) #print xsDataInputJesf.marshal() xsDataInputJesf.exportToFile(os.path.join(self.getPluginTestsDataHome(),"XSDataInputJesfv1_0_reference.xml")) edPluginExecJesf = self.createPlugin() edPluginExecJesf.setDataInput(xsDataInputJesf) edPluginExecJesf.checkParameters()
def process(self, _edObject=None): EDPluginExec.process(self) self.DEBUG("EDPluginExecReadDataBM23v1_0.process") self.checkMandatoryParameters(self.dataInput, "Data Input is None") self.checkMandatoryParameters(self.dataInput.inputFile, "Data Input 'inputFile' is None") iSkipHeaderLines = 0 if self.dataInput.nSkipHeader: iSkipHeaderLines = self.dataInput.nSkipHeader.value # Load input data numpyDataArray = numpy.genfromtxt(self.dataInput.inputFile.path.value, skip_header=iSkipHeaderLines) # Create output data xsDataResultReadDataBM23 = XSDataResultReadDataBM23() xsDataResultReadDataBM23.energy = EDUtilsArray.arrayToXSData( numpyDataArray[:, 0]) xsDataResultReadDataBM23.dataArray = EDUtilsArray.arrayToXSData( numpyDataArray[:, 1:]) self.setDataOutput(xsDataResultReadDataBM23)
def createNexusGroup( self, _numpyDataArray, _groupTitle, _groupLongName, _numpyXAxisDataArray=None, _xAxisTitle=None, _xAxisLongName=None, _xAxisUnit=None, _numpyYAxisDataArray=None, _yAxisTitle=None, _yAxisLongName=None, _yAxisUnit=None, ): # Create entry for data arrays in nexus file xsDataNexusArrayGroup = XSDataNexusArrayGroup() xsDataNexusArrayGroup.title = XSDataString(_groupTitle) xsDataNexusArrayGroup.long_name = XSDataString(_groupLongName) xsDataNexusArrayGroup.data = EDUtilsArray.arrayToXSData( _numpyDataArray) xsDataNexusArrayGroup.signal = XSDataInteger(1) if _numpyXAxisDataArray is not None: xsDataNexusAxisX = XSDataNexusAxis() xsDataNexusAxisX.title = XSDataString(_xAxisTitle) xsDataNexusAxisX.long_name = XSDataString(_xAxisLongName) xsDataNexusAxisX.primary = XSDataInteger(1) xsDataNexusAxisX.axis = XSDataInteger(0) xsDataNexusAxisX.units = XSDataString(_xAxisUnit) xsDataNexusAxisX.axisData = EDUtilsArray.arrayToXSData( _numpyXAxisDataArray) xsDataNexusArrayGroup.addAxis(xsDataNexusAxisX) if _numpyYAxisDataArray is not None: xsDataNexusAxisY = XSDataNexusAxis() xsDataNexusAxisY.title = XSDataString(_yAxisTitle) xsDataNexusAxisY.long_name = XSDataString(_yAxisLongName) xsDataNexusAxisY.primary = XSDataInteger(2) xsDataNexusAxisY.axis = XSDataInteger(1) xsDataNexusAxisY.units = XSDataString(_yAxisUnit) xsDataNexusAxisY.axisData = EDUtilsArray.arrayToXSData( _numpyYAxisDataArray) xsDataNexusArrayGroup.addAxis(xsDataNexusAxisY) # print xsDataInputWriteNexusFile.marshal() return xsDataNexusArrayGroup
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginExecMeasureOffsetv2_0.preProcess") sdi = self.getDataInput() crop = sdi.getCropBorders() if len(crop) == 2: self.tCrop = (crop[0].getValue(), crop[1].getValue()) elif len(crop) == 1: self.tCrop = (crop[0].getValue(), crop[0].getValue()) # if len(sdi.getImage()) == 2: for i in sdi.getImage(): array = openimage(i.getPath().getValue()).data shape = array.shape if (self.tCrop != [0, 0]) and (shape[0] > self.tCrop[0]) and (shape[1] > self.tCrop[1]): array = array[self.tCrop[0]:-self.tCrop[0], self.tCrop[1]:-self.tCrop[1] ] EDVerbose.DEBUG("After Crop, images have shape : (%s,%s) " % (array.shape)) self.xsdImages.append(EDUtilsArray.arrayToXSData(array)) elif len(sdi.getArray()) == 2: if (self.tCrop == [0, 0]) : self.xsdImages = sdi.getArray() else: for xsdArray in sdi.getArray(): array = EDUtilsArray.xsDataToArray(xsdArray) shape = array.shape if (shape[0] > self.tCrop[0]) and (shape[1] > self.tCrop[1]): array = array[self.tCrop[0]:-self.tCrop[0], self.tCrop[1]:-self.tCrop[1] ] EDVerbose.DEBUG("After Crop, images have shape : (%s,%s) " % (array.shape)) self.xsdImages.append(EDUtilsArray.arrayToXSData(array)) else: strError = "EDPluginExecMeasureOffsetv2_0.preProcess: You should either provide two images or two arrays, but I got: %s" % sdi.marshal() EDVerbose.ERROR(strError) self.setFailure() raise RuntimeError(strError) EDVerbose.DEBUG("EDPluginExecMeasureOffsetv2_0.xsdImages len=%i %s" % (len(self.xsdImages), self.xsdImages)) EDAssert.equal(self.xsdImages[0].getShape() , self.xsdImages[1].getShape(), "Images have the same size") self.xsdIdx = sdi.getIndex() if len(self.xsdIdx) < len(self.xsdImages): self.xsdIdx = [XSDataInteger(i) for i in range(len(self.xsdImages))]
def preProcess(self, _edObject=None): EDPluginExecProcessScript.preProcess(self) self.DEBUG("EDPluginExecGnomv0_2.preProcess") if self.dataInput.angularScale is not None: self.fAngularScale = self.dataInput.angularScale.value dataInput = self.dataInput inputFile = None if len(dataInput.experimentalDataQ) > 0: self.npaExperimentalDataQ = numpy.array([i.value for i in dataInput.experimentalDataQ]) elif dataInput.experimentalDataQArray is not None: self.npaExperimentalDataQ = EDUtilsArray.xsDataToArray(dataInput.experimentalDataQArray) elif dataInput.experimentalDataFile is not None: inputFile = dataInput.experimentalDataFile.path.value else: strErrorMessage = "EDPluginExecGnomv0_2: input parameter is missing: experimentalDataQ or experimentalDataQArray or experimentalDataFile" self.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage if len(dataInput.experimentalDataValues) > 0: self.npaExperimentalDataI = numpy.array([i.value for i in dataInput.experimentalDataValues]) elif dataInput.experimentalDataIArray is not None: self.npaExperimentalDataI = EDUtilsArray.xsDataToArray(dataInput.experimentalDataIArray) elif dataInput.experimentalDataFile is not None: inputFile = dataInput.experimentalDataFile.path.value else: strErrorMessage = "EDPluginExecGnomv0_2: input parameter is missing: experimentalDataValues or experimentalDataIArray or experimentalDataFile" self.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage if len(dataInput.experimentalDataStdDev) > 0: self.npaExperimentalDataStdDev = numpy.array([i.value for i in dataInput.experimentalDataStdDev]) elif dataInput.experimentalDataStdArray is not None: self.npaExperimentalDataStdDev = EDUtilsArray.getArray(dataInput.experimentalDataStdArray) if inputFile: self.loadDataFile(inputFile) self.generateGnomConfigFile() self.generateGnomScript()
def prepareGleGraph(self, _xsDataPlot): strGraph = "" if _xsDataPlot.xsize != None and _xsDataPlot.ysize != None: strGraph += "size %f %f\n" % (_xsDataPlot.xsize, _xsDataPlot.ysize) strGraph += "begin graph\n" strGraph += ' title "%s"\n' % _xsDataPlot.title strGraph += ' xtitle "%s"\n' % _xsDataPlot.xtitle strGraph += ' ytitle "%s"\n' % _xsDataPlot.ytitle if _xsDataPlot.xmin != None or _xsDataPlot.xmax != None: strGraph += " xaxis " if _xsDataPlot.xmin != None: strGraph += "min %f " % _xsDataPlot.xmin if _xsDataPlot.xmax != None: strGraph += "max %f " % _xsDataPlot.xmax strGraph += "\n" if _xsDataPlot.ymin != None or _xsDataPlot.ymax != None: strGraph += " yaxis " if _xsDataPlot.ymin != None: strGraph += "min %f " % _xsDataPlot.ymin if _xsDataPlot.ymax != None: strGraph += "max %f " % _xsDataPlot.ymax strGraph += "\n" if _xsDataPlot.keypos is None: strGraph += " key pos tl hei 0.25\n" else: strGraph += " key pos %s hei 0.25\n" % _xsDataPlot.keypos iIndex = 1 listDataFiles = [] for xsDataGraph in _xsDataPlot.graph: strTmpDataPath = tempfile.mkstemp(prefix="data_", suffix=".dat", dir=self.getWorkingDirectory(), text=True)[ 1 ] numpyData = EDUtilsArray.xsDataToArray(xsDataGraph.data, _bForceNoNumpy=True) numpy.savetxt(strTmpDataPath, numpyData, delimiter=" ") listDataFiles.append(strTmpDataPath) # EDUtilsFile.writeFile(strTmpDataPath, strData) strGraph += " data %s\n" % strTmpDataPath strGraph += " d%d line " % iIndex if xsDataGraph.lineColor != None and xsDataGraph.lineColor != "None": strGraph += " color %s " % xsDataGraph.lineColor if xsDataGraph.lineStyle != None and xsDataGraph.lineStyle != "None": strGraph += " lstyle %s " % xsDataGraph.lineStyle if xsDataGraph.lineWidth != None: strGraph += " lwidth %f " % xsDataGraph.lineWidth if xsDataGraph.markerType != None and xsDataGraph.markerType != "None": strGraph += " marker %s " % xsDataGraph.markerType if xsDataGraph.markerColor != None and xsDataGraph.markerColor != "None": strGraph += " color %s " % xsDataGraph.markerColor if xsDataGraph.label != None and xsDataGraph.label != "None": strGraph += ' key "%s" ' % xsDataGraph.label strGraph += "\n" iIndex += 1 strGraph += "end graph\n" return (strGraph, listDataFiles)
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.postProcess") # Create some output data xsDataResult = XSDataResultStitchOffsetedImage() if self._strOutFile is not None: edf = edfimage(data=self._ndaResult, header={"Dummy":str(self._fDummy), "Blending":self._strBlending, "Autoscale":str(self._bAutoscale)}) edf.write(self._strOutFile) xsDataResult.setOutputImage(XSDataImageExt(path=XSDataString(self._strOutFile))) else: xsDataResult.setOutputArray(EDUtilsArray.arrayToXSData(self._ndaResult)) self.setDataOutput(xsDataResult)
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) EDVerbose.DEBUG("EDPluginExecShiftImagev1_0.preProcess") sdi = self.getDataInput() if sdi.inputImage is not None: self.npaImage = numpy.array(EDUtilsArray.getArray(sdi.inputImage)) elif sdi.getInputArray() is not None: self.npaImage = EDUtilsArray.xsDataToArray(sdi.getInputArray()) else: EDVerbose.ERROR("EDPluginExecShiftImagev1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError offset = sdi.getOffset() if len(offset) == 2: self.tOffset = (offset[0].getValue(), offset[1].getValue()) elif len(offset) == 1: self.tOffset = (offset[0].getValue(), offset[0].getValue()) if sdi.getOutputImage() is not None: self.strOutputImage = sdi.getOutputImage().getPath().getValue()
def prepareGleGraph(self, _xsDataPlot): strGraph = "" if _xsDataPlot.xsize != None and _xsDataPlot.ysize != None: strGraph += "size %f %f\n" % (_xsDataPlot.xsize, _xsDataPlot.ysize) strGraph += "begin graph\n" strGraph += " title \"%s\"\n" % _xsDataPlot.title strGraph += " xtitle \"%s\"\n" % _xsDataPlot.xtitle strGraph += " ytitle \"%s\"\n" % _xsDataPlot.ytitle if _xsDataPlot.xmin != None or _xsDataPlot.xmax != None: strGraph += " xaxis " if _xsDataPlot.xmin != None: strGraph += "min %f " % _xsDataPlot.xmin if _xsDataPlot.xmax != None: strGraph += "max %f " % _xsDataPlot.xmax strGraph += "\n" if _xsDataPlot.ymin != None or _xsDataPlot.ymax != None: strGraph += " yaxis " if _xsDataPlot.ymin != None: strGraph += "min %f " % _xsDataPlot.ymin if _xsDataPlot.ymax != None: strGraph += "max %f " % _xsDataPlot.ymax strGraph += "\n" if _xsDataPlot.keypos is None: strGraph += " key pos tl hei 0.25\n" else: strGraph += " key pos %s hei 0.25\n" % _xsDataPlot.keypos iIndex = 1 for xsDataGraph in _xsDataPlot.graph: strTmpDataPath = tempfile.mkstemp(prefix="data_", suffix=".dat", \ dir=self.getWorkingDirectory(), text=True)[1] numpyData = EDUtilsArray.xsDataToArray(xsDataGraph.data, _bForceNoNumpy=True) numpy.savetxt(strTmpDataPath, numpyData, delimiter=" ") #EDUtilsFile.writeFile(strTmpDataPath, strData) strGraph += " data %s\n" % strTmpDataPath strGraph += " d%d line " % iIndex if xsDataGraph.lineColor != None: strGraph += " color %s " % xsDataGraph.lineColor if xsDataGraph.lineStyle != None: strGraph += " lstyle %d " % xsDataGraph.lineStyle if xsDataGraph.lineWidth != None: strGraph += " lwidth %f " % xsDataGraph.lineWidth if xsDataGraph.markerType != None: strGraph += " marker %s " % xsDataGraph.markerType if xsDataGraph.markerColor != None: strGraph += " color %s " % xsDataGraph.markerColor if xsDataGraph.label != None: strGraph += " key \"%s\" " % xsDataGraph.label strGraph += "\n" iIndex += 1 strGraph += "end graph\n" return strGraph
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlAlignStackv1_0.preProcess") sdi = self.dataInput self.xsdHDF5File = sdi.HDF5File self.xsdHDF5Internal = sdi.internalHDF5Path self.hdf5ExtraAttributes = sdi.extraAttributes if sdi.dontAlign is not None: self.bDoAlign = not(bool(sdi.dontAlign.value)) self.iFrames = [ xsd.value for xsd in sdi.index] for idx, oneXSDFile in enumerate(sdi.images): self.npArrays.append(EDUtilsArray.getArray(oneXSDFile)) if len(self.iFrames) <= idx: if (oneXSDFile.number is not None): self.iFrames.append(oneXSDFile.number.value) elif oneXSDFile.path is not None : number = "" filename = oneXSDFile.path.value basename = os.path.splitext(filename)[0] for i in basename[-1:0:-1]: if i.isdigit(): number = i + number else: break self.iFrames.append(int(number)) if self.npArrays == []: strError = "EDPluginControlAlignStackv1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal() self.ERROR(strError) self.setFailure() self.xsdMeasureOffset = sdi.measureOffset if self.xsdMeasureOffset.alwaysVersusRef is not None: self.bAlwaysMOvsRef = bool(self.xsdMeasureOffset.alwaysVersusRef.value) with self.__class__.__semaphore: if (self.__class__.__iRefFrame is None): self.DEBUG("reference Frame is: %s" % sdi.frameReference.value) if sdi.getFrameReference() is not None: self.__class__.__iRefFrame = sdi.frameReference.value else: self.__class__.__iRefFrame = 0 if len(self.iFrames) == len(self.npArrays): for i, j in zip(self.iFrames, self.npArrays): self.addFrame(i, j) else: self.ERROR("EDPluginControlAlignStackv1_0.preProcess: You should either provide an images with a frame number or precise it in the XML ! I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsProcessOneFilev1_6.process") xsd = XSDataInputWaitFile(expectedFile=XSDataFile(XSDataString(self.rawImage)), expectedSize=self.rawImageSize, timeOut=XSDataTime(30)) self.__edPluginWaitFile.setDataInput(xsd) self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile) self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile) self.__edPluginWaitFile.executeSynchronous() if self.isFailure(): return self.xsDataResult.sample = self.sample self.xsDataResult.experimentSetup = self.experimentSetup res = self.integrate() self.write3ColumnAscii(res, self.integratedCurve) self.xsDataResult.dataQ = EDUtilsArray.arrayToXSData(res.radial) self.xsDataResult.dataI = EDUtilsArray.arrayToXSData(res.intensity) self.xsDataResult.dataStdErr = EDUtilsArray.arrayToXSData(res.sigma)
def testCheckParameters(self): xsDataInputJesf = XSDataInputJesf() numpyData = numpy.genfromtxt( os.path.join(self.getPluginTestsDataHome(), "spectra.dat")) xsDataArray = EDUtilsArray.arrayToXSData(numpyData) xsDataInputJesf.setData(xsDataArray) #print xsDataInputJesf.marshal() xsDataInputJesf.exportToFile( os.path.join(self.getPluginTestsDataHome(), "XSDataInputJesfv1_0_reference.xml")) edPluginExecJesf = self.createPlugin() edPluginExecJesf.setDataInput(xsDataInputJesf) edPluginExecJesf.checkParameters()
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) self.DEBUG("EDPluginExecPyFAIv1_0.postProcess") # Create some output data if self.strOutputFile: output = XSDataImageExt(path=XSDataString(self.strOutputFile)) elif self.shared: output = XSDataImageExt(shared=XSDataString(self.shared)) else: output = XSDataImageExt(array=EDUtilsArray.arrayToXSData(self.npaOut)) xsDataResult = XSDataResultPyFAI(output=output) self.setDataOutput(xsDataResult)
def postProcess(self, _edObject=None): EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExecMedianFilterv1_0.postProcess") # Create some output data xsDataResult = XSDataResultMedianFilter() if self.outputImage is None: xsDataResult.setOutputArray(EDUtilsArray.arrayToXSData(self.outputArray)) else: edf = fabio.edfimage.edfimage(data=self.outputArray.astype("float32")) edf.write(self.outputImage) xsDataResult.setOutputImage(XSDataImage(XSDataString(self.outputImage))) self.setDataOutput(xsDataResult) self.outputArray = None
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) EDVerbose.DEBUG("EDPluginExecShiftImagev1_0.preProcess") sdi = self.getDataInput() if sdi.inputImage is not None: self.npaImage = numpy.array(EDUtilsArray.getArray(sdi.inputImage)) elif sdi.getInputArray() is not None: self.npaImage = EDUtilsArray.xsDataToArray(sdi.getInputArray()) else: EDVerbose.ERROR( "EDPluginExecShiftImagev1_0.preProcess: You should either provide an images or an arrays, but I got: %s" % sdi.marshal()) self.setFailure() raise RuntimeError offset = sdi.getOffset() if len(offset) == 2: self.tOffset = (offset[0].getValue(), offset[1].getValue()) elif len(offset) == 1: self.tOffset = (offset[0].getValue(), offset[0].getValue()) if sdi.getOutputImage() is not None: self.strOutputImage = sdi.getOutputImage().getPath().getValue()