def preProcess(self, _edObject=None): """ The pre-process of ED Plugin Control DiffractionCT Powder Integration consists in preparing the input data for SPD Cake. and declares the execution plugin as EDPluginFit2DCacke """ EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginControlDCTPowderIntegrationv1_1.preProcess") # Load the execution plugin self.m_edPluginPowderIntegration = self.loadPlugin(self.m_edStringControlledPluginName) #Retrive its'datamodel xsDataInputSPDCake = XSDataInputSPDCake() instrumentParameters = self.getDataInput().getInstrumentParameters() imageParameters = self.getDataInput().getImageParameters() xsDataInputSPDCake.setInputFile(self.getDataInput().getImageFile()) xsDataInputSPDCake.setWavelength(instrumentParameters.get_diffrn_radiation_wavelength()) xsDataInputSPDCake.setSampleToDetectorDistance(instrumentParameters.get_pd_instr_dist_spec_detc()) xsDataInputSPDCake.setAngleOfTilt(imageParameters.get_pd_instr_special_details_tilt_angle()) xsDataInputSPDCake.setTiltRotation(imageParameters.get_pd_instr_special_details_tilt_rotation()) xsDataInputSPDCake.setDarkCurrentImageFile(imageParameters.get_file_correction_image_dark_current()) xsDataInputSPDCake.setFlatFieldImageFile(imageParameters.get_file_correction_image_flat_field()) xsDataInputSPDCake.setSpatialDistortionFile(imageParameters.get_file_correction_spline_spatial_distortion()) # EDVerbose.screen("imageParameters.get_array_element_size_1: %s" % imageParameters.get_array_element_size_1().marshal()) xsDataInputSPDCake.setBeamCentreInPixelsX(XSDataDouble(\ EDUtilsUnit.getSIValue(imageParameters.get_diffrn_detector_element_center_1()) / \ EDUtilsUnit.getSIValue(imageParameters.get_array_element_size_1()))) xsDataInputSPDCake.setBeamCentreInPixelsY(XSDataDouble(\ EDUtilsUnit.getSIValue(imageParameters.get_diffrn_detector_element_center_2()) / \ EDUtilsUnit.getSIValue(imageParameters.get_array_element_size_2()))) xsDataInputSPDCake.setPixelSizeX(imageParameters.get_array_element_size_1()) #imageParameters.get_diffrn_detector_element_center_1()) xsDataInputSPDCake.setPixelSizeY(imageParameters.get_array_element_size_2()) #imageParameters.get_diffrn_detector_element_center_1()) xsDataInputSPDCake.setBufferSizeX(XSDataInteger(2048)) xsDataInputSPDCake.setBufferSizeY(XSDataInteger(2048)) xsDataInputSPDCake.setStartAzimuth(XSDataAngle(0)) xsDataInputSPDCake.setStopAzimuth(XSDataAngle(360)) xsDataInputSPDCake.setStepAzimuth(XSDataAngle(360)) xsDataInputSPDCake.setOutputDirCake(self.getDataInput().getDestinationDir()) xsDataInputSPDCake.setDeleteCorImg(XSDataBoolean(True)) try: self.m_edPluginPowderIntegration.setDataInput(xsDataInputSPDCake) except Exception, error: # This exception handling needs to be rethought, see bug #43. errorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ("EDPluginControlDCTPowderIntegrationv1_1.preProcess: Unexpected error in SPD handler: ", error) EDVerbose.error(errorMessage) self.addErrorMessage(errorMessage) raise RuntimeError, errorMessage
def populateXSDataInputSPDCake(dictID11): xsDataInputSPDCake = XSDataInputSPDCake() # Angle of tilt xsDataInputSPDCake.setAngleOfTilt( XSDataAngle(float(dictID11["ANGLE OF TILT"]))) # Dark current if dictID11["DARK CURRENT"] == "YES": xsDataInputSPDCake.setDarkCurrentImageFile( XSDataFile(XSDataString(dictID11["DC FILE"]))) #xsDataFile = XSDataFile() #xsDataFile.setPath(XSDataString(dictID11["DC FILE "])) #xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile) if dictID11["FLAT-FIELD"] == "YES": xsDataInputSPDCake.setFlatFieldImageFile( XSDataFile(XSDataString(dictID11["FF FILE"]))) if dictID11["FF SCALE"] == "NO": xsDataInputSPDCake.setFlatFieldImageFile( XSDataFile(XSDataString(dictID11["FF MULTIPLIER"]))) if dictID11["SPATIAL DIS."] == "YES": xsDataInputSPDCake.setSpatialDistortionFile( XSDataFile(XSDataString(dictID11["SD FILE"]))) xsDataInputSPDCake.setStartAzimuth( XSDataAngle(float(dictID11["START AZIMUTH"]))) xsDataInputSPDCake.setStopAzimuth( XSDataAngle(float(dictID11["END AZIMUTH"]))) xsDataInputSPDCake.setInnerRadius( XSDataDouble(float(dictID11["INNER RADIUS"]))) xsDataInputSPDCake.setOuterRadius( XSDataDouble(float(dictID11["OUTER RADIUS"]))) xsDataInputSPDCake.setBufferSizeX( XSDataInteger(int(dictID11["X-PIXEL SIZE"]))) xsDataInputSPDCake.setBufferSizeY( XSDataInteger(int(dictID11["Y-PIXEL SIZE"]))) xsDataInputSPDCake.setSampleToDetectorDistance( XSDataLength(float(dictID11["DISTANCE"]))) xsDataInputSPDCake.setWavelength( XSDataLength(float(dictID11["WAVELENGTH"]))) xsDataInputSPDCake.setBeamCentreInPixelsX( XSDataDouble(float(dictID11["X-BEAM CENTRE"]))) xsDataInputSPDCake.setBeamCentreInPixelsY( XSDataDouble(float(dictID11["Y-BEAM CENTRE"]))) xsDataInputSPDCake.setTiltRotation( XSDataAngle(float(dictID11["TILT ROTATION"]))) xsDataInputSPDCake.setOutputFileType( XSDataFile(XSDataString(dictID11["saving_format"]))) xsDataInputSPDCake.setOutputFileType( XSDataFile(XSDataString(dictID11["output_dir"]))) # TODO : some parameters remain not inserted in this file because not in the datamodel print xsDataInputSPDCake.marshal()
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