def testRasterConfiguration(self): strPathToTestConfigFile = os.path.join(self.strUnitTestDataHome, "XSConfiguration_raster.xml") edConfiguration = EDConfiguration(strPathToTestConfigFile) dictItem = edConfiguration.get(self.getPluginName()) xsDataMOSFLMInput = XSDataMOSFLMInput() xsDataMOSFLMBeam = XSDataMOSFLMBeamPosition() xsDataMOSFLMBeam.setX(XSDataLength(1.0)) xsDataMOSFLMBeam.setY(XSDataLength(2.0)) xsDataMOSFLMInput.setBeam(xsDataMOSFLMBeam) xsDataMOSFLMDetector = XSDataMOSFLMDetector() xsDataMOSFLMDetector.setType(XSDataString("ADSC")) xsDataMOSFLMInput.setDetector(xsDataMOSFLMDetector) xsDataMOSFLMInput.setDirectory(XSDataString("/tmp")) xsDataMOSFLMInput.setTemplate(XSDataString("testdata_1_###.img")) xsDataMOSFLMInput.setWavelength(XSDataWavelength(1.1111)) xsDataMOSFLMInput.setDistance(XSDataLength(222.22)) edPluginMOSFLMv10 = self.createPlugin() edPluginMOSFLMv10.setScriptExecutable("cat") edPluginMOSFLMv10.setConfig(dictItem, _bLocal=True) edPluginMOSFLMv10.configure() edPluginMOSFLMv10.setXSDataInputClass(XSDataMOSFLMInput) edPluginMOSFLMv10.setDataInput(xsDataMOSFLMInput) edPluginMOSFLMv10.generateMOSFLMCommands() edListCommands = edPluginMOSFLMv10.getListCommandExecution() edListCommandsReference = [ 'WAVELENGTH 1.1111', 'DISTANCE 222.22', 'BEAM 1.0 2.0', 'DETECTOR ADSC', 'DIRECTORY /tmp', 'TEMPLATE testdata_1_###.img', 'RASTER 15 15 3 3 3' ] EDAssert.equal(edListCommandsReference, edListCommands, "MOSFLM commands with ratser configured")
def testGenerateMOSFLMCommands(self): xsDataMOSFLMInput = XSDataMOSFLMInput() xsDataMOSFLMBeam = XSDataMOSFLMBeamPosition() xsDataMOSFLMBeam.setX(XSDataLength(1.0)) xsDataMOSFLMBeam.setY(XSDataLength(2.0)) xsDataMOSFLMInput.setBeam(xsDataMOSFLMBeam) xsDataMOSFLMDetector = XSDataMOSFLMDetector() xsDataMOSFLMDetector.setType(XSDataString("ADSC")) xsDataMOSFLMInput.setDetector(xsDataMOSFLMDetector) xsDataMOSFLMInput.setDirectory(XSDataString("/tmp")) xsDataMOSFLMInput.setTemplate(XSDataString("testdata_1_###.img")) xsDataMOSFLMInput.setWavelength(XSDataWavelength(1.1111)) xsDataMOSFLMInput.setDistance(XSDataLength(222.22)) edPluginMOSFLMv10 = self.createPlugin() edPluginMOSFLMv10.setScriptExecutable("cat") edPluginMOSFLMv10.configure() edPluginMOSFLMv10.setXSDataInputClass(XSDataMOSFLMInput) edPluginMOSFLMv10.setDataInput(xsDataMOSFLMInput) edPluginMOSFLMv10.generateMOSFLMCommands() edListCommands = edPluginMOSFLMv10.getListCommandExecution() edListCommandsReference = [ 'WAVELENGTH 1.1111', 'DISTANCE 222.22', 'BEAM 1.0 2.0', 'DETECTOR ADSC', 'DIRECTORY /tmp', 'TEMPLATE testdata_1_###.img' ] EDAssert.equal(edListCommandsReference, edListCommands, "MOSFLM commands") self.cleanUp(edPluginMOSFLMv10)
def generateDataMOSFLMInputGeneratePrediction(self): """ """ from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition() xsDataMOSFLMBeamPosition.setX(XSDataLength(102.5)) xsDataMOSFLMBeamPosition.setY(XSDataLength(104.7)) from XSDataMOSFLMv10 import XSDataMOSFLMDetector xsDataMOSFLMDetector = XSDataMOSFLMDetector() xsDataMOSFLMDetector.setType(XSDataString("ADSC")) from XSDataMOSFLMv10 import XSDataMOSFLMImage xsDataMOSFLMImage1 = XSDataMOSFLMImage() xsDataMOSFLMImage1.setNumber(XSDataInteger(1)) xsDataMOSFLMImage1.setRotationAxisStart(XSDataAngle(0.0)) xsDataMOSFLMImage1.setRotationAxisEnd(XSDataAngle(1.0)) from XSDataMOSFLMv10 import XSDataMOSFLMInputGeneratePrediction xsDataMOSFLMInputGeneratePrediction = XSDataMOSFLMInputGeneratePrediction( ) xsDataMOSFLMInputGeneratePrediction.setDistance(XSDataLength(198.4)) xsDataMOSFLMInputGeneratePrediction.setWavelength( XSDataWavelength(0.9340)) xsDataMOSFLMInputGeneratePrediction.setBeam(xsDataMOSFLMBeamPosition) xsDataMOSFLMInputGeneratePrediction.setDetector(xsDataMOSFLMDetector) xsDataMOSFLMInputGeneratePrediction.setDirectory( XSDataString(self.strDataImagePath)) xsDataMOSFLMInputGeneratePrediction.setTemplate( XSDataString("ref-testscale_1_###.img")) xsDataMOSFLMInputGeneratePrediction.setImage(xsDataMOSFLMImage1) return xsDataMOSFLMInputGeneratePrediction
def postProcess(self, _edObject=None): EDPluginControl.postProcess(self) EDVerbose.DEBUG("EDPluginBioSaxsMetadatav1_0.postProcess") # Create some output data xsDataResult = XSDataResultBioSaxsMetadatav1_0() if self.strOutputImage is not None: xsdImage = XSDataImage() xsdImage.setPath(XSDataString(self.strOutputImage)) xsDataResult.setOutputImage(xsdImage) if self.detector is not None: # EDVerbose.DEBUG("Detector=%s" % self.detector) xsDataResult.setDetector(XSDataString(self.detector)) if self.detectorDistance is not None: # EDVerbose.DEBUG("DetectorDistance %s(%s)" % (self.detectorDistance, self.detectorDistance.__class__)) xsDataResult.setDetectorDistance( XSDataLength(self.detectorDistance)) if self.pixelSize_1 is not None: # EDVerbose.DEBUG("pixelSize_1 %s(%s)" % (self.pixelSize_1, self.pixelSize_1.__class__)) xsDataResult.setPixelSize_1(XSDataLength(self.pixelSize_1)) if self.pixelSize_2 is not None: # EDVerbose.DEBUG("pixelSize_2 %s(%s)" % (self.pixelSize_2, self.pixelSize_2.__class__)) xsDataResult.setPixelSize_2(XSDataLength(self.pixelSize_2)) if self.beamCenter_1 is not None: # EDVerbose.DEBUG("beamCenter_1 %s(%s)" % (self.beamCenter_1, self.beamCenter_1.__class__)) xsDataResult.setBeamCenter_1(XSDataDouble(self.beamCenter_1)) if self.beamCenter_2 is not None: # EDVerbose.DEBUG("beamCenter_2 %s(%s)" % (self.beamCenter_2, self.beamCenter_2.__class__)) xsDataResult.setBeamCenter_2(XSDataDouble(self.beamCenter_2)) if self.beamStopDiode is not None: # EDVerbose.DEBUG("beamStopDiode %s(%s)" % (self.beamStopDiode, self.beamStopDiode.__class__)) xsDataResult.setBeamStopDiode(XSDataDouble(self.beamStopDiode)) if self.wavelength is not None: xsDataResult.setWavelength(XSDataWavelength(self.wavelength)) if self.maskFile is not None: xsdFile = XSDataImage() xsdFile.setPath(XSDataString(self.maskFile)) xsDataResult.setMaskFile(xsdFile) if self.normalizationFactor is not None: xsDataResult.setNormalizationFactor( XSDataDouble(self.normalizationFactor)) if self.machineCurrent is not None: xsDataResult.setMachineCurrent(XSDataDouble(self.machineCurrent)) if self.code is not None: xsDataResult.setCode(XSDataString(self.code)) if self.comments is not None: xsDataResult.setComments(XSDataString(self.comments)) if self.concentration is not None: xsDataResult.setConcentration(XSDataDouble(self.concentration)) EDVerbose.DEBUG("xsDataResult=%s" % xsDataResult.marshal()) self.setDataOutput(xsDataResult)
def __init__(self, code=None, comment=None, \ maskFile=None, normalization=None, imageSize=None, detector="pilatus", detectorDistance=None, pixelSize_1=None, pixelSize_2=None, beamCenter_1=None, beamCenter_2=None, wavelength=None,): EDLogging.__init__(self) self.comment = comment self.code = code self.maskFile = maskFile self.normalization = normalization self.detector = detector self.detectorDistance = detectorDistance if (detector == "pilatus") and (pixelSize_1 is None) and (pixelSize_2 is None): self.pixelSize_1 = 1.72e-4 self.pixelSize_2 = 1.72e-4 else: self.pixelSize_1 = pixelSize_1 self.pixelSize_2 = pixelSize_2 if (detector == "pilatus") and (beamCenter_1 is None): self.imageSize = 4000000 else: self.imageSize = imageSize self.beamCenter_1 = beamCenter_1 self.beamCenter_2 = beamCenter_2 self.wavelength = wavelength self.timeStamp = time.strftime("-%Y%m%d%H%M%S", time.localtime()) self.dest1D = "1d" + self.timeStamp self.dest2D = "2d" + self.timeStamp self.destMisc = "misc" + self.timeStamp self.sample = XSDataBioSaxsSample() if code is not None: self.sample.code = XSDataString(code) if comment is not None: self.sample.comment = XSDataString(comment) self.experimentSetup = XSDataBioSaxsExperimentSetup() if self.detector: self.experimentSetup.detector = XSDataString(self.detector) if self.detectorDistance: self.experimentSetup.detectorDistance = XSDataLength( self.detectorDistance) if self.pixelSize_1: self.experimentSetup.pixelSize_1 = XSDataLength(self.pixelSize_1) if self.pixelSize_2: self.experimentSetup.pixelSize_2 = XSDataLength(self.pixelSize_2) if self.beamCenter_1: self.experimentSetup.beamCenter_1 = XSDataDouble(self.beamCenter_1) if self.beamCenter_2: self.experimentSetup.beamCenter_2 = XSDataDouble(self.beamCenter_2) if self.wavelength: self.experimentSetup.wavelength = XSDataWavelength(self.wavelength)
def testSetDataModelInput(self): edPluginStrategy = self.createPlugin() strPathToTestConfigFile = os.path.join(self.getPluginTestsDataHome(), "XSConfiguration_ESRF.xml") edConfiguration = EDConfiguration(strPathToTestConfigFile) dictItem = edConfiguration.get(edPluginStrategy.getPluginName()) edPluginStrategy.setConfig(dictItem) edPluginStrategy.configure() xsDataStrategy = XSDataInputStrategy() # Beam xsExperimentalCondition = XSDataExperimentalCondition() xsBeam = XSDataBeam() xsBeam.setFlux(XSDataFlux(1e+12)) xsBeam.setWavelength(XSDataWavelength(2.41)) xsBeam.setSize(XSDataSize(x=XSDataLength(0.1), y=XSDataLength(0.1))) xsBeam.setExposureTime(XSDataTime(1)) xsExperimentalCondition.setBeam(xsBeam) # Detector and Exposure Time xsDataDetector = XSDataDetector() xsDataDetector.setType(XSDataString("q210-2x")) xsExperimentalCondition.setDetector(xsDataDetector) xsDataGoniostat = XSDataGoniostat() xsDataGoniostat.setRotationAxis(XSDataString("phi")) xsExperimentalCondition.setGoniostat(xsDataGoniostat) xsDataStrategy.setExperimentalCondition(xsExperimentalCondition) # Best Files bestFileContentDat = EDUtilsFile.readFile( os.path.join(self.strDataPath, "bestfile.dat")) xsDataStrategy.setBestFileContentDat(XSDataString(bestFileContentDat)) bestFileContentPar = EDUtilsFile.readFile( os.path.join(self.strDataPath, "bestfile.par")) xsDataStrategy.setBestFileContentPar(XSDataString(bestFileContentPar)) bestFileContentHKL = EDUtilsFile.readFile( os.path.join(self.strDataPath, "bestfile1.hkl")) xsDataStrategy.addBestFileContentHKL(XSDataString(bestFileContentHKL)) # Crystal xsDataSampleCrystalMM = XSDataSampleCrystalMM() xsDataStructure = XSDataStructure() xsDataComposition = XSDataChemicalCompositionMM() xsDataChain = XSDataChain() xsDataChain.setType(XSDataString("protein")) xsDataChain.setNumberOfCopies(XSDataDouble(2)) xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtom1 = XSDataAtom() xsDataAtom1.setSymbol(XSDataString("Se")) xsDataAtom1.setNumberOf(XSDataDouble(4)) xsDataAtomicComposition.addAtom(xsDataAtom1) xsDataChain.setHeavyAtoms(xsDataAtomicComposition) xsDataChain.setNumberOfMonomers(XSDataDouble(100)) xsDataStructure.addChain(xsDataChain) xsDataChain2 = XSDataChain() xsDataChain2.setType(XSDataString("rna")) xsDataChain2.setNumberOfCopies(XSDataDouble(1)) xsDataChain2.setNumberOfMonomers(XSDataDouble(60)) xsDataStructure.addChain(xsDataChain2) xsDataLigand = XSDataLigand() xsDataLigand.setNumberOfCopies(XSDataDouble(2)) xsDataLigand.setNumberOfLightAtoms(XSDataDouble(42)) xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtom2 = XSDataAtom() xsDataAtom2.setSymbol(XSDataString("Fe")) xsDataAtom2.setNumberOf(XSDataDouble(1)) xsDataAtomicComposition.addAtom(xsDataAtom2) xsDataLigand.setHeavyAtoms(xsDataAtomicComposition) xsDataStructure.addLigand(xsDataLigand) xsDataStructure.setNumberOfCopiesInAsymmetricUnit(XSDataDouble(0.25)) xsDataSolvent = XSDataSolvent() xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtom3 = XSDataAtom() xsDataAtom3.setSymbol(XSDataString("Na")) xsDataAtom3.setConcentration(XSDataDouble(1000)) xsDataAtom4 = XSDataAtom() xsDataAtom4.setSymbol(XSDataString("Cl")) xsDataAtom4.setConcentration(XSDataDouble(1000)) xsDataAtomicComposition.addAtom(xsDataAtom3) xsDataAtomicComposition.addAtom(xsDataAtom4) xsDataSolvent.setAtoms(xsDataAtomicComposition) xsDataComposition.setStructure(xsDataStructure) xsDataComposition.setSolvent(xsDataSolvent) xsDataSampleCrystalMM.setChemicalComposition(xsDataComposition) xsDataSampleCrystalMM.setSize( XSDataSize(XSDataLength(0.1), XSDataLength(0.1), XSDataLength(0.1))) xsDataCrystal = XSDataCrystal() xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0), angle_beta=XSDataAngle(90.0), angle_gamma=XSDataAngle(90.0), length_a=XSDataLength(78.9), length_b=XSDataLength(95.162), length_c=XSDataLength(104.087)) xsDataCrystal.setCell(xsDataCell) xsDataSpaceGroup = XSDataSpaceGroup() xsDataSpaceGroup.setITNumber(XSDataInteger(16)) xsDataCrystal.setSpaceGroup(xsDataSpaceGroup) xsDataSampleCrystalMM.setSusceptibility(XSDataDouble(1.5)) xsDataStrategy.setCrystalRefined(xsDataCrystal) xsDataStrategy.setSample(xsDataSampleCrystalMM) xsDataStrategy.exportToFile(self.strObtainedInputFile) pyStrExpectedInput = self.readAndParseFile(self.strReferenceInputFile) pyStrObtainedInput = self.readAndParseFile(self.strObtainedInputFile) xsDataInputExpected = XSDataInputStrategy.parseString( pyStrExpectedInput) xsDataInputObtained = XSDataInputStrategy.parseString( pyStrObtainedInput) EDAssert.equal(xsDataInputExpected.marshal(), xsDataInputObtained.marshal())
def postProcess(self, _edObject=None): """ complex type XSDataBioSaxsExperimentSetup extends XSData{ detector : XSDataString optional detectorDistance : XSDataLength optional pixelSize_1 : XSDataLength optional pixelSize_2 : XSDataLength optional beamCenter_1 : XSDataDouble optional beamCenter_2 : XSDataDouble optional beamStopDiode : XSDataDouble optional wavelength : XSDataWavelength optional machineCurrent : XSDataDouble optional maskFile : XSDataImage optional normalizationFactor : XSDataDouble optional storageTemperature: XSDataDouble optional exposureTemperature: XSDataDouble optional exposureTime: XSDataTime optional frameNumber: XSDataInteger optional frameMax: XSDataInteger optional } complex type XSDataBioSaxsSample extends XSData { concentration : XSDataDouble optional comments : XSDataString optional code : XSDataString optional temperature: XSDataDouble optional """ EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginBioSaxsMetadatav1_1.postProcess") # Create some output data xsDataResult = XSDataResultBioSaxsMetadatav1_0() xsdSample = XSDataBioSaxsSample() xsdExperiment = XSDataBioSaxsExperimentSetup() if self.strOutputImage is not None: xsdImage = XSDataImage() xsdImage.setPath(XSDataString(self.strOutputImage)) xsDataResult.setOutputImage(xsdImage) if self.detector is not None: xsdExperiment.detector = xsDataResult.detector = XSDataString( self.detector) if self.detectorDistance is not None: xsdExperiment.detectorDistance = xsDataResult.detectorDistance = XSDataLength( self.detectorDistance) if self.pixelSize_1 is not None: xsDataResult.pixelSize_1 = XSDataLength(self.pixelSize_1) xsdExperiment.pixelSize_1 = xsDataResult.pixelSize_1 if self.pixelSize_2 is not None: xsDataResult.pixelSize_2 = XSDataLength(self.pixelSize_2) xsdExperiment.pixelSize_2 = xsDataResult.pixelSize_2 if self.beamCenter_1 is not None: xsDataResult.beamCenter_1 = XSDataDouble(self.beamCenter_1) xsdExperiment.beamCenter_1 = xsDataResult.beamCenter_1 if self.beamCenter_2 is not None: xsDataResult.beamCenter_2 = XSDataDouble(self.beamCenter_2) xsdExperiment.beamCenter_2 = xsDataResult.beamCenter_2 if self.beamStopDiode is not None: xsdExperiment.beamStopDiode = xsDataResult.beamStopDiode = XSDataDouble( self.beamStopDiode) if self.wavelength is not None: xsdExperiment.wavelength = xsDataResult.wavelength = XSDataWavelength( self.wavelength) if self.maskFile is not None: xsdFile = XSDataImage() xsdFile.setPath(XSDataString(self.maskFile)) xsdExperiment.maskFile = xsDataResult.maskFile = xsdFile if self.normalizationFactor is not None: xsdExperiment.normalizationFactor = xsDataResult.normalizationFactor = XSDataDouble( self.normalizationFactor) if self.machineCurrent is not None: xsdExperiment.machineCurrent = xsDataResult.machineCurrent = XSDataDouble( self.machineCurrent) if self.storageTemperature is not None: xsdExperiment.storageTemperature = xsDataResult.storageTemperature = XSDataDouble( self.storageTemperature) if self.exposureTemperature is not None: xsdExperiment.exposureTemperature = xsDataResult.exposureTemperature = XSDataDouble( self.exposureTemperature) if self.exposureTime is not None: xsdExperiment.exposureTime = xsDataResult.exposureTime = XSDataTime( self.exposureTime) if self.frameNumber is not None: xsdExperiment.frameNumber = xsDataResult.frameNumber = XSDataInteger( self.frameNumber) if self.frameMax is not None: xsdExperiment.frameMax = xsDataResult.frameMax = XSDataInteger( self.frameMax) if self.timeOfFrame is not None: xsdExperiment.timeOfFrame = xsDataResult.timeOfFrame = XSDataTime( self.timeOfFrame) if self.code is not None: xsdSample.code = xsDataResult.code = XSDataString(self.code) if self.comments is not None: xsdSample.comments = xsDataResult.comments = XSDataString( self.comments) if self.concentration is not None: xsdSample.concentration = xsDataResult.concentration = XSDataDouble( self.concentration) xsDataResult.sample = xsdSample xsDataResult.experimentSetup = xsdExperiment self.setDataOutput(xsDataResult)
def process(self, _edObject=None): EDPluginExec.process(self) self.DEBUG("EDPluginExecReadImageHeaderEiger4Mv10.process") xsDataInputReadImageHeader = self.getDataInput() xsDataFile = xsDataInputReadImageHeader.getImage() strPath = xsDataFile.getPath().getValue() dictEiger4MHeader = self.readHeaderEiger4M(strPath) if (dictEiger4MHeader is None): strErrorMessage = "EDPluginExecReadImageHeaderEiger4Mv10.process : Cannot read header : %s" % strPath self.error(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: xsDataExperimentalCondition = XSDataExperimentalCondition() xsDataDetector = XSDataDetector() iNoPixelsX = 2070 iNoPixelsY = 2167 xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX)) xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY)) # Pixel size listPixelSizeXY = dictEiger4MHeader[ "Pixel_size" ].split(" ") fPixelSizeX = float(listPixelSizeXY[0]) * 1000 xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX)) fPixelSizeY = float(listPixelSizeXY[3]) * 1000 xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY)) # Beam position listBeamPosition = dictEiger4MHeader["Beam_xy"].replace("(", " ").replace(")", " ").replace(",", " ").split() fBeamPositionX = float(listBeamPosition[1]) * fPixelSizeX fBeamPositionY = float(listBeamPosition[0]) * fPixelSizeY xsDataDetector.setBeamPositionX(XSDataLength(fBeamPositionX)) xsDataDetector.setBeamPositionY(XSDataLength(fBeamPositionY)) fDistance = float(dictEiger4MHeader[ "Detector_distance" ].split(" ")[0]) * 1000 xsDataDetector.setDistance(XSDataLength(fDistance)) # xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictEiger4MHeader[ "header_size" ]))) xsDataDetector.setSerialNumber(XSDataString(dictEiger4MHeader[ "Detector:" ])) # #xsDataDetector.setBin( XSDataString( dictEiger4MHeader[ "BIN" ] ) ) ) # #xsDataDetector.setDataType( XSDataString( dictEiger4MHeader[ "TYPE" ] ) ) ) # #xsDataDetector.setByteOrder( XSDataString( dictEiger4MHeader[ "BYTE_ORDER" ] ) ) ) # xsDataDetector.setImageSaturation(XSDataInteger(int(dictEiger4MHeader[ "saturation_level" ]))) xsDataDetector.setName(XSDataString("EIGER 4M")) xsDataDetector.setType(XSDataString("eiger4m")) xsDataExperimentalCondition.setDetector(xsDataDetector) # Beam object xsDataBeam = XSDataBeam() xsDataBeam.setWavelength(XSDataWavelength(float(dictEiger4MHeader[ "Wavelength" ].split(" ")[0]))) xsDataBeam.setExposureTime(XSDataTime(float(dictEiger4MHeader[ "Exposure_time" ].split(" ")[0]))) xsDataExperimentalCondition.setBeam(xsDataBeam) # Goniostat object xsDataGoniostat = XSDataGoniostat() fRotationAxisStart = float(dictEiger4MHeader[ "Start_angle" ].split(" ")[0]) fOscillationWidth = float(dictEiger4MHeader[ "Angle_increment" ].split(" ")[0]) xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart)) xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth)) xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth)) xsDataExperimentalCondition.setGoniostat(xsDataGoniostat) # # Create the image object xsDataImage = XSDataImage() xsDataImage.setPath(XSDataString(strPath)) if "DateTime" in dictEiger4MHeader: strTimeStamp = dictEiger4MHeader[ "DateTime" ] xsDataImage.setDate(XSDataString(strTimeStamp)) iImageNumber = EDUtilsImage.getImageNumber(strPath) xsDataImage.setNumber(XSDataInteger(iImageNumber)) xsDataSubWedge = XSDataSubWedge() xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition) xsDataSubWedge.addImage(xsDataImage) self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader() self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)
def setup(self, _listInput=[], _mode="offline"): """Configure the various options""" bOK = False if _listInput == []: _listInput = [os.getcwd()] while not bOK: strtmp = raw_input( "What are the input directories (mandatory, space separated) %s: " % _listInput).strip() if len(strtmp) > 0: bAllExists = True lstTemp = shlex.split(strtmp) for oneDir in shlex.split(strtmp): if not os.path.exists(oneDir): EDVerbose.screen("No such file or directory: %s" % oneDir) bAllExists = False if bAllExists is True: self.listInput = lstTemp bOK = True else: self.listInput = _listInput bOK = True bOK = False while not bOK: strtmp = raw_input( "What is operation mode [offline|online|all] (mandatory: %s): " % _mode).strip().lower() if len(strtmp) > 0: bOK = True if strtmp == "offline": self.bNewerOnly = False self.strMode = "OffLine" elif strtmp == "online": self.bNewerOnly = True self.strMode = "dirwatch" elif strtmp == "all": self.bNewerOnly = False self.strMode = "dirwatch" else: bOK = False bOK = False while not bOK: strtmp = raw_input( "What is the destination directory (mandatory): ").strip() if os.path.isdir(strtmp): self.destinationDirectory = XSDataFile() self.destinationDirectory.setPath( XSDataString(os.path.abspath(strtmp))) bOK = True bOK = False while not bOK: strtmp = raw_input( "What is the sinogram filename prefix (mandatory): ").strip() if strtmp != "": self.sinogramFileNamePrefix = XSDataString(strtmp) bOK = True bOK = False while not bOK: strtmp = raw_input( "What is the powder diffraction subdirectory (mandatory): " ).strip() if strtmp != "": self.powderDiffractionSubdirectory = XSDataString(strtmp) bOK = True strtmp = raw_input( "What is the powder diffraction output format (CHI or CIF, if any ): " ).strip().lower() if strtmp.find("cif") >= 0: self.powderDiffractionFormat = XSDataString("cif") elif strtmp.find("chi") >= 0: self.powderDiffractionFormat = XSDataString("chi") strtmp = raw_input("Process all files ending with: ").strip() if len(strtmp) > 0: for oneExt in shlex.split(strtmp): self.listExtensions.append(oneExt) strtmp = raw_input("Exclude all files starting with: ").strip() if len(strtmp) > 0: for oneExt in shlex.split(strtmp): self.listExcludedPrefix.append(oneExt) strtmp = raw_input( "Do you want to over-ride metadata from the headers [y|N]: " ).strip().lower() if len(strtmp) > 0 and strtmp[0] == "y": strtmp = raw_input("What is the flat field image: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() flatFieldImage = XSDataFile() flatFieldImage.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_image_flat_field( flatFieldImage) strtmp = raw_input("What is the dark current image: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() darkCurrentImage = XSDataFile() darkCurrentImage.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_image_dark_current( darkCurrentImage) strtmp = raw_input("What is the mask file: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() maskFile = XSDataFile() maskFile.setPath(XSDataString(strtmp)) self.forceImage.set_file_correction_image_mask(maskFile) strtmp = raw_input("What is the spline file: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() splineFile = XSDataFile() splineFile.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_spline_spatial_distortion( splineFile) strtmp = raw_input( "What is the wavelength (like 0.7 A): ").replace( "(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: try: f = float(w[0]) except ValueError: print("unable to understand what you said, skipping") else: wavelength = XSDataWavelength() wavelength.setValue(f) if len(w) == 2: wavelength.setUnit(XSDataString(w[1])) if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_diffrn_radiation_wavelength( wavelength) strtmp = raw_input( "What is the distance between the sample and the detector along the beam: " ).replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: try: f = float(w[0]) except ValueError: print("unable to understand what you said, skipping") else: distance = XSDataLength() distance.setValue(f) if len(w) == 2: distance.setUnit(XSDataString(w[1])) if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_pd_instr_dist_spec_detc(distance) strtmp = raw_input( "What is the pixel size (like 52.8 um 53.2 um): ").replace( "(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: xsdata1 = None xsdata2 = None if len(w) == 4: try: f1 = float(w[0]) f2 = float(w[2]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata1.setUnit(XSDataString(w[1])) xsdata2 = XSDataLength() xsdata2.setValue(f2) xsdata2.setUnit(XSDataString(w[3])) elif len(w) == 2: try: f1 = float(w[0]) f2 = float(w[1]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata2 = XSDataLength() xsdata2.setValue(f2) else: print("unable to understand what you said, skipping") if (xsdata1 is not None) and (xsdata2 is not None): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_array_element_size_1(xsdata1) self.forceImage.set_array_element_size_2(xsdata2) strtmp = raw_input( "What is the beam center in distance, not pixels (like 53.5 mm 48.2 mm): " ).strip().replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: xsdata1 = None xsdata2 = None if len(w) == 4: try: f1 = float(w[0]) f2 = float(w[2]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata1.setUnit(XSDataString(w[1])) xsdata2 = XSDataLength() xsdata2.setValue(f2) xsdata2.setUnit(XSDataString(w[3])) elif len(w) == 2: try: f1 = float(w[0]) f2 = float(w[1]) except ValueError, IndexError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata2 = XSDataLength() xsdata2.setValue(f2) else: print("unable to understand what you said, skipping") if (xsdata1 is not None) and (xsdata2 is not None): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_diffrn_detector_element_center_1( xsdata1) self.forceImage.set_diffrn_detector_element_center_2( xsdata2) strtmp = raw_input("What is the detector tilt angle: ").strip() tiltAngle = None try: tiltAngle = XSDataAngle(float(strtmp)) except ValueError: print("unable to understand what you said, skipping") else: if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_pd_instr_special_details_tilt_angle( tiltAngle) strtmp = raw_input("What is the tilt plan rotation: ").strip() tiltRotation = None try: tiltRotation = XSDataAngle(float(strtmp)) except ValueError: print("unable to understand what you said, skipping") else: if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_pd_instr_special_details_tilt_rotation( tiltRotation) strtmp = raw_input( "What is the number of fast motor steps (you will have n+1 points): " ).strip() try: self.fastMotorSteps = int(strtmp) except ValueError: fastMotorSteps = None else: if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_tomo_spec_displ_x_max( XSDataLength(self.fastMotorSteps)) self.forceInstrument.set_tomo_spec_displ_x_min(XSDataLength(0)) self.forceInstrument.set_tomo_spec_displ_x_inc(XSDataLength(1)) self.forceInstrument.set_tomo_scan_type(XSDataString("flat")) strtmp = raw_input( "What is the number of slow motor steps (you will have n+1 points): " ).strip() try: self.slowMotorSteps = int(strtmp) except ValueError: self.slowMotorSteps = None else: if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_tomo_scan_ampl( XSDataLength(self.slowMotorSteps)) self.forceInstrument.set_tomo_spec_displ_rotation_inc( XSDataLength(1)) self.forceInstrument.set_tomo_scan_type(XSDataString("flat")) strtmp = raw_input( "What is the index offset of your images: ").strip() try: self.indexOffset = int(strtmp) except ValueError: print("unable to understand what you said, skipping")
def testSetDataModelInput(self): # Crystal from XSDataRaddosev10 import XSDataRaddoseInput xsDataRaddoseInput = XSDataRaddoseInput() from XSDataCommon import XSDataString from XSDataCommon import XSDataDouble from XSDataCommon import XSDataAngle from XSDataCommon import XSDataLength from XSDataCommon import XSDataSize from XSDataCommon import XSDataInteger from XSDataRaddosev10 import XSDataCell from XSDataRaddosev10 import XSDataAtom from XSDataRaddosev10 import XSDataAtomicComposition xsDataAtomSulfur = XSDataAtom() xsDataAtomSulfur.setNumberOf(XSDataDouble(4)) xsDataAtomSulfur.setSymbol(XSDataString("S")) xsDataAtomSelenium = XSDataAtom() xsDataAtomSelenium.setNumberOf(XSDataDouble(4)) xsDataAtomSelenium.setSymbol(XSDataString("Se")) xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtomicComposition.addAtom(xsDataAtomSulfur) xsDataAtomicComposition.addAtom(xsDataAtomSelenium) xsDataRaddoseInput.setCrystalPATM(xsDataAtomicComposition) xsDataRaddoseInput.setCrystalNRES(XSDataInteger(295)) xsDataRaddoseInput.setCrystalNMON(XSDataInteger(8)) xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0), angle_beta=XSDataAngle(90.0), angle_gamma=XSDataAngle(90.0), length_a=XSDataLength(78.9), length_b=XSDataLength(95.162), length_c=XSDataLength(104.087)) xsDataSizeCrystal = XSDataSize(XSDataLength(0.1), XSDataLength(0.1), XSDataLength(0.1)) xsDataRaddoseInput.setCrystalCell(xsDataCell) xsDataRaddoseInput.setCrystalSize(xsDataSizeCrystal) # Beam from XSDataCommon import XSDataFlux from XSDataCommon import XSDataWavelength from XSDataCommon import XSDataTime xsDataSize = XSDataSize(x=XSDataLength(0.1), y=XSDataLength(0.1)) xsDataRaddoseInput.setBeamSize(xsDataSize) xsDataRaddoseInput.setBeamFlux(XSDataFlux(1e+12)) xsDataRaddoseInput.setBeamWavelength(XSDataWavelength(2.41)) xsDataRaddoseInput.setBeamExposureTime(XSDataTime(1)) xsDataRaddoseInput.setNumberOfImages(XSDataInteger(1)) xsDataRaddoseInput.exportToFile(self.strObtainedInputFile) strExpectedInput = self.readAndParseFile(self.strReferenceInputFile) strObtainedInput = self.readAndParseFile(self.strObtainedInputFile) xsDataRaddoseInputExpected = XSDataRaddoseInput.parseString( strExpectedInput) xsDataRaddoseInputObtained = XSDataRaddoseInput.parseString( strObtainedInput) EDAssert.equal(xsDataRaddoseInputExpected.marshal(), xsDataRaddoseInputObtained.marshal())
def setup(self, _listInput=[], _mode="offline"): """Configure the various options""" bOK = False if _listInput == []: _listInput = [os.getcwd()] while not bOK: strtmp = raw_input("What are the input directories (mandatory, space separated) %s: " % _listInput).strip() if len(strtmp) > 0: bAllExists = True lstTemp = shlex.split(strtmp) for oneDir in shlex.split(strtmp): if not os.path.exists(oneDir): EDVerbose.screen("No such file or directory: %s" % oneDir) bAllExists = False if bAllExists is True: self.listInput = lstTemp bOK = True else: self.listInput = _listInput bOK = True bOK = False while not bOK: strtmp = raw_input("What is operation mode [offline|online|all] (mandatory: %s): " % _mode).strip().lower() if len(strtmp) > 0: bOK = True if strtmp == "offline": self.bNewerOnly = False self.strMode = "OffLine" elif strtmp == "online": self.bNewerOnly = True self.strMode = "dirwatch" elif strtmp == "all": self.bNewerOnly = False self.strMode = "dirwatch" else: bOK = False bOK = False while not bOK: strtmp = raw_input("What is the destination directory (mandatory): ").strip() if os.path.isdir(strtmp): self.destinationDirectory = XSDataFile() self.destinationDirectory.setPath(XSDataString(os.path.abspath(strtmp))) bOK = True bOK = False while not bOK: strtmp = raw_input("What is the sinogram filename prefix (mandatory): ").strip() if strtmp != "": self.sinogramFileNamePrefix = XSDataString(strtmp) bOK = True bOK = False while not bOK: strtmp = raw_input("What is the powder diffraction subdirectory (mandatory): ").strip() if strtmp != "": self.powderDiffractionSubdirectory = XSDataString(strtmp) bOK = True strtmp = raw_input("What is the powder diffraction output format (CHI or CIF, if any ): ").strip().lower() if strtmp.find("cif") >= 0: self.powderDiffractionFormat = XSDataString("cif") elif strtmp.find("chi") >= 0: self.powderDiffractionFormat = XSDataString("chi") strtmp = raw_input("Process all files ending with: ").strip() if len(strtmp) > 0: for oneExt in shlex.split(strtmp): self.listExtensions.append(oneExt) strtmp = raw_input("Exclude all files starting with: ").strip() if len(strtmp) > 0: for oneExt in shlex.split(strtmp): self.listExcludedPrefix.append(oneExt) strtmp = raw_input("Do you want to over-ride metadata from the headers [y|N]: ").strip().lower() if len(strtmp) > 0 and strtmp[0] == "y": strtmp = raw_input("What is the flat field image: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() flatFieldImage = XSDataFile() flatFieldImage.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_image_flat_field(flatFieldImage) strtmp = raw_input("What is the dark current image: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() darkCurrentImage = XSDataFile() darkCurrentImage.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_image_dark_current(darkCurrentImage) strtmp = raw_input("What is the mask file: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() maskFile = XSDataFile() maskFile.setPath(XSDataString(strtmp)) self.forceImage.set_file_correction_image_mask(maskFile) strtmp = raw_input("What is the spline file: ").strip() if os.path.isfile(strtmp): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() splineFile = XSDataFile() splineFile.setPath(XSDataString(os.path.abspath(strtmp))) self.forceImage.set_file_correction_spline_spatial_distortion(splineFile) strtmp = raw_input("What is the wavelength (like 0.7 A): ").replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: try: f = float(w[0]) except ValueError: print("unable to understand what you said, skipping") else: wavelength = XSDataWavelength() wavelength.setValue(f) if len(w) == 2: wavelength.setUnit(XSDataString(w[1])) if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_diffrn_radiation_wavelength(wavelength) strtmp = raw_input("What is the distance between the sample and the detector along the beam: ").replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: try: f = float(w[0]) except ValueError: print("unable to understand what you said, skipping") else: distance = XSDataLength() distance.setValue(f) if len(w) == 2: distance.setUnit(XSDataString(w[1])) if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_pd_instr_dist_spec_detc(distance) strtmp = raw_input("What is the pixel size (like 52.8 um 53.2 um): ").replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: xsdata1 = None xsdata2 = None if len(w) == 4: try: f1 = float(w[0]) f2 = float(w[2]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata1.setUnit(XSDataString(w[1])) xsdata2 = XSDataLength() xsdata2.setValue(f2) xsdata2.setUnit(XSDataString(w[3])) elif len(w) == 2: try: f1 = float(w[0]) f2 = float(w[1]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata2 = XSDataLength() xsdata2.setValue(f2) else: print("unable to understand what you said, skipping") if (xsdata1 is not None) and (xsdata2 is not None): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_array_element_size_1(xsdata1) self.forceImage.set_array_element_size_2(xsdata2) strtmp = raw_input("What is the beam center in distance, not pixels (like 53.5 mm 48.2 mm): ").strip().replace("(", "").replace(")", "").strip() w = strtmp.split() if len(w) > 0: xsdata1 = None xsdata2 = None if len(w) == 4: try: f1 = float(w[0]) f2 = float(w[2]) except ValueError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata1.setUnit(XSDataString(w[1])) xsdata2 = XSDataLength() xsdata2.setValue(f2) xsdata2.setUnit(XSDataString(w[3])) elif len(w) == 2: try: f1 = float(w[0]) f2 = float(w[1]) except ValueError, IndexError: print "Unable to convert to float !!! skipping" else: xsdata1 = XSDataLength() xsdata1.setValue(f1) xsdata2 = XSDataLength() xsdata2.setValue(f2) else: print("unable to understand what you said, skipping") if (xsdata1 is not None) and (xsdata2 is not None): if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_diffrn_detector_element_center_1(xsdata1) self.forceImage.set_diffrn_detector_element_center_2(xsdata2) strtmp = raw_input("What is the detector tilt angle: ").strip() tiltAngle = None try: tiltAngle = XSDataAngle(float(strtmp)) except ValueError: print("unable to understand what you said, skipping") else: if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_pd_instr_special_details_tilt_angle(tiltAngle) strtmp = raw_input("What is the tilt plan rotation: ").strip() tiltRotation = None try: tiltRotation = XSDataAngle(float(strtmp)) except ValueError: print("unable to understand what you said, skipping") else: if self.forceImage is None: self.forceImage = XSDataDiffractionCTImage() self.forceImage.set_pd_instr_special_details_tilt_rotation(tiltRotation) strtmp = raw_input("What is the number of fast motor steps (you will have n+1 points): ").strip() try: self.fastMotorSteps = int(strtmp) except ValueError: fastMotorSteps = None else: if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_tomo_spec_displ_x_max(XSDataLength(self.fastMotorSteps)) self.forceInstrument.set_tomo_spec_displ_x_min(XSDataLength(0)) self.forceInstrument.set_tomo_spec_displ_x_inc(XSDataLength(1)) self.forceInstrument.set_tomo_scan_type(XSDataString("flat")) strtmp = raw_input("What is the number of slow motor steps (you will have n+1 points): ").strip() try: self.slowMotorSteps = int(strtmp) except ValueError: self.slowMotorSteps = None else: if self.forceInstrument is None: self.forceInstrument = XSDataDiffractionCTInstrument() self.forceInstrument.set_tomo_scan_ampl(XSDataLength(self.slowMotorSteps)) self.forceInstrument.set_tomo_spec_displ_rotation_inc(XSDataLength(1)) self.forceInstrument.set_tomo_scan_type(XSDataString("flat")) strtmp = raw_input("What is the index offset of your images: ").strip() try: self.indexOffset = int(strtmp) except ValueError: print("unable to understand what you said, skipping")
def toXml(self, filename): """Here we create the XML string to be passed to the EDNA plugin from the input filename This can / should be modified by the final user @param filename: full path of the input file @type filename: python string representing the path @rtype: XML string @return: python string """ # Is the file to process? dirname, basename = os.path.split(filename) rootDir, dirname = os.path.split(dirname) basename, ext = os.path.splitext(basename) if not ((dirname.lower() == "raw") and (ext.lower() == ".edf")): self.DEBUG("Not processing %s" % filename) return existing2DImage = os .path.join(rootDir, "2d", basename + ".edf") if os.path.isfile(existing2DImage): # print existing2DImage title = None for line in open(existing2DImage): if len(line) > 512: break else: line = line.strip() if line.startswith("title"): title = line.split("=", 1)[-1] if line.startswith("Center_1")and (self.beamCenter_1 is None): try: self.experimentSetup.beamCenter_1 = XSDataDouble(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) elif line.startswith("Center_2")and (self.beamCenter_2 is None): try: self.experimentSetup.beamCenter_2 = XSDataDouble(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) elif line.startswith("PSize_1")and (self.pixelSize_1 is None): try: self.experimentSetup.pixelSize_1 = XSDataLength(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) elif line.startswith("PSize_2") and (self.pixelSize_2 is None): try: self.experimentSetup.pixelSize_2 = XSDataLength(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) elif line.startswith("SampleDistance") and (self.detectorDistance is None) : try: self.experimentSetup.detectorDistance = XSDataLength(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) elif line.startswith("WaveLength")and (self.wavelength is None): try: self.experimentSetup.wavelength = XSDataWavelength(float(line.split("=", 1)[-1].split()[0])) except Exception: self.ERROR("Reading from header: not a float " + line) if title: for block in title.split(","): if "=" in block: key, value = block.split("=", 1) elif ":" in block: key, value = block.split(":", 1) else: key = None if key: key = key.strip() value = value.strip() # print key, value if key == "DiodeCurr": try: self.experimentSetup.beamStopDiode = XSDataDouble(float(value)) except Exception: self.ERROR("Unable to convert %s to float" % block) elif key == "MachCurr": try: self.experimentSetup.machineCurrent = XSDataDouble(float(value.split()[0])) except Exception: self.ERROR("Unable to convert %s to float" % block) elif key == "Concentration": try: self.sample.concentration = XSDataDouble(float(value.split()[0])) except Exception: self.ERROR("Unable to convert %s to float" % block) elif (key == "Comments") and (self.comment is None): self.sample.comments = XSDataString(value.strip()) elif (key == "Code") and (self.code is None) : self.sample.code = XSDataString(value.strip()) elif (key == "Mask") and (self.maskFile is None): self.experimentSetup.maskFile = XSDataImage(XSDataString(value.strip())) elif (key == "Normalisation") and (self.normalization is None): try: self.experimentSetup.normalizationFactor = XSDataDouble(float(value.split()[0])) except Exception: self.ERROR("Unable to convert %s to float" % block) xsd = XSDataInputBioSaxsProcessOneFilev1_0() xsd.rawImage = XSDataImage(XSDataString(filename)) xsd.rawImageSize = XSDataInteger(self.imageSize) xsd.experimentSetup = self.experimentSetup xsd.sample = self.sample dir1d = os.path.join(rootDir, self.dest1D) dir2d = os.path.join(rootDir, self.dest2D) dirMisc = os.path.join(rootDir, self.destMisc) if not os.path.exists(dir1d): os.makedirs(dir1d) if not os.path.exists(dir2d): os.makedirs(dir2d) if not os.path.exists(dirMisc): os.makedirs(dirMisc) xsd.normalizedImage = XSDataImage(XSDataString(os.path.join(dir2d, basename + ".edf"))) xsd.integratedImage = XSDataImage(XSDataString(os.path.join(dirMisc, basename + ".ang"))) xsd.integratedCurve = XSDataFile(XSDataString(os.path.join(dir1d, basename + ".dat"))) # print xsd.marshal() return xsd.marshal()
def generateXSDataInputXDS(_xsDataCollection): xsDataCollection = _xsDataCollection xsDataExperimentalCondition = _xsDataCollection.getSubWedge( )[0].getExperimentalCondition() xsDataSubWedgeList = xsDataCollection.getSubWedge() xsDataInputXDS = XSDataInputXDSGenerateBackgroundImage() xsDataBeam = xsDataExperimentalCondition.getBeam() xsDataDetector = xsDataExperimentalCondition.getDetector() xsDataGoniostat = xsDataExperimentalCondition.getGoniostat() dWavelength = xsDataBeam.getWavelength().getValue() dDistance = xsDataDetector.getDistance().getValue() dBeamPositionX = xsDataDetector.getBeamPositionX().getValue() dBeamPositionY = xsDataDetector.getBeamPositionY().getValue() # Start with the detector xsDataXDSDetector = EDHandlerXSDataXDSv1_0.getXSDataXDSDetector( xsDataDetector) xsDataInputXDS.setDetector(xsDataXDSDetector) # Then the beam xsDataXDSBeam = XSDataXDSBeam() xsDataVectorDoubleIncidentBeam = XSDataVectorDouble() xsDataVectorDoubleIncidentBeam.setV1(0.0) xsDataVectorDoubleIncidentBeam.setV2(0.0) xsDataVectorDoubleIncidentBeam.setV3(1.0) xsDataXDSBeam.setIncident_beam_direction( xsDataVectorDoubleIncidentBeam) xsDataVectorDoublePolarizationPlaneNormal = XSDataVectorDouble() xsDataVectorDoublePolarizationPlaneNormal.setV1(0.0) xsDataVectorDoublePolarizationPlaneNormal.setV2(1.0) xsDataVectorDoublePolarizationPlaneNormal.setV3(0.0) xsDataXDSBeam.setPolarization_plane_normal( xsDataVectorDoublePolarizationPlaneNormal) xsDataXDSBeam.setX_ray_wavelength(XSDataWavelength(dWavelength)) xsDataInputXDS.setBeam(xsDataXDSBeam) # Then the goniostat xsDataXDSGoniostat = XSDataXDSGoniostat() xsDataVectorDoubleRotationAxis = XSDataVectorDouble() xsDataVectorDoubleRotationAxis.setV1(1.0) xsDataVectorDoubleRotationAxis.setV2(0.0) xsDataVectorDoubleRotationAxis.setV3(0.0) xsDataXDSGoniostat.setRotation_axis(xsDataVectorDoubleRotationAxis) xsDataXDSGoniostat.setOscillation_range( xsDataGoniostat.getOscillationWidth()) xsDataXDSGoniostat.setStarting_angle( xsDataGoniostat.getRotationAxisStart()) xsDataInputXDS.setGoniostat(xsDataXDSGoniostat) # # Then the Crystal # # xsDataXDSCrystal = XSDataXDSCrystal() # # xsDataXDSCrystal.setFriedels_law(XSDataString("FALSE")) # ## if ( xsDataCrystal is not None ): ## xsDataSpaceGroup = xsDataCrystal.getSpaceGroup() ## if ( xsDataSpaceGroup is not None ): ## xsDataStringName = xsDataSpaceGroup.getName() ## if ( xsDataStringName is not None ): ## xsDataInputXDS.setSymmetry( XSDataString( xsDataStringName.getValue() ) ) # xsDataXDSCrystal.setSpace_group_number(XSDataInteger(0)) # # xsDataXDSCrystal.setStrong_pixel(XSDataInteger(8)) # # xsDataCell = XSDataCell() # xsDataCell.setLength_a(XSDataLength(0.0)) # xsDataCell.setLength_b(XSDataLength(0.0)) # xsDataCell.setLength_c(XSDataLength(0.0)) # xsDataCell.setAngle_alpha(XSDataAngle(0.0)) # xsDataCell.setAngle_beta(XSDataAngle(0.0)) # xsDataCell.setAngle_gamma(XSDataAngle(0.0)) # xsDataXDSCrystal.setUnit_cell_constants(xsDataCell) # # xsDataInputXDS.setCrystal(xsDataXDSCrystal) # Finaly the images xsDataXDSImage = XSDataXDSImage() xsDataSubWedgeFirst = xsDataSubWedgeList[0] xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0] pyStrPath = xsDataImageFirst.getPath().getValue() pyStrFileName = EDUtilsFile.getBaseName(pyStrPath) pyStrDirectory = EDUtilsPath.getFolderName(pyStrPath) pyStrPrefix = EDUtilsImage.getPrefix(pyStrFileName) pyStrSuffix = EDUtilsImage.getSuffix(pyStrFileName) pyStrXDSTemplate = "%s_xdslink_?????.%s" % (pyStrPrefix, pyStrSuffix) xsDataXDSImage.setName_template_of_data_frames( XSDataString(pyStrXDSTemplate)) iXDSLowestImageNumberGlobal = 1 xsDataXDSImage.setStarting_frame( XSDataInteger(iXDSLowestImageNumberGlobal)) # First we have to find the smallest goniostat rotation axis start: fGonioStatOscillationStartMin = None for xsDataSubWedge in xsDataSubWedgeList: xsDataGoniostat = xsDataSubWedge.getExperimentalCondition( ).getGoniostat() fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart( ).getValue() if (fGonioStatOscillationStartMin is None): fGonioStatOscillationStartMin = fGonioStatOscillationStart elif (fGonioStatOscillationStartMin > fGonioStatOscillationStart): fGonioStatOscillationStartMin = fGonioStatOscillationStart # Loop through the list of sub wedges for xsDataSubWedge in xsDataSubWedgeList: xsDataImageList = xsDataSubWedge.getImage() xsDataGoniostat = xsDataSubWedge.getExperimentalCondition( ).getGoniostat() fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart( ).getValue() fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth( ).getValue() # First find the lowest and highest image numbers iLowestImageNumber = None for xsDataImage in xsDataImageList: iImageNumber = xsDataImage.getNumber().getValue() if (iLowestImageNumber is None): iLowestImageNumber = iImageNumber elif (iImageNumber < iLowestImageNumber): iLowestImageNumber = iImageNumber # Loop through the list of images iLowestXDSImageNumber = None iHighestXDSImageNumber = None for xsDataImage in xsDataImageList: iImageNumber = xsDataImage.getNumber().getValue() fImageOscillationStart = fGonioStatOscillationStart + ( iImageNumber - iLowestImageNumber) * fGonioStatOscillationRange iXDSImageNumber = iXDSLowestImageNumberGlobal + int( (fImageOscillationStart - fGonioStatOscillationStartMin) / fGonioStatOscillationRange) #print iXDSImageNumber, fImageOscillationStart, fGonioStatOscillationStartMin, fGonioStatOscillationRange pyStrSourcePath = xsDataImage.getPath() pyStrTarget = "%s_xdslink_%05d.%s" % ( pyStrPrefix, iXDSImageNumber, pyStrSuffix) xsDataXDSImageLink = XSDataXDSImageLink() xsDataFileSource = XSDataFile() xsDataFileSource.setPath(pyStrSourcePath) xsDataXDSImageLink.setSource(xsDataFileSource) xsDataXDSImageLink.setTarget(XSDataString(pyStrTarget)) xsDataInputXDS.addImage_link(xsDataXDSImageLink) if (iLowestXDSImageNumber is None): iLowestXDSImageNumber = iXDSImageNumber elif (iLowestXDSImageNumber > iXDSImageNumber): iLowestXDSImageNumber = iXDSImageNumber if (iHighestXDSImageNumber is None): iHighestXDSImageNumber = iXDSImageNumber elif (iHighestXDSImageNumber < iXDSImageNumber): iHighestXDSImageNumber = iXDSImageNumber xsDataXDSIntegerRange = XSDataXDSIntegerRange() xsDataXDSIntegerRange.setLower( XSDataInteger(iLowestXDSImageNumber)) xsDataXDSIntegerRange.setUpper( XSDataInteger(iHighestXDSImageNumber)) xsDataXDSImage.addBackground_range(xsDataXDSIntegerRange) xsDataXDSImage.addData_range(xsDataXDSIntegerRange) xsDataXDSImage.addSpot_range(xsDataXDSIntegerRange) xsDataInputXDS.setImage(xsDataXDSImage) return xsDataInputXDS
def testGetXSDataRaddoseInput(self): """ """ from XSDataCommon import XSDataLength from XSDataCommon import XSDataWavelength from XSDataCommon import XSDataFlux from XSDataCommon import XSDataSize from XSDataCommon import XSDataDouble from XSDataCommon import XSDataString from XSDataCommon import XSDataAngle from XSDataCommon import XSDataTime from XSDataCommon import XSDataInteger from XSDataMXv1 import XSDataBeam from XSDataMXv1 import XSDataStructure from XSDataMXv1 import XSDataChain from XSDataMXv1 import XSDataAtom from XSDataMXv1 import XSDataLigand from XSDataMXv1 import XSDataCrystal from XSDataMXv1 import XSDataSpaceGroup from XSDataMXv1 import XSDataSampleCrystalMM from XSDataMXv1 import XSDataChemicalCompositionMM from XSDataMXv1 import XSDataAtomicComposition from XSDataMXv1 import XSDataSolvent from XSDataMXv1 import XSDataCell from EDHandlerXSDataRaddosev10 import EDHandlerXSDataRaddosev10 EDFactoryPluginStatic.loadModule("XSDataRaddosev10") from XSDataRaddosev10 import XSDataRaddoseInput xsDataBeam = XSDataBeam() xsDataBeam.setSize(XSDataSize(x=XSDataLength(0.1), y=XSDataLength(0.1))) xsDataBeam.setWavelength(XSDataWavelength(2.41)) xsDataBeam.setFlux(XSDataFlux(1e+12)) xsDataBeam.setExposureTime(XSDataTime(0.037)) xsDataSample = XSDataSampleCrystalMM() xsDataStructure = XSDataStructure() xsDataComposition = XSDataChemicalCompositionMM() xsDataChain = XSDataChain() xsDataChain.setType(XSDataString("protein")) xsDataChain.setNumberOfCopies(XSDataDouble(2)) xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtom1 = XSDataAtom() xsDataAtom1.setSymbol(XSDataString("Se")) xsDataAtom1.setNumberOf(XSDataDouble(4)) xsDataAtomicComposition.addAtom(xsDataAtom1) xsDataAtom2 = XSDataAtom() xsDataAtom2.setSymbol(XSDataString("S")) xsDataAtom2.setNumberOf(XSDataDouble(5)) xsDataAtomicComposition.addAtom(xsDataAtom2) xsDataChain.setHeavyAtoms(xsDataAtomicComposition) xsDataChain.setNumberOfMonomers(XSDataDouble(100)) xsDataStructure.addChain(xsDataChain) xsDataChain2 = XSDataChain() xsDataChain2.setType(XSDataString("rna")) xsDataChain2.setNumberOfCopies(XSDataDouble(1)) xsDataChain2.setNumberOfMonomers(XSDataDouble(60)) xsDataStructure.addChain(xsDataChain2) xsDataLigand = XSDataLigand() xsDataLigand.setNumberOfCopies(XSDataDouble(2)) xsDataLigand.setNumberOfLightAtoms(XSDataDouble(42)) xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtom3 = XSDataAtom() xsDataAtom3.setSymbol(XSDataString("Fe")) xsDataAtom3.setNumberOf(XSDataDouble(1)) xsDataAtomicComposition.addAtom(xsDataAtom3) xsDataLigand.setHeavyAtoms(xsDataAtomicComposition) xsDataStructure.addLigand(xsDataLigand) xsDataStructure.setNumberOfCopiesInAsymmetricUnit(XSDataDouble(0.25)) xsDataSolvent = XSDataSolvent() xsDataAtomicComposition = XSDataAtomicComposition() xsDataAtomNa = XSDataAtom() xsDataAtomNa.setSymbol(XSDataString("Na")) xsDataAtomNa.setConcentration(XSDataDouble(1000)) xsDataAtomicComposition.addAtom(xsDataAtomNa) xsDataAtomCl = XSDataAtom() xsDataAtomCl.setSymbol(XSDataString("Cl")) xsDataAtomCl.setConcentration(XSDataDouble(1000)) xsDataAtomicComposition.addAtom(xsDataAtomCl) xsDataSolvent.setAtoms(xsDataAtomicComposition) xsDataComposition.setStructure(xsDataStructure) xsDataComposition.setSolvent(xsDataSolvent) xsDataSample.setChemicalComposition(xsDataComposition) xsDataSample.setSize( XSDataSize(XSDataLength(0.1), XSDataLength(0.1), XSDataLength(0.1))) xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0), angle_beta=XSDataAngle(90.0), angle_gamma=XSDataAngle(90.0), length_a=XSDataLength(78.9), length_b=XSDataLength(95.162), length_c=XSDataLength(104.087)) xsDataCrystal = XSDataCrystal() xsDataSpaceGroup = XSDataSpaceGroup() xsDataCrystal.setCell(xsDataCell) xsDataSpaceGroup.setITNumber(XSDataInteger(16)) xsDataCrystal.setSpaceGroup(xsDataSpaceGroup) xsDataSample.setCrystal(xsDataCrystal) iNumSymOperators = 4 iNumberOfImages = 2 xsDataRaddosev01Input = EDHandlerXSDataRaddosev10( ).getXSDataRaddoseInput(xsDataBeam, xsDataSample, iNumSymOperators, iNumberOfImages) xsDataRaddosev01Input.exportToFile(self.strObtainedInputFile2) strExpectedInput = EDUtilsTest.readAndParseFile( self.strReferenceInputFile2) strObtainedInput = EDUtilsTest.readAndParseFile( self.strObtainedInputFile2) xsDataInputExpected = XSDataRaddoseInput.parseString(strExpectedInput) xsDataInputObtained = XSDataRaddoseInput.parseString(strObtainedInput) EDAssert.equal(xsDataInputExpected.marshal(), xsDataInputObtained.marshal())
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamExposureTime': obj_ = XSDataTime() obj_.build(child_) self.setBeamExposureTime(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamFlux': obj_ = XSDataFlux() obj_.build(child_) self.setBeamFlux(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamSize': obj_ = XSDataSize() obj_.build(child_) self.setBeamSize(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamWavelength': obj_ = XSDataWavelength() obj_.build(child_) self.setBeamWavelength(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalCell': obj_ = XSDataCell() obj_.build(child_) self.setCrystalCell(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalNDNA': obj_ = XSDataInteger() obj_.build(child_) self.setCrystalNDNA(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalNMON': obj_ = XSDataInteger() obj_.build(child_) self.setCrystalNMON(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalNRES': obj_ = XSDataInteger() obj_.build(child_) self.setCrystalNRES(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalNRNA': obj_ = XSDataInteger() obj_.build(child_) self.setCrystalNRNA(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalPATM': obj_ = XSDataAtomicComposition() obj_.build(child_) self.setCrystalPATM(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalSATM': obj_ = XSDataAtomicComposition() obj_.build(child_) self.setCrystalSATM(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'crystalSize': obj_ = XSDataSize() obj_.build(child_) self.setCrystalSize(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'numberOfImages': obj_ = XSDataInteger() obj_.build(child_) self.setNumberOfImages(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def generateXSDataMOSFLMInputIndexing(_xsDataIndexingInput): """ Translation from XSDataIndexingInput to XSDataMOSFLMInputIndexing. """ EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10") from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition from XSDataMOSFLMv10 import XSDataMOSFLMImage EDVerbose.DEBUG( "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing") xsDataCollection = _xsDataIndexingInput.getDataCollection() xsDataExperimentalCondition = _xsDataIndexingInput.getExperimentalCondition( ) xsDataCrystal = _xsDataIndexingInput.getCrystal() xsDataSubWedgeList = xsDataCollection.getSubWedge() xsDataMOSFLMInputIndexing = XSDataMOSFLMInputIndexing() if (xsDataExperimentalCondition is None): xsDataExperimentalCondition = xsDataSubWedgeList[ 0].getExperimentalCondition() xsDataBeam = xsDataExperimentalCondition.getBeam() xsDataDetector = xsDataExperimentalCondition.getDetector() xsDataGoniostat = xsDataExperimentalCondition.getGoniostat() dWavelength = xsDataBeam.getWavelength().getValue() dDistance = xsDataDetector.getDistance().getValue() dBeamPositionX = xsDataDetector.getBeamPositionX().getValue() dBeamPositionY = xsDataDetector.getBeamPositionY().getValue() xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition() xsDataMOSFLMBeamPosition.setX(XSDataLength(dBeamPositionX)) xsDataMOSFLMBeamPosition.setY(XSDataLength(dBeamPositionY)) xsDataMOSFLMInputIndexing.setBeam(xsDataMOSFLMBeamPosition) xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector( xsDataDetector) xsDataMOSFLMInputIndexing.setDetector(xsDataMOSFLMDetector) xsDataMOSFLMInputIndexing.setWavelength(XSDataWavelength(dWavelength)) xsDataMOSFLMInputIndexing.setDistance(XSDataLength(dDistance)) xsDataSubWedgeFirst = xsDataSubWedgeList[0] xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0] strPath = xsDataImageFirst.getPath().getValue() strFileName = os.path.basename(strPath) strDirectory = os.path.dirname(strPath) if xsDataDetector.type.value == "eiger2_16m": strMOSFLMTemplate = EDUtilsImage.getH5MasterTemplate( strFileName, 1) else: strMOSFLMTemplate = EDUtilsImage.getTemplate(strFileName, "#") xsDataMOSFLMInputIndexing.setTemplate(XSDataString(strMOSFLMTemplate)) xsDataMOSFLMInputIndexing.setDirectory(XSDataString(strDirectory)) if (xsDataCrystal is not None): xsDataSpaceGroup = xsDataCrystal.getSpaceGroup() if (xsDataSpaceGroup is not None): xsDataStringName = xsDataSpaceGroup.getName() if (xsDataStringName is not None): xsDataMOSFLMInputIndexing.setSymmetry( XSDataString(xsDataStringName.getValue())) # Loop through the list of sub wedges for xsDataSubWedge in xsDataSubWedgeList: xsDataImageList = xsDataSubWedge.getImage() xsDataGoniostat = xsDataSubWedge.getExperimentalCondition( ).getGoniostat() fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart( ).getValue() fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth( ).getValue() # First find the lowest image number iLowestImageNumber = None for xsDataImage in xsDataImageList: iImageNumber = xsDataImage.getNumber().getValue() if (iLowestImageNumber is None): iLowestImageNumber = iImageNumber elif (iImageNumber < iLowestImageNumber): iLowestImageNumber = iImageNumber # Loop through the list of images for xsDataImage in xsDataImageList: # Create the MOSFLM image object xsDataMOSFLMImage = XSDataMOSFLMImage() iImageNumber = xsDataImage.getNumber().getValue() xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber)) fImageOscillationStart = fGonioStatOscillationStart + ( iImageNumber - iLowestImageNumber) * fGonioStatOscillationRange xsDataMOSFLMImage.setRotationAxisStart( XSDataAngle(fImageOscillationStart)) xsDataMOSFLMImage.setRotationAxisEnd( XSDataAngle(fImageOscillationStart + fGonioStatOscillationRange)) xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage) return xsDataMOSFLMInputIndexing
def createInputCharacterisationFromSubWedges(self): self.DEBUG( "EDPluginControlInterfacev1_3.createInputCharacterisationFromSubWedges" ) xsDataResultSubWedgeAssemble = self.edPluginControlSubWedgeAssemble.getDataOutput( ) self.xsDataInputCharacterisation = XSDataInputCharacterisation() xsDataCollection = XSDataCollection() # Default exposure time (for the moment, this value should be # possible to read from the command line) if self.xsDataDiffractionPlan is None: self.xsDataDiffractionPlan = XSDataDiffractionPlan() if (not xsDataResultSubWedgeAssemble is None): pyListSubWedge = xsDataResultSubWedgeAssemble.getSubWedge() xsDataCollection.setSubWedge(pyListSubWedge) for xsDataSubWedge in pyListSubWedge: if (self.strComplexity is not None): self.xsDataDiffractionPlan.setComplexity( XSDataString(self.strComplexity)) if (self.fFlux is not None): xsDataSubWedge.getExperimentalCondition().getBeam( ).setFlux(XSDataFlux(self.fFlux)) if (self.fBeamSizeX is not None) and (self.fBeamSizeY is not None): xsDataSize = XSDataSize() xsDataSize.setX(XSDataLength(self.fBeamSizeX)) xsDataSize.setY(XSDataLength(self.fBeamSizeY)) xsDataSubWedge.getExperimentalCondition().getBeam( ).setSize(xsDataSize) if (self.fApertureSize is not None): xsDataSubWedge.getExperimentalCondition().getBeam( ).setApertureSize(XSDataLength(self.fApertureSize)) if (self.fBeamPosX is not None): xsDataSubWedge.getExperimentalCondition().getDetector( ).setBeamPositionX(XSDataLength(self.fBeamPosX)) if (self.fBeamPosY is not None): xsDataSubWedge.getExperimentalCondition().getDetector( ).setBeamPositionY(XSDataLength(self.fBeamPosY)) if (self.fMinExposureTimePerImage is not None): xsDataSubWedge.getExperimentalCondition().getBeam( ).setMinExposureTimePerImage( XSDataTime(self.fMinExposureTimePerImage)) if (self.fTransmission is not None): xsDataSubWedge.getExperimentalCondition().getBeam( ).setTransmission(XSDataDouble(self.fTransmission)) if (self.fWavelength is not None): xsDataSubWedge.getExperimentalCondition().getBeam( ).setWavelength(XSDataWavelength(self.fWavelength)) if self.fMinOscillationWidth != None: xsDataSubWedge.getExperimentalCondition().getGoniostat( ).setMinOscillationWidth( XSDataAngle(self.fMinOscillationWidth)) if self.fMaxOscillationSpeed != None: xsDataSubWedge.getExperimentalCondition().getGoniostat( ).setMaxOscillationSpeed( XSDataAngularSpeed(self.fMaxOscillationSpeed)) if (self.strForcedSpaceGroup is not None): self.xsDataDiffractionPlan.setForcedSpaceGroup( XSDataString(self.strForcedSpaceGroup)) self.xsDataDiffractionPlan.setAnomalousData( XSDataBoolean(self.bAnomalousData)) self.xsDataDiffractionPlan.setMaxExposureTimePerDataCollection( XSDataTime(self.fMaxExposureTimePerDataCollection)) if (self.strStrategyOption is not None): self.xsDataDiffractionPlan.setStrategyOption( XSDataString(self.strStrategyOption)) xsDataCollection.setDiffractionPlan(self.xsDataDiffractionPlan) if self.xsDataSample is not None: xsDataCollection.setSample( XSDataSampleCrystalMM.parseString(self.xsDataSample.marshal())) self.xsDataInputCharacterisation.setDataCollection(xsDataCollection)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'experimentalCondition': obj_ = XSDataExperimentalCondition() obj_.build(child_) self.setExperimentalCondition(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'diffractionPlan': obj_ = XSDataDiffractionPlan() obj_.build(child_) self.setDiffractionPlan(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'sample': obj_ = XSDataSampleCrystalMM() obj_.build(child_) self.setSample(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'imagePath': obj_ = XSDataFile() obj_.build(child_) self.imagePath.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'flux': obj_ = XSDataFloat() obj_.build(child_) self.setFlux(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'minExposureTimePerImage': obj_ = XSDataTime() obj_.build(child_) self.setMinExposureTimePerImage(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamSize': obj_ = XSDataLength() obj_.build(child_) self.setBeamSize(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamSizeX': obj_ = XSDataLength() obj_.build(child_) self.setBeamSizeX(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamSizeY': obj_ = XSDataLength() obj_.build(child_) self.setBeamSizeY(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'apertureSize': obj_ = XSDataLength() obj_.build(child_) self.setApertureSize(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'templateMode': obj_ = XSDataBoolean() obj_.build(child_) self.setTemplateMode(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'generatedTemplateFile': obj_ = XSDataFile() obj_.build(child_) self.setGeneratedTemplateFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'resultsFilePath': obj_ = XSDataFile() obj_.build(child_) self.setResultsFilePath(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamPosX': obj_ = XSDataFloat() obj_.build(child_) self.setBeamPosX(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'beamPosY': obj_ = XSDataFloat() obj_.build(child_) self.setBeamPosY(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'wavelength': obj_ = XSDataWavelength() obj_.build(child_) self.setWavelength(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'transmission': obj_ = XSDataDouble() obj_.build(child_) self.setTransmission(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dataCollectionId': obj_ = XSDataInteger() obj_.build(child_) self.setDataCollectionId(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'shortComments': obj_ = XSDataString() obj_.build(child_) self.setShortComments(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'comments': obj_ = XSDataString() obj_.build(child_) self.setComments(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'inputCharacterisation': obj_ = XSDataInputCharacterisation() obj_.build(child_) self.setInputCharacterisation(obj_)
def process(self, _edObject=None): EDPluginExec.process(self) EDVerbose.DEBUG("*** EDPluginExecReadImageHeaderADSCv10.process") xsDataInputReadImageHeader = self.getDataInput() xsDataFile = xsDataInputReadImageHeader.getImage() strPath = xsDataFile.getPath().getValue() strAbsolutePath = os.path.abspath(strPath) dictHeader = self.readHeaderADSC(strPath) if (dictHeader is None): strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : error when reading header from %s" % strAbsolutePath EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: xsDataExperimentalCondition = XSDataExperimentalCondition() xsDataDetector = XSDataDetector() xsDataDetector.setBeamPositionX(XSDataLength(float(dictHeader[ "BEAM_CENTER_X" ]))) xsDataDetector.setBeamPositionY(XSDataLength(float(dictHeader[ "BEAM_CENTER_Y" ]))) xsDataDetector.setDistance(XSDataLength(float(dictHeader[ "DISTANCE" ]))) fPixelSize = float(dictHeader[ "PIXEL_SIZE" ]) xsDataDetector.setPixelSizeX(XSDataLength(fPixelSize)) xsDataDetector.setPixelSizeY(XSDataLength(fPixelSize)) if "TWOTHETA" in dictHeader.keys(): xsDataDetector.setTwoTheta(XSDataAngle(float(dictHeader[ "TWOTHETA" ]))) xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictHeader[ "HEADER_BYTES" ]))) xsDataDetector.setSerialNumber(XSDataString(dictHeader[ "DETECTOR_SN" ])) xsDataDetector.setNumberPixelX(XSDataInteger(int(dictHeader[ "SIZE1" ]))) xsDataDetector.setNumberPixelY(XSDataInteger(int(dictHeader[ "SIZE2" ]))) xsDataDetector.setBin(XSDataString(dictHeader[ "BIN" ])) xsDataDetector.setDataType(XSDataString(dictHeader[ "TYPE" ])) xsDataDetector.setByteOrder(XSDataString(dictHeader[ "BYTE_ORDER" ])) if "CCD_IMAGE_SATURATION" in dictHeader.keys(): xsDataDetector.setImageSaturation(XSDataInteger(int(dictHeader[ "CCD_IMAGE_SATURATION" ]))) # Determine type of detector... iNoPixelsX = xsDataDetector.getNumberPixelX().getValue() iNoPixelsY = xsDataDetector.getNumberPixelY().getValue() if (iNoPixelsX == 2304 and iNoPixelsY == 2304): xsDataDetector.setName(XSDataString("ADSC Q4")) xsDataDetector.setType(XSDataString("q4")) elif (iNoPixelsX == 1152 and iNoPixelsY == 1152): xsDataDetector.setName(XSDataString("ADSC Q4 bin 2x2")) xsDataDetector.setType(XSDataString("q4-2x")) elif (iNoPixelsX == 4096 and iNoPixelsY == 4096): xsDataDetector.setName(XSDataString("ADSC Q210")) xsDataDetector.setType(XSDataString("q210")) elif (iNoPixelsX == 2048 and iNoPixelsY == 2048): xsDataDetector.setName(XSDataString("ADSC Q210 bin 2x2")) xsDataDetector.setType(XSDataString("q210-2x")) elif (iNoPixelsX == 6144 and iNoPixelsY == 6144): xsDataDetector.setName(XSDataString("ADSC Q315")) xsDataDetector.setType(XSDataString("q315")) elif (iNoPixelsX == 3072 and iNoPixelsY == 3072): xsDataDetector.setName(XSDataString("ADSC Q315 bin 2x2")) xsDataDetector.setType(XSDataString("q315-2x")) else: strErrorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ("EDPluginExecReadImageHeaderADSCv10.process", "Unknown detector type") EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage xsDataExperimentalCondition.setDetector(xsDataDetector) # Beam object xsDataBeam = XSDataBeam() xsDataBeam.setWavelength(XSDataWavelength(float(dictHeader[ "WAVELENGTH" ]))) xsDataBeam.setExposureTime(XSDataTime(float(dictHeader[ "TIME" ]))) xsDataExperimentalCondition.setBeam(xsDataBeam) # Goniostat object xsDataGoniostat = XSDataGoniostat() fRotationAxisStart = float(dictHeader[ "OSC_START" ]) fOscillationWidth = float(dictHeader[ "OSC_RANGE" ]) xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart)) xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth)) xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth)) strRotationAxis = None if ("AXIS" in dictHeader.keys()): strRotationAxis = dictHeader[ "AXIS" ] elif ("OSC_AXIS" in dictHeader.keys()): strRotationAxis = dictHeader[ "OSC_AXIS" ] else: strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : Neither AXIS nor OSC_AXIS header item found." EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() xsDataGoniostat.setRotationAxis(XSDataString(strRotationAxis)) xsDataExperimentalCondition.setGoniostat(xsDataGoniostat) # Create the image object xsDataImage = XSDataImage() xsDataImage.setPath(XSDataString(strAbsolutePath)) xsDataImage.setDate(XSDataString(dictHeader[ "DATE" ])) strFileName = os.path.basename(strPath) iImageNumber = EDUtilsImage.getImageNumber(strFileName) xsDataImage.setNumber(XSDataInteger(iImageNumber)) xsDataSubWedge = XSDataSubWedge() xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition) xsDataSubWedge.addImage(xsDataImage) self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader() self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)
def testIsSameExperimentalCondition(self): edPluginSubWedgeMergev10 = self.createPlugin() xsDataExperimentalConditionReference = self.getTestExperimentalCondition( ) xsDataExperimentalConditionSameAsReference = self.getTestExperimentalCondition( ) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionSameAsReference), True) xsDataExperimentalConditionDifferentExposureTime = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentExposureTime.getBeam( ).setExposureTime(XSDataTime(10.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentExposureTime), False) xsDataExperimentalConditionDifferentWavelength = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentWavelength.getBeam().setWavelength( XSDataWavelength(1.5)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentWavelength), False) xsDataExperimentalConditionDifferentBeamPositionX = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentBeamPositionX.getDetector( ).setBeamPositionX(XSDataLength(20.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentBeamPositionX), False) xsDataExperimentalConditionDifferentBeamPositionY = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentBeamPositionY.getDetector( ).setBeamPositionY(XSDataLength(20.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentBeamPositionY), False) xsDataExperimentalConditionDifferentDistance = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentDistance.getDetector().setDistance( XSDataLength(220.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentDistance), False) xsDataExperimentalConditionDifferentName = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentName.getDetector().setName( XSDataString(u"EDNA")) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentName), False) xsDataExperimentalConditionDifferentNumberPixelX = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentNumberPixelX.getDetector( ).setNumberPixelX(XSDataInteger(2)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentNumberPixelX), False) xsDataExperimentalConditionDifferentNumberPixelY = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentNumberPixelY.getDetector( ).setNumberPixelY(XSDataInteger(2)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentNumberPixelY), False) xsDataExperimentalConditionDifferentSerialNumber = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentSerialNumber.getDetector( ).setSerialNumber(XSDataString(u"EDNA")) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentSerialNumber), False) xsDataExperimentalConditionDifferentTwoTheta = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentTwoTheta.getDetector().setTwoTheta( XSDataAngle(90.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentTwoTheta), False) xsDataExperimentalConditionDifferentOscillationWidth = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentOscillationWidth.getGoniostat( ).setOscillationWidth(XSDataAngle(2.0)) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentOscillationWidth), False) xsDataExperimentalConditionDifferentRotationAxis = self.getTestExperimentalCondition( ) xsDataExperimentalConditionDifferentRotationAxis.getGoniostat( ).setRotationAxis(XSDataString(u"EDNA")) EDAssert.equal( edPluginSubWedgeMergev10.isSameExperimentalCondition( xsDataExperimentalConditionReference, xsDataExperimentalConditionDifferentRotationAxis), False)
def populateXSDataInputSPDCake(self, _inputDict=None): self.DEBUG("EDPluginControlID11v1_0.populateXSDataInputSPDCake") xsDataInputSPDCake = XSDataInputSPDCake() if isinstance(_inputDict, dict): self.__dictID11 = _inputDict # Angle of tilt if "ANGLE OF TILT" in self.__dictID11: xsDataTilt = XSDataAngle() xsDataTilt.setValue(float(self.__dictID11["ANGLE OF TILT"])) xsDataTilt.setUnit(XSDataString("deg")) xsDataInputSPDCake.setAngleOfTilt(xsDataTilt) if "TILT ROTATION" in self.__dictID11: xsDataTiltRot = XSDataAngle() xsDataTiltRot.setValue(float(self.__dictID11["TILT ROTATION"])) xsDataTiltRot.setUnit(XSDataString("deg")) xsDataInputSPDCake.setTiltRotation(xsDataTiltRot) if "X-PIXEL SIZE" in self.__dictID11: xsDataXPixel = XSDataLength() xsDataXPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"])) xsDataXPixel.setUnit(XSDataString("micron")) xsDataInputSPDCake.setPixelSizeX(xsDataXPixel) if "Y-PIXEL SIZE" in self.__dictID11: xsDataYPixel = XSDataLength() xsDataYPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"])) xsDataYPixel.setUnit(XSDataString("micron")) xsDataInputSPDCake.setPixelSizeY(xsDataYPixel) if "DISTANCE" in self.__dictID11: xsDataDistance = XSDataLength() xsDataDistance.setValue(float(self.__dictID11["DISTANCE"])) xsDataDistance.setUnit(XSDataString("mm")) xsDataInputSPDCake.setSampleToDetectorDistance(xsDataDistance) if "WAVELENGTH" in self.__dictID11: xsDataWaweLength = XSDataWavelength() xsDataWaweLength.setValue(float(self.__dictID11["WAVELENGTH"])) xsDataWaweLength.setUnit(XSDataString("A")) xsDataInputSPDCake.setWavelength(xsDataWaweLength) if "DIM1_DATA" in self.__dictID11: xsDataBufferSizeX = XSDataInteger(int( self.__dictID11["DIM1_DATA"])) xsDataInputSPDCake.setBufferSizeX(xsDataBufferSizeX) if "DIM2_DATA" in self.__dictID11: xsDataBufferSizeY = XSDataInteger(int( self.__dictID11["DIM2_DATA"])) xsDataInputSPDCake.setBufferSizeY(xsDataBufferSizeY) # Dark current if ("DARK CURRENT" in self.__dictID11) and (self.__dictID11["DARK CURRENT"] == "YES"): if ("DC FILE" in self.__dictID11) and os.path.isfile( self.__dictID11["DC FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["DC FILE"])) xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile) else: self.warning( "Asked for DC Current correction but no DC current file") if ("FLAT-FIELD" in self.__dictID11) and (self.__dictID11["FLAT-FIELD"] == "YES"): if ("FF FILE" in self.__dictID11) and os.path.isfile( self.__dictID11["FF FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["FF FILE"])) xsDataInputSPDCake.setFlatFieldImageFile(xsDataFile) else: self.warning( "Asked for FLAT-FIELD correction but no FLAT-FIELD file") if ("MASK FILE" in self.__dictID11) and (self.__dictID11["USE MASK"] == "YES"): if ("MASK FILE" in self.__dictID11) and os.path.isfile( self.__dictID11["MASK FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["MASK FILE"])) xsDataInputSPDCake.setMaskFile(xsDataFile) else: self.warning( "Asked for DC Current correction but no DC current file") if ("FF SCALE" in self.__dictID11) and (self.__dictID11["FF SCALE"] == "YES"): if ("FF MULTIPLIER" in self.__dictID11): try: value = float(self.__dictID11["FF MULTIPLIER"]) except Exception: self.warning( "Asked for FF SCALE correction but FF MULTIPLIER provided (%s) in not float !" % (self.__dictID11["FF MULTIPLIER"])) else: xsDataInputSPDCake.setIntensityScaleFactor( XSDataDouble(1 / value)) else: self.warning( "Asked for FF SCALE correction but no FF MULTIPLIER provided" ) if ("SPATIAL DIS." in self.__dictID11) and (self.__dictID11["SPATIAL DIS."] == "YES"): if ("SD FILE" in self.__dictID11) and os.path.isfile( self.__dictID11["SD FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["SD FILE"])) xsDataInputSPDCake.setSpatialDistortionFile(xsDataFile) else: self.warning( "Asked for SPATIAL DISTORSION correction but no SPATIAL DISTORSION file" ) if "START AZIMUTH" in self.__dictID11: xsDataAzimuthStart = XSDataAngle() xsDataAzimuthStart.setValue(float( self.__dictID11["START AZIMUTH"])) xsDataAzimuthStart.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStartAzimuth(xsDataAzimuthStart) if "END AZIMUTH" in self.__dictID11: xsDataAzimuthStop = XSDataAngle() xsDataAzimuthStop.setValue(float(self.__dictID11["END AZIMUTH"])) xsDataAzimuthStop.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStopAzimuth(xsDataAzimuthStop) if "AZIMUTH BINS" in self.__dictID11: xsDataAzimuthStep = XSDataAngle() xsDataAzimuthStep.setValue( (float(self.__dictID11["END AZIMUTH"]) - float(self.__dictID11["START AZIMUTH"])) / float(self.__dictID11["AZIMUTH BINS"])) xsDataAzimuthStep.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStepAzimuth(xsDataAzimuthStep) if "INNER RADIUS" in self.__dictID11: xsDataInnerRadius = XSDataDouble() xsDataInnerRadius.setValue(float(self.__dictID11["INNER RADIUS"])) xsDataInputSPDCake.setInnerRadius(xsDataInnerRadius) if "OUTER RADIUS" in self.__dictID11: xsDataOuterRadius = XSDataDouble() xsDataOuterRadius.setValue(float(self.__dictID11["OUTER RADIUS"])) xsDataInputSPDCake.setOuterRadius(xsDataOuterRadius) if "X-BEAM CENTRE" in self.__dictID11: xsDataXBeamCentre = XSDataDouble() xsDataXBeamCentre.setValue(float(self.__dictID11["X-BEAM CENTRE"])) xsDataInputSPDCake.setBeamCentreInPixelsX(xsDataXBeamCentre) if "Y-BEAM CENTRE" in self.__dictID11: xsDataYBeamCentre = XSDataDouble() xsDataYBeamCentre.setValue(float(self.__dictID11["Y-BEAM CENTRE"])) xsDataInputSPDCake.setBeamCentreInPixelsY(xsDataYBeamCentre) # if "saving_format" in self.__dictID11: # xsSaveFormat = XSDataString() # if self.__dictID11["saving_format"] == "SPREAD SHEET": # xsSaveFormat.setValue("spr") # elif self.__dictID11["saving_format"] == "CIF": # xsSaveFormat.setValue("cif") # elif self.__dictID11["saving_format"] == "CHIPLOT": # xsSaveFormat.setValue("chi") # else: # xsSaveFormat.setValue("edf") # xsDataInputSPDCake.setOutputFileType(xsSaveFormat) if "output_dir" in self.__dictID11: xsOutputDir = XSDataFile() xsOutputDir.setPath(XSDataString(self.__dictID11["output_dir"])) xsDataInputSPDCake.setOutputDir(xsOutputDir) #Default options to SPD xsDataInputSPDCake.setOutputFileType(XSDataString("azim")) xsDataInputSPDCake.setDeleteCorImg( XSDataBoolean(not self.isVerboseDebug())) xsDataInputSPDCake.setCorrectTiltMask(XSDataBoolean(self.bCorrectMask)) return xsDataInputSPDCake
def populateXSDataInputSPDCake(self, _inputDict=None): self.DEBUG("EDPluginControlID11v1_0.populateXSDataInputSPDCake") xsDataInputSPDCake = XSDataInputSPDCake() if isinstance(_inputDict, dict): self.__dictID11 = _inputDict # Angle of tilt if "ANGLE OF TILT" in self.__dictID11: xsDataTilt = XSDataAngle() xsDataTilt.setValue(float(self.__dictID11["ANGLE OF TILT"])) xsDataTilt.setUnit(XSDataString("deg")) xsDataInputSPDCake.setAngleOfTilt(xsDataTilt) if "TILT ROTATION" in self.__dictID11: xsDataTiltRot = XSDataAngle() xsDataTiltRot.setValue(float(self.__dictID11["TILT ROTATION"])) xsDataTiltRot.setUnit(XSDataString("deg")) xsDataInputSPDCake.setTiltRotation(xsDataTiltRot) if "X-PIXEL SIZE" in self.__dictID11: xsDataXPixel = XSDataLength() xsDataXPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"])) xsDataXPixel.setUnit(XSDataString("micron")) xsDataInputSPDCake.setPixelSizeX(xsDataXPixel) if "Y-PIXEL SIZE" in self.__dictID11: xsDataYPixel = XSDataLength() xsDataYPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"])) xsDataYPixel.setUnit(XSDataString("micron")) xsDataInputSPDCake.setPixelSizeY(xsDataYPixel) if "DISTANCE" in self.__dictID11: xsDataDistance = XSDataLength() xsDataDistance.setValue(float(self.__dictID11["DISTANCE"])) xsDataDistance.setUnit(XSDataString("mm")) xsDataInputSPDCake.setSampleToDetectorDistance(xsDataDistance) if "WAVELENGTH" in self.__dictID11: xsDataWaweLength = XSDataWavelength() xsDataWaweLength.setValue(float(self.__dictID11["WAVELENGTH"])) xsDataWaweLength.setUnit(XSDataString("A")) xsDataInputSPDCake.setWavelength(xsDataWaweLength) if "DIM1_DATA" in self.__dictID11: xsDataBufferSizeX = XSDataInteger(int(self.__dictID11["DIM1_DATA"])) xsDataInputSPDCake.setBufferSizeX(xsDataBufferSizeX) if "DIM2_DATA" in self.__dictID11: xsDataBufferSizeY = XSDataInteger(int(self.__dictID11["DIM2_DATA"])) xsDataInputSPDCake.setBufferSizeY(xsDataBufferSizeY) # Dark current if ("DARK CURRENT" in self.__dictID11) and (self.__dictID11["DARK CURRENT"] == "YES") : if ("DC FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["DC FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["DC FILE"])) xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile) else: self.warning("Asked for DC Current correction but no DC current file") if ("FLAT-FIELD" in self.__dictID11) and (self.__dictID11["FLAT-FIELD"] == "YES"): if ("FF FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["FF FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["FF FILE"])) xsDataInputSPDCake.setFlatFieldImageFile(xsDataFile) else: self.warning("Asked for FLAT-FIELD correction but no FLAT-FIELD file") if ("MASK FILE" in self.__dictID11) and (self.__dictID11["USE MASK"] == "YES") : if ("MASK FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["MASK FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["MASK FILE"])) xsDataInputSPDCake.setMaskFile(xsDataFile) else: self.warning("Asked for DC Current correction but no DC current file") if ("FF SCALE" in self.__dictID11) and (self.__dictID11["FF SCALE"] == "YES"): if ("FF MULTIPLIER" in self.__dictID11): try: value = float(self.__dictID11["FF MULTIPLIER"]) except Exception: self.warning("Asked for FF SCALE correction but FF MULTIPLIER provided (%s) in not float !" % (self.__dictID11["FF MULTIPLIER"])) else: xsDataInputSPDCake.setIntensityScaleFactor(XSDataDouble(1 / value)) else: self.warning("Asked for FF SCALE correction but no FF MULTIPLIER provided") if ("SPATIAL DIS." in self.__dictID11) and (self.__dictID11["SPATIAL DIS."] == "YES"): if ("SD FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["SD FILE"]): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.__dictID11["SD FILE"])) xsDataInputSPDCake.setSpatialDistortionFile(xsDataFile) else : self.warning("Asked for SPATIAL DISTORSION correction but no SPATIAL DISTORSION file") if "START AZIMUTH" in self.__dictID11: xsDataAzimuthStart = XSDataAngle() xsDataAzimuthStart.setValue(float(self.__dictID11["START AZIMUTH"])) xsDataAzimuthStart.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStartAzimuth(xsDataAzimuthStart) if "END AZIMUTH" in self.__dictID11: xsDataAzimuthStop = XSDataAngle() xsDataAzimuthStop.setValue(float(self.__dictID11["END AZIMUTH"])) xsDataAzimuthStop.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStopAzimuth(xsDataAzimuthStop) if "AZIMUTH BINS" in self.__dictID11: xsDataAzimuthStep = XSDataAngle() xsDataAzimuthStep.setValue((float(self.__dictID11["END AZIMUTH"]) - float(self.__dictID11["START AZIMUTH"])) / float(self.__dictID11["AZIMUTH BINS"])) xsDataAzimuthStep.setUnit(XSDataString("deg")) xsDataInputSPDCake.setStepAzimuth(xsDataAzimuthStep) if "INNER RADIUS" in self.__dictID11: xsDataInnerRadius = XSDataDouble() xsDataInnerRadius.setValue(float(self.__dictID11["INNER RADIUS"])) xsDataInputSPDCake.setInnerRadius(xsDataInnerRadius) if "OUTER RADIUS" in self.__dictID11: xsDataOuterRadius = XSDataDouble() xsDataOuterRadius.setValue(float(self.__dictID11["OUTER RADIUS"])) xsDataInputSPDCake.setOuterRadius(xsDataOuterRadius) if "X-BEAM CENTRE" in self.__dictID11: xsDataXBeamCentre = XSDataDouble() xsDataXBeamCentre.setValue(float(self.__dictID11["X-BEAM CENTRE"])) xsDataInputSPDCake.setBeamCentreInPixelsX(xsDataXBeamCentre) if "Y-BEAM CENTRE" in self.__dictID11: xsDataYBeamCentre = XSDataDouble() xsDataYBeamCentre.setValue(float(self.__dictID11["Y-BEAM CENTRE"])) xsDataInputSPDCake.setBeamCentreInPixelsY(xsDataYBeamCentre) # if "saving_format" in self.__dictID11: # xsSaveFormat = XSDataString() # if self.__dictID11["saving_format"] == "SPREAD SHEET": # xsSaveFormat.setValue("spr") # elif self.__dictID11["saving_format"] == "CIF": # xsSaveFormat.setValue("cif") # elif self.__dictID11["saving_format"] == "CHIPLOT": # xsSaveFormat.setValue("chi") # else: # xsSaveFormat.setValue("edf") # xsDataInputSPDCake.setOutputFileType(xsSaveFormat) if "output_dir" in self.__dictID11: xsOutputDir = XSDataFile() xsOutputDir.setPath(XSDataString(self.__dictID11["output_dir"])) xsDataInputSPDCake.setOutputDir(xsOutputDir) #Default options to SPD xsDataInputSPDCake.setOutputFileType(XSDataString("azim")) xsDataInputSPDCake.setDeleteCorImg(XSDataBoolean(not self.isVerboseDebug())) xsDataInputSPDCake.setCorrectTiltMask(XSDataBoolean(self.bCorrectMask)) return xsDataInputSPDCake
def from_params(self, data_collection, char_params): edna_input = XSDataInputMXCuBE.parseString(self.edna_default_input) if data_collection.id: edna_input.setDataCollectionId(XSDataInteger(data_collection.id)) #Beam object beam = edna_input.getExperimentalCondition().getBeam() try: transmission = self.collect_obj.get_transmission() beam.setTransmission(XSDataDouble(transmission)) except AttributeError: pass try: wavelength = self.collect_obj.get_wavelength() beam.setWavelength(XSDataWavelength(wavelength)) except AttributeError: pass try: beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity())) except AttributeError: pass try: beamsize = self.get_beam_size() if not None in beamsize: beam.setSize( XSDataSize(x=XSDataLength(float(beamsize[0])), y=XSDataLength(float(beamsize[1])))) except AttributeError: pass #Optimization parameters diff_plan = edna_input.getDiffractionPlan() aimed_i_sigma = XSDataDouble(char_params.aimed_i_sigma) aimed_completness = XSDataDouble(char_params.aimed_completness) aimed_multiplicity = XSDataDouble(char_params.aimed_multiplicity) aimed_resolution = XSDataDouble(char_params.aimed_resolution) complexity = char_params.strategy_complexity complexity = XSDataString(qme.STRATEGY_COMPLEXITY[complexity]) permitted_phi_start = XSDataAngle(char_params.permitted_phi_start) _range = char_params.permitted_phi_end - char_params.permitted_phi_start rotation_range = XSDataAngle(_range) diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma) diff_plan.setAimedCompleteness(aimed_completness) if char_params.use_aimed_multiplicity: diff_plan.setAimedMultiplicity(aimed_multiplicity) if char_params.use_aimed_resolution: diff_plan.setAimedResolution(aimed_resolution) diff_plan.setComplexity(complexity) if char_params.use_permitted_rotation: diff_plan.setUserDefinedRotationStart(permitted_phi_start) diff_plan.setUserDefinedRotationRange(rotation_range) #Vertical crystal dimension sample = edna_input.getSample() sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim)) sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim)) #Radiation damage model sample.setSusceptibility(XSDataDouble(char_params.rad_suscept)) sample.setChemicalComposition(None) sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta / 1e6)) sample.setRadiationDamageModelGamma( XSDataDouble(char_params.gamma / 1e6)) diff_plan.setForcedSpaceGroup(XSDataString(char_params.space_group)) # Characterisation type - Routine DC if char_params.use_min_dose: pass if char_params.use_min_time: time = XSDataTime(char_params.min_time) diff_plan.setMaxExposureTimePerDataCollection(time) # Account for radiation damage if char_params.induce_burn: diff_plan.setStrategyOption(XSDataString("-DamPar")) else: diff_plan.setStrategyOption(None) # Characterisation type - SAD if char_params.opt_sad: diff_plan.setAnomalousData(XSDataBoolean(True)) else: diff_plan.setAnomalousData(XSDataBoolean(False)) #Data set data_set = XSDataMXCuBEDataSet() acquisition_parameters = data_collection.acquisitions[ 0].acquisition_parameters path_template = data_collection.acquisitions[0].path_template path_str = os.path.join(path_template.directory, path_template.get_image_file_name()) for img_num in range(int(acquisition_parameters.num_images)): image_file = XSDataFile() path = XSDataString() path.setValue(path_str % (img_num + 1)) image_file.setPath(path) data_set.addImageFile(image_file) edna_input.addDataSet(data_set) edna_input.process_directory = path_template.process_directory return edna_input
def process(self, _edObject=None): EDPluginExec.process(self) EDVerbose.DEBUG("EDPluginExecReadImageHeaderMARCCDv10.process") xsDataInputReadImageHeader = self.getDataInput() xsDataFile = xsDataInputReadImageHeader.getImage() strPath = xsDataFile.getPath().getValue() dictMARCCDHeader = self.readHeaderMarccd(strPath) if (dictMARCCDHeader is None): strErrorMessage = "EDPluginExecReadImageHeaderMARCCDv10.process : Cannot read header : %s" % strPath EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: xsDataExperimentalCondition = XSDataExperimentalCondition() xsDataDetector = XSDataDetector() iNoPixelsX = int(dictMARCCDHeader["nslow"]) iNoPixelsY = int(dictMARCCDHeader["nfast"]) xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX)) xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY)) fPixelSizeX = float(dictMARCCDHeader["pixelsize_x"]) / 1000.0 xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX)) fPixelSizeY = float(dictMARCCDHeader["pixelsize_y"]) / 1000.0 xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY)) fBeamPositionX = float(dictMARCCDHeader["beam_x"]) / 1000.0 fBeamPositionY = float(dictMARCCDHeader["beam_y"]) / 1000.0 # Fix for bug 397 - check if the beam position is close to the centre of the image fTwoTheta = float(dictMARCCDHeader["end_twotheta"]) / 1000.0 xsDataDetector.setTwoTheta(XSDataAngle(fTwoTheta)) if (abs(fTwoTheta) < 0.1): if (abs(fBeamPositionX / (fPixelSizeX / 1000.0) - iNoPixelsX / 2.0) > (2 * iNoPixelsX)): fBeamPositionX = fBeamPositionX * fPixelSizeX / 1000.0 fBeamPositionY = fBeamPositionY * fPixelSizeY / 1000.0 xsDataDetector.setBeamPositionX(XSDataLength(fBeamPositionX)) xsDataDetector.setBeamPositionY(XSDataLength(fBeamPositionY)) fDistance = float(dictMARCCDHeader["xtal_to_detector"]) / 1000.0 if (abs(fDistance) < 0.1): fDistanceStart = float( dictMARCCDHeader["start_xtal_to_detector"]) / 1000.0 fDistanceEnd = float( dictMARCCDHeader["end_xtal_to_detector"]) / 1000.0 if (abs(fDistanceStart - fDistanceEnd) < 0.1): fDistance = fDistanceStart else: # Somethings very wrong with the distances... strErrorMessage = "EDPluginExecReadImageHeaderMARCCDv10.process : Inconsistency in MAR CCD image header: start_xtal_to_detector = %d, end_xtal_to_detector = %d" % \ (fDistanceStart, fDistanceEnd) EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() xsDataDetector.setDistance(XSDataLength(fDistance)) xsDataDetector.setNumberBytesInHeader( XSDataInteger(float(dictMARCCDHeader["header_size"]))) #xsDataDetector.setSerialNumber( XSDataInteger( dictMARCCDHeader[ "DETECTOR_SN" ] ) ) ) #xsDataDetector.setBin( XSDataString( dictMARCCDHeader[ "BIN" ] ) ) ) #xsDataDetector.setDataType( XSDataString( dictMARCCDHeader[ "TYPE" ] ) ) ) #xsDataDetector.setByteOrder( XSDataString( dictMARCCDHeader[ "BYTE_ORDER" ] ) ) ) xsDataDetector.setImageSaturation( XSDataInteger(int(dictMARCCDHeader["saturation_level"]))) # Determine type of detector... if (iNoPixelsX == 2048 and iNoPixelsY == 2048): xsDataDetector.setName(XSDataString("MAR CCD 165")) xsDataDetector.setType(XSDataString("mar165")) elif (iNoPixelsX == 3072 and iNoPixelsY == 3072): xsDataDetector.setName(XSDataString("MAR CCD 225")) xsDataDetector.setType(XSDataString("mar225")) elif (iNoPixelsX == 4096 and iNoPixelsY == 4096): xsDataDetector.setName(XSDataString("MAR CCD 325")) xsDataDetector.setType(XSDataString("mar325")) else: strErrorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ( "EDPluginExecReadImageHeaderMARCCDv10.process", "Unknown detector type") EDVerbose.error(strErrorMessage) self.addErrorMessage(strErrorMessage) raise RuntimeError, strErrorMessage xsDataExperimentalCondition.setDetector(xsDataDetector) # Beam object xsDataBeam = XSDataBeam() xsDataBeam.setWavelength( XSDataWavelength( float(dictMARCCDHeader["source_wavelength"]) / 100000.0)) xsDataBeam.setExposureTime( XSDataTime(float(dictMARCCDHeader["exposure_time"]) / 1000.0)) xsDataExperimentalCondition.setBeam(xsDataBeam) # Goniostat object xsDataGoniostat = XSDataGoniostat() fRotationAxisStart = float(dictMARCCDHeader["start_phi"]) / 1000.0 fOscillationWidth = float( dictMARCCDHeader["rotation_range"]) / 1000.0 xsDataGoniostat.setRotationAxisStart( XSDataAngle(fRotationAxisStart)) xsDataGoniostat.setRotationAxisEnd( XSDataAngle(fRotationAxisStart + fOscillationWidth)) xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth)) xsDataExperimentalCondition.setGoniostat(xsDataGoniostat) # Create the image object xsDataImage = XSDataImage() xsDataImage.setPath(XSDataString(strPath)) strTimeStamp = dictMARCCDHeader["acquire_timestamp"] xsDataImage.setDate(XSDataString(strTimeStamp)) iImageNumber = EDUtilsImage.getImageNumber(strPath) xsDataImage.setNumber(XSDataInteger(iImageNumber)) xsDataSubWedge = XSDataSubWedge() xsDataSubWedge.setExperimentalCondition( xsDataExperimentalCondition) xsDataSubWedge.addImage(xsDataImage) self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader() self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)