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 unitTestGetValueAngle(self): """ Test conversion in length """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueAngle") EDAssert.equal( 100.0, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataAngle, "90 deg"), "grad"), "Length Conversion deg -> grad ")
def unitTestGetValueTime(self): """ Test conversion in Time """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueTime") EDAssert.equal( 60.0, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataTime, "1 h"), "mn"), "Length Conversion h -> mn ")
def unitTestGetValueLength(self): """ Test conversion in length """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueLength") EDAssert.equal( 0.0452, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataLength, "45.2 um"), "mm"), "Length Conversion um -> mm ")
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecNormalizeImagev1_2.preProcess") sdi = self.getDataInput() if sdi.dataScaleFactor is not None: self.scaleData = sdi.dataScaleFactor.value if sdi.darkScaleFactor is not None: self.scaleDark = sdi.darkScaleFactor.value if sdi.flatScaleFactor is not None: self.scaleFlat = sdi.flatScaleFactor.value if sdi.data == []: strError = "You should either provide at least ONE input filename or an array, you provided: %s" % sdi.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) else: for inputData in sdi.data: if inputData.exposureTime is None: self.WARNING("You did not provide an exposure time for DATA... using default: 1") self.listDataExposure.append(1.0) else: self.listDataExposure.append(EDUtilsUnit.getSIValue(inputData.exposureTime)) self.listDataArray.append(EDUtilsArray.getArray(inputData) / self.scaleData) for inputFlat in sdi.flat: if inputFlat.exposureTime is None: self.WARNING("You did not provide an exposure time for FLAT... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputFlat.exposureTime) self.listFlatExposure.append(expTime) self.listFlatArray.append(EDUtilsArray.getArray(inputFlat) / self.scaleFlat) with self.__class__.semaphore: for inputDark in sdi.dark: if inputDark.exposureTime is None: self.WARNING("You did not provide an exposure time for Dark... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputDark.exposureTime) # strMeanDarkKey = "/".join((self.getClassName(), "MeanDark%6.3f" % expTime)) if str(expTime) not in self.__class__.dictDark: self.listDarkExposure.append(expTime) self.listDarkArray.append(EDUtilsArray.getArray(inputDark) / self.scaleDark) if sdi.output is not None: if (sdi.output.path is not None): self.strOutputFilename = sdi.output.path.value elif (sdi.output.shared is not None): self.strOutputShared = sdi.output.shared.value # else export as array. EDAssert.equal(len(self.listDataArray), len(self.listDataExposure), _strComment="number of data images / exposure times ") EDAssert.equal(len(self.listFlatArray), len(self.listFlatExposure), _strComment="number of flat images / exposure times ") EDAssert.equal(len(self.listDarkArray), len(self.listDarkExposure), _strComment="number of dark images / exposure times ")
def unitTestGetSIValue(self): """ test the execution of unitTestGetSIValue static method """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetSIValue") xsd = XSDataLength(1.5) xsd.setUnit(XSDataString("mm")) EDAssert.equal(0.0015, EDUtilsUnit.getSIValue(xsd), "Conversion mm to meter") xsd = XSDataAngle(90) xsd.setUnit(XSDataString("deg")) EDAssert.equal(math.pi / 2, EDUtilsUnit.getSIValue(xsd), "Conversion deg to rad")
def getDetector(xsDetector): detector = None if xsDetector.name and (xsDetector.name.value in dir(pyFAI.detectors)): detector = getattr(pyFAI.detectors, xsDetector.name.value)() else: pixel2 = EDUtilsUnit.getSIValue(xsDetector.pixelSizeX) pixel1 = EDUtilsUnit.getSIValue(xsDetector.pixelSizeY) if xsDetector.splineFile and os.path.isFile(xsDetector.splineFile.path.value): dictGeo = {"pixel1":pixel1, "pixel2":pixel2, "splineFile":xsDetector.splineFile.path.value} else: dictGeo = {"pixel1":pixel1, "pixel2":pixel2, "splineFile":None} detector = pyFAI.detectors.Detector() detector.setPyFAI(**dictGeo) return detector
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecPyFAIv1_0.preProcess") sdi = self.dataInput ai = pyFAI.AzimuthalIntegrator() if sdi.geometryFit2D is not None: xsGeometry = sdi.geometryFit2D detector = self.getDetector(xsGeometry.detector) d = {"direct": EDUtilsUnit.getSIValue(xsGeometry.distance) * 1000, #fit2D takes the distance in mm "centerX": xsGeometry.beamCentreInPixelsX.value , "centerY":xsGeometry.beamCentreInPixelsY.value , "tilt": xsGeometry.angleOfTilt.value, "tiltPlanRotation": xsGeometry.tiltRotation.value} d.update(detector.getFit2D()) ai.setFit2D(**d) elif sdi.geometryPyFAI is not None: xsGeometry = sdi.geometryPyFAI detector = self.getDetector(xsGeometry.detector) d = {"dist": EDUtilsUnit.getSIValue(xsGeometry.sampleDetectorDistance), "poni1": EDUtilsUnit.getSIValue(xsGeometry.pointOfNormalIncidence1), "poni2": EDUtilsUnit.getSIValue(xsGeometry.pointOfNormalIncidence2), "rot1": EDUtilsUnit.getSIValue(xsGeometry.rotation1), "rot2": EDUtilsUnit.getSIValue(xsGeometry.rotation2), "rot3": EDUtilsUnit.getSIValue(xsGeometry.rotation3)} d.update(detector.getPyFAI()) ai.setPyFAI(**d) else: strError = "Geometry definition in %s, not recognized as a valid geometry%s %s" % (sdi, os.linesep, sdi.marshal()) self.ERROR(strError) raise RuntimeError(strError) ######################################################################## # Choose the azimuthal integrator ######################################################################## with self.__class__._sem: if tuple(ai.param) in self.__class__._dictGeo: self.ai = self.__class__._dictGeo[tuple(ai.param)] else: self.__class__._dictGeo[tuple(ai.param)] = ai self.ai = ai self.data = EDUtilsArray.getArray(self.dataInput.input).astype(float) if sdi.dark is not None: self.data -= EDUtilsArray.getArray(sdi.dark) if sdi.flat is not None: self.data /= EDUtilsArray.getArray(sdi.flat) if sdi.mask is not None: self.mask = EDUtilsArray.getArray(sdi.mask) if sdi.wavelength is not None: self.ai.wavelength = EDUtilsUnit.getSIValue(sdi.wavelength) if sdi.output is not None: self.strOutputFile = sdi.output.path.value if sdi.dummy is not None: self.dummy = sdi.dummy.value if sdi.deltaDummy is not None: self.delta_dummy = sdi.deltaDummy.value if sdi.nbPt: self.nbPt = sdi.nbPt.value
def getInputParameter(self): """ Read all the input parameters and store them in instance variables called self.dictGeometry and self.pathToInputFile """ self.DEBUG("EDPluginSPDCakev1_5.getInputParameter") EDPluginSPDCorrectv10.getInputParameter(self) if self.xsDataInputSPD.getStartAzimuth() is not None: if self.xsDataInputSPD.getStartAzimuth().getUnit() is not None: self.dictGeometry["StartAzimuth"] = EDUtilsUnit.getValue(self.xsDataInputSPD.getStartAzimuth(), "deg") else: self.WARNING("You did not specify the StartAzimuth Unit, Falling back to Deg (not Rad)") self.dictGeometry["StartAzimuth"] = self.xsDataInputSPD.getStartAzimuth().getValue() if self.xsDataInputSPD.getStopAzimuth() is not None: if self.xsDataInputSPD.getStopAzimuth().getUnit() is not None: self.dictGeometry["StopAzimuth"] = EDUtilsUnit.getValue(self.xsDataInputSPD.getStopAzimuth(), "deg") else: self.WARNING("You did not specify the StopAzimuth Unit, Falling back to Deg (not Rad)") self.dictGeometry["StopAzimuth"] = self.xsDataInputSPD.getStopAzimuth().getValue() if self.xsDataInputSPD.getStepAzimuth() is not None: if self.xsDataInputSPD.getStepAzimuth().getUnit() is not None: self.dictGeometry["StepAzimuth"] = EDUtilsUnit.getValue(self.xsDataInputSPD.getStepAzimuth(), "deg") else: self.WARNING("You did not specify the StepAzimuth Unit, Falling back to Deg (not Rad)") self.dictGeometry["StepAzimuth"] = self.xsDataInputSPD.getStepAzimuth().getValue() if self.xsDataInputSPD.getInnerRadius() is not None: self.dictGeometry["InnerRadius"] = self.xsDataInputSPD.getInnerRadius().getValue() if self.xsDataInputSPD.getOuterRadius() is not None: self.dictGeometry["OuterRadius"] = self.xsDataInputSPD.getOuterRadius().getValue() if self.xsDataInputSPD.getOutputDirCake() is not None: self.dictGeometry["OutputDirCake"] = self.xsDataInputSPD.getOutputDirCake().getPath().getValue() EDUtilsPath.createFolder(self.dictGeometry["OutputDirCake"]) if self.dictGeometry["OutputDirCake"] != self.dictGeometry["OutputDir"]: self.setFireAndForget(False) else: self.dictGeometry["OutputDirCake"] = self.dictGeometry["OutputDir"] if self.xsDataInputSPD.getMaskFile() is not None: self.dictGeometry["MaskFile"] = self.xsDataInputSPD.getMaskFile().getPath().getValue() if not os.path.isfile(self.dictGeometry["MaskFile"]): self.ERROR("Mask file %s does not exist " % self.dictGeometry["MaskFile"]) self.dictGeometry.pop("MaskFile") if self.xsDataInputSPD.getIntensityScaleFactor() is not None: self.dictGeometry["IntensityScaleFactor"] = self.xsDataInputSPD.getIntensityScaleFactor().getValue() if self.xsDataInputSPD.getDeleteCorImg() is not None: self.bDeleteCorImg = (self.xsDataInputSPD.getDeleteCorImg().getValue() in ["1", 1, "true", "True", True]) if self.bDeleteCorImg: self.setFireAndForget(False) if self.xsDataInputSPD.getCorrectTiltMask() is not None: self.bCorrectTiltMask = bool(self.xsDataInputSPD.getCorrectTiltMask().getValue())
def integrate(self): img = fabio.open(self.rawImage) if "Date" in img.header: self.experimentSetup.timeOfFrame = XSDataTime(time.mktime(time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y"))) wavelength = EDUtilsUnit.getSIValue(self.experimentSetup.wavelength) current_config = self.integrator.getPyFAI() short_config = {} for key in self.integrator_config: short_config[key] = current_config[key] with self.__class__.semaphore: if (short_config != self.integrator_config) or \ (self.integrator.wavelength != wavelength) or\ (self.maskfile != self.experimentSetup.maskFile.path.value): self.screen("Resetting PyFAI integrator") self.integrator.setPyFAI(**self.integrator_config) self.integrator.wavelength = wavelength self.integrator.detector.mask = self.calc_mask() q, I, std = self.integrator.integrate1d(data=img.data, nbPt=max(img.dim1, img.dim2), correctSolidAngle=True, dummy=self.dummy, delta_dummy=self.delta_dummy, filename=None, error_model="poisson", radial_range=None, azimuth_range=None, polarization_factor=0, dark=None, flat=None, method=self.METHOD, unit="q_nm^-1", safe=False) self.lstExecutiveSummary.append("Azimuthal integration of raw image '%s'-->'%s'." % (self.rawImage, self.integratedCurve)) return q, I, std
def unitTestGetValueSIAngle(self): """ Test sub method specific to length: GetValueLength """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueSIAngle") EDAssert.equal(math.pi / 2.0, EDUtilsUnit.getValueAngle(90, "deg"), "Angle Conversion deg -> rad ")
def integrate(self): img = fabio.open(self.rawImage) if "Date" in img.header: self.experimentSetup.timeOfFrame = XSDataTime(time.mktime(time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y"))) wavelength = EDUtilsUnit.getSIValue(self.experimentSetup.wavelength) current_config = self.integrator.getPyFAI() short_config = {} for key in self.integrator_config: short_config[key] = current_config[key] with self.__class__.semaphore: if (short_config != self.integrator_config) or \ (self.integrator.wavelength != wavelength) or\ (self.maskfile != self.experimentSetup.maskFile.path.value): self.screen("Resetting PyFAI integrator") self.integrator.setPyFAI(**self.integrator_config) self.integrator.wavelength = wavelength self.integrator.detector.mask = self.calc_mask() q, I, std = self.integrator.integrate1d(img.data, max(img.dim1, img.dim2), correctSolidAngle=True, dummy=self.dummy, delta_dummy=self.delta_dummy, filename=None, error_model="poisson", radial_range=None, azimuth_range=None, polarization_factor=0, dark=None, flat=None, method=self.METHOD, unit="q_nm^-1", safe=False) self.lstExecutiveSummary.append("Azimuthal integration of raw image '%s'-->'%s'." % (self.rawImage, self.integratedCurve)) return q, I, std
def unitTestGetValueSILength(self): """ Test sub method specific to length: GetValueLength """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueSILength") EDAssert.equal(1.54E-10, EDUtilsUnit.getValueLength(1.54, "A"), "Length Conversion A -> m ")
def integrate(self): #with fabio.fabioutils.File(self.rawImage) as raw: img = fabio.open(self.rawImage) number_of_bins = self.number_of_bins or max(img.dim1, img.dim2) if "Date" in img.header: self.experimentSetup.timeOfFrame = XSDataTime(time.mktime(time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y"))) new_integrator = pyFAI.AzimuthalIntegrator(detector=self.detector) new_integrator.setFit2D(self.experimentSetup.detectorDistance.value * 1000, self.experimentSetup.beamCenter_1.value, self.experimentSetup.beamCenter_2.value) new_integrator.wavelength = EDUtilsUnit.getSIValue(self.experimentSetup.wavelength) with self.__class__.semaphore: if (str(new_integrator) != str(self.integrator) or self.maskfile != self.experimentSetup.maskFile.path.value): self.screen("Resetting PyFAI integrator") new_integrator.detector.mask = self.calc_mask() self.__class__.integrator = new_integrator res_tuple = self.integrator.integrate1d(img.data, number_of_bins, correctSolidAngle=True, dummy=self.dummy, delta_dummy=self.delta_dummy, filename=None, error_model="poisson", radial_range=None, azimuth_range=None, polarization_factor=0.99, dark=None, flat=None, method=self.METHOD, unit="q_nm^-1", safe=False, normalization_factor=self.normalization_factor ) self.lstExecutiveSummary.append("Azimuthal integration of raw image '%s'-->'%s'." % (self.rawImage, self.integratedCurve)) return res_tuple
def unitTestGetValueSITime(self): """ Test sub method specific to length: GetValueTime """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueSITime") EDAssert.equal(1800, EDUtilsUnit.getValueTime(30, "mn"), "Length Conversion mn -> s ")
def unitTestToXSD(self): """ """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestToXSD") xsdObt = EDUtilsUnit.toXSD(XSDataLength, "1.5 mm") xsdExp = XSDataLength(1.5) xsdExp.setUnit(XSDataString("mm")) EDAssert.equal(xsdExp.marshal(), xsdObt.marshal(), "XML representation are the same")
def integrate(self): #with fabio.fabioutils.File(self.rawImage) as raw: img = fabio.open(self.rawImage) number_of_bins = self.number_of_bins or max(img.dim1, img.dim2) if "Date" in img.header: self.experimentSetup.timeOfFrame = XSDataTime( time.mktime( time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y"))) new_integrator = pyFAI.AzimuthalIntegrator(detector=self.detector) new_integrator.setFit2D( self.experimentSetup.detectorDistance.value * 1000, self.experimentSetup.beamCenter_1.value, self.experimentSetup.beamCenter_2.value) new_integrator.wavelength = EDUtilsUnit.getSIValue( self.experimentSetup.wavelength) with self.__class__.semaphore: if (str(new_integrator) != str(self.integrator) or self.maskfile != self.experimentSetup.maskFile.path.value): self.screen("Resetting PyFAI integrator") new_integrator.detector.mask = self.calc_mask() self.__class__.integrator = new_integrator res_tuple = self.integrator.integrate1d( img.data, number_of_bins, correctSolidAngle=True, dummy=self.dummy, delta_dummy=self.delta_dummy, filename=None, error_model="poisson", radial_range=None, azimuth_range=None, polarization_factor=0.99, dark=None, flat=None, method=self.METHOD, unit="q_nm^-1", safe=False, normalization_factor=self.normalization_factor) self.lstExecutiveSummary.append( "Azimuthal integration of raw image '%s'-->'%s'." % (self.rawImage, self.integratedCurve)) valid_bins = abs(res_tuple.intensity - self.dummy) > self.delta_dummy short_tuple = res_tuple.__class__(res_tuple.radial[valid_bins], res_tuple.intensity[valid_bins], res_tuple.sigma[valid_bins]) return short_tuple
def unitTestGetValueLength(self): """ Test conversion in length """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueLength") EDAssert.equal(0.0452, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataLength, "45.2 um"), "mm"), "Length Conversion um -> mm ")
def getInputParameter(self, _edObject=None): """ Read all the input parameters and store them in instance variables called self.dictGeometry and self.pathToInputFile """ self.DEBUG("EDPluginSPDCorrectv10.getInputParameter") self.xsDataInputSPD = self.getDataInput() self.pathToInputFile = self.xsDataInputSPD.getInputFile().getPath().getValue() if not os.path.isfile(self.pathToInputFile): edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", self.pathToInputFile, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getDarkCurrentImageFile() is not None: pathToDarkCurrentImageFile = self.xsDataInputSPD.getDarkCurrentImageFile().getPath().getValue() if os.path.isfile(pathToDarkCurrentImageFile): self.dictGeometry["DarkCurrentImageFile"] = pathToDarkCurrentImageFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDarkCurrentImageFile, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getFlatFieldImageFile() is not None: pathToFlatFieldImageFile = self.xsDataInputSPD.getFlatFieldImageFile().getPath().getValue() if os.path.isfile(pathToFlatFieldImageFile): self.dictGeometry["FlatFieldImageFile"] = pathToFlatFieldImageFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToFlatFieldImageFile, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getSpatialDistortionFile() is not None: pathToSpatialDistortionFile = self.xsDataInputSPD.getSpatialDistortionFile().getPath().getValue() if os.path.isfile(pathToSpatialDistortionFile): self.dictGeometry["SpatialDistortionFile"] = pathToSpatialDistortionFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToSpatialDistortionFile, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getAngleOfTilt() is not None: if self.xsDataInputSPD.getAngleOfTilt().getUnit() is not None: self.dictGeometry["AngleOfTilt"] = EDUtilsUnit.getValue(self.xsDataInputSPD.getAngleOfTilt(), "deg") else: # Fall-back by default to deg self.WARNING("You did not specify the AngleOfTilt unit ... I Guess it is deg") self.dictGeometry["AngleOfTilt"] = self.xsDataInputSPD.getAngleOfTilt().getValue() else: self.dictGeometry["AngleOfTilt"] = 0 if self.xsDataInputSPD.getTiltRotation() is not None: if self.xsDataInputSPD.getTiltRotation().getUnit() is not None: self.dictGeometry["TiltRotation"] = EDUtilsUnit.getValue(self.xsDataInputSPD.getTiltRotation(), "deg") else: # Fall-back by default to deg self.WARNING("You did not specify the TiltRotation unit ... I Guess it is deg") self.dictGeometry["TiltRotation"] = self.xsDataInputSPD.getTiltRotation().getValue() else: self.dictGeometry["TiltRotation"] = 0 if self.xsDataInputSPD.getBeamCentreInPixelsX() is not None: self.dictGeometry["BeamCenterX"] = self.xsDataInputSPD.getBeamCentreInPixelsX().getValue() if self.xsDataInputSPD.getBeamCentreInPixelsY() is not None: self.dictGeometry["BeamCenterY"] = self.xsDataInputSPD.getBeamCentreInPixelsY().getValue() if self.xsDataInputSPD.getBufferSizeX() is not None: self.dictGeometry["BufferSizeX"] = self.xsDataInputSPD.getBufferSizeX().getValue() if self.xsDataInputSPD.getBufferSizeY() is not None: self.dictGeometry["BufferSizeY"] = self.xsDataInputSPD.getBufferSizeY().getValue() if self.xsDataInputSPD.getDistortionFileX() is not None: pathToDistortionFileX = self.xsDataInputSPD.getDistortionFileX().getPath().getValue() if os.path.isfile(pathToDistortionFileX): self.dictGeometry["DistortionFileX"] = pathToDistortionFileX else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDistortionFileX, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getDistortionFileY() is not None: pathToDistortionFileY = self.xsDataInputSPD.getDistortionFileY().getPath().getValue() if os.path.isfile(pathToDistortionFileY): self.dictGeometry["DistortionFileY"] = pathToDistortionFileY else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDistortionFileY, ) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getPixelSizeX() is not None: self.dictGeometry["PixelSizeX"] = EDUtilsUnit.getSIValue(self.xsDataInputSPD.getPixelSizeX()) if self.xsDataInputSPD.getPixelSizeY() is not None: self.dictGeometry["PixelSizeY"] = EDUtilsUnit.getSIValue(self.xsDataInputSPD.getPixelSizeY()) if self.xsDataInputSPD.getSampleToDetectorDistance() is not None: self.dictGeometry["SampleToDetectorDistance"] = EDUtilsUnit.getSIValue( self.xsDataInputSPD.getSampleToDetectorDistance() ) if self.xsDataInputSPD.getWavelength() is not None: if self.xsDataInputSPD.getWavelength().getUnit() is not None: self.dictGeometry["Wavelength"] = EDUtilsUnit.getSIValue(self.xsDataInputSPD.getWavelength()) else: # Fall-back to Angsrom self.WARNING("You did not specify the wavelength unit ... I Guess it is Angstrom") self.dictGeometry["Wavelength"] = self.xsDataInputSPD.getWavelength().getValue() * 1e-10 if self.xsDataInputSPD.getOutputFileType() is not None: self.dictGeometry["OutputFileType"] = self.xsDataInputSPD.getOutputFileType().getValue() if not self.dictGeometry["OutputFileType"].startswith("."): self.dictGeometry["OutputFileType"] = "." + self.dictGeometry["OutputFileType"] else: self.dictGeometry["OutputFileType"] = ".edf" if self.xsDataInputSPD.getOutputDir() is not None: tmpdir = self.xsDataInputSPD.getOutputDir().getPath().getValue() if os.path.isdir(tmpdir): self.dictGeometry["OutputDir"] = tmpdir if tmpdir != os.path.dirname(self.pathToInputFile): self._bFireAndForget = True else: self.WARNING( "The destination directory %s does not exist, using working directory instead %s" % (tmpdir, self.getWorkingDirectory()) ) self.dictGeometry["OutputDir"] = self.getWorkingDirectory() else: self.dictGeometry["OutputDir"] = os.path.dirname(self.pathToInputFile) if ( self.dictGeometry["OutputDir"] == os.path.dirname(self.pathToInputFile) and not (self.pathToInputFile.endswith(self.dictGeometry["OutputFileType"])) and not (self.dictGeometry["OutputFileType"].lower() in [".h5", ".chi", ".nx", ".nexus", ".cif"]) ): self.bFireAndForget = True
def readArrayFromFile(self, _filename): """ Populate self.inputArray for a given filename and extracts as well self.fPixelSize self.fDistance self.fRadOffset self.wavelength ... """ image = openimage(_filename) self.inputArray = image.data self.dHeader = image.header if "Offset_1" in self.dHeader: offset, unit = self.dHeader["Offset_1"].split(None, 1) if unit.lower() != "pixel": EDVerbose.WARNING( "I got a strange unit for offset: %s, I expected pixel." % self.dHeader["Offset_1"]) try: self.fRadOffset = float(offset) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize this offset and convert it to float: %s" % self.dHeader[ "Offset_1"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if "Offset_2" in self.dHeader: offset, unit = self.dHeader["Offset_2"].split(None, 1) if unit.lower() != "pixel": EDVerbose.WARNING( "I got a strange unit for offset: %s, I expected pixel." % self.dHeader["Offset_2"]) try: self.fAzimOffset = float(offset) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize this offset and convert it to float: %s" % self.dHeader[ "Offset_2"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if "PSize_1" in self.dHeader: psize, unit = self.dHeader["PSize_1"].split(None, 1) try: fPixelSize = float(psize) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the radial pixel size and convert it to float: %s" % self.dHeader[ "PSize_1"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: self.fPixelSize = EDUtilsUnit.getValueLength(fPixelSize, unit) if "PSize_2" in self.dHeader: psize, unit = self.dHeader["PSize_2"].split(None, 1) try: fPixelSize = float(psize) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the azimuthal pixel size and convert it to float: %s" % self.dHeader[ "PSize_2"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: self.fAzimSize = EDUtilsUnit.getValueAngle(fPixelSize, unit) if ("SampleDistance" in self.dHeader): distance, unit = self.dHeader["SampleDistance"].split(None, 1) try: fDistance = float(distance) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the Sample Distance is and convert it to float: %s" % self.dHeader[ "SampleDistance"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage self.fDistance = EDUtilsUnit.getValueLength(fDistance, unit) if ("WaveLength" in self.dHeader): wavelenth, unit = self.dHeader["WaveLength"].split(None, 1) try: fWavelength = float(wavelenth) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the wavelength is and convert it to float: %s" % self.dHeader[ "WaveLength"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage self.fWavelength = EDUtilsUnit.getValueLength(fWavelength, unit) if ("Dummy" in self.dHeader): self.fDummy = float(self.dHeader.get("Dummy", 0)) if ("DDummy" in self.dHeader): self.fDeltaDummy = float(self.dHeader.get("DDummy", 0.1))
def unitTestGetValueAngle(self): """ Test conversion in length """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueAngle") EDAssert.equal(100.0, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataAngle, "90 deg"), "grad"), "Length Conversion deg -> grad ")
def preProcess(self, _edObject=None): """ Preprocess: check the input parameters and unpack them """ EDPluginExec.preProcess(self) EDVerbose.DEBUG("EDPluginExportAsciiPowderv1_0.preProcess") if self.getDataInput().getEdfFile() is not None: self.inputFilename = self.getDataInput().getEdfFile().getPath( ).getValue() if not os.path.isfile(self.inputFilename): EDVerbose.ERROR( "The input file provided is not a valid file: %s" % self.inputFilename) raise RuntimeError("Not a valid file %s" % self.inputFilename) else: self.readArrayFromFile(self.inputFilename) elif self.getDataInput().getIntensities() is not None: self.inputArray = EDUtilsArray.xsDataToArray( self.getDataInput().getIntensities()) else: strErrorMessage = "EDPluginExportAsciiPowderv1_0.preProcess: neither an input image, neither a data array given in input !" EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if self.getDataInput().getDistance() is not None: self.fDistance = EDUtilsUnit.getSIValue( self.getDataInput().getDistance()) if self.getDataInput().getPixelSize() is not None: self.fPixelSize = EDUtilsUnit.getSIValue( self.getDataInput().getPixelSize()) if self.getDataInput().getOffset() is not None: self.fRadOffset = self.getDataInput().getOffset().getValue() if self.getDataInput().getOutputFormat() is not None: self.strFormat = self.getDataInput().getOutputFormat().getValue( ).lower() if self.getDataInput().getNumberOfBins() is not None: self.iNbBins = self.getDataInput().getNumberOfBins().getValue() if self.strFormat == "array": self.outputFilename = None else: if self.getDataInput().getOutputFile() is None: if "chi" in self.strFormat: ext = ".chi" elif "cif" in self.strFormat: ext = ".cif" elif "spr" in self.strFormat: ext = ".spr" else: ext = ".powder" self.outputFilename = os.path.join(self.getWorkingDirectory(), "output" + ext) else: self.outputFilename = self.getDataInput().getOutputFile( ).getPath().getValue() if os.path.isdir(self.outputFilename): if "chi" in self.strFormat: ext = ".chi" elif "cif" in self.strFormat: ext = ".cif" elif "spr" in self.strFormat: ext = ".spr" else: ext = ".powder" self.outputFilename = os.path.join( self.outputFilename, os.path.splitext(os.path.basename( self.inputFilename))[0] + ext) if (self.fPixelSize is None) or (self.fDistance is None): strErrorMessage = "EDPluginExportAsciiPowderv1_0.preProcess: pixel size: %s; distance: %s Cannot be identified in %s !!!!" % ( self.fPixelSize, self.fDistance, self.inputFilename) EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecNormalizeImagev1_2.preProcess") sdi = self.getDataInput() if sdi.dataScaleFactor is not None: self.scaleData = sdi.dataScaleFactor.value if sdi.darkScaleFactor is not None: self.scaleDark = sdi.darkScaleFactor.value if sdi.flatScaleFactor is not None: self.scaleFlat = sdi.flatScaleFactor.value if sdi.data == []: strError = "You should either provide at least ONE input filename or an array, you provided: %s" % sdi.marshal( ) self.ERROR(strError) self.setFailure() raise RuntimeError(strError) else: for inputData in sdi.data: if inputData.exposureTime is None: self.WARNING( "You did not provide an exposure time for DATA... using default: 1" ) self.listDataExposure.append(1.0) else: self.listDataExposure.append( EDUtilsUnit.getSIValue(inputData.exposureTime)) self.listDataArray.append( EDUtilsArray.getArray(inputData) / self.scaleData) for inputFlat in sdi.flat: if inputFlat.exposureTime is None: self.WARNING( "You did not provide an exposure time for FLAT... using default: 1" ) expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputFlat.exposureTime) self.listFlatExposure.append(expTime) self.listFlatArray.append( EDUtilsArray.getArray(inputFlat) / self.scaleFlat) with self.__class__.semaphore: for inputDark in sdi.dark: if inputDark.exposureTime is None: self.WARNING( "You did not provide an exposure time for Dark... using default: 1" ) expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputDark.exposureTime) # strMeanDarkKey = "/".join((self.getClassName(), "MeanDark%6.3f" % expTime)) if str(expTime) not in self.__class__.dictDark: self.listDarkExposure.append(expTime) self.listDarkArray.append( EDUtilsArray.getArray(inputDark) / self.scaleDark) if sdi.output is not None: if (sdi.output.path is not None): self.strOutputFilename = sdi.output.path.value elif (sdi.output.shared is not None): self.strOutputShared = sdi.output.shared.value # else export as array. EDAssert.equal(len(self.listDataArray), len(self.listDataExposure), _strComment="number of data images / exposure times ") EDAssert.equal(len(self.listFlatArray), len(self.listFlatExposure), _strComment="number of flat images / exposure times ") EDAssert.equal(len(self.listDarkArray), len(self.listDarkExposure), _strComment="number of dark images / exposure times ")
def doSuccessReadHeader(self, _edPlugin=None): EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_2.doSuccessReadHeader") self.retrieveSuccessMessages(_edPlugin, "EDPluginControlDiffractionCTv1_2.doSuccessReadHeader") # Translate dictionary to image and instrument objects xsDataInputPowderIntegration = XSDataInputPowderIntegration() self.xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument() self.xsDataDiffractionCTImage = XSDataDiffractionCTImage() xsdOut = _edPlugin.getDataOutput() if xsdOut is None: strErr = "EDPluginControlDiffractionCTv1_2.doSuccessReadHeader: xsdataResult is None" EDVerbose.ERROR(strErr) self.setFailure() raise RuntimeError(strErr) xsDataDictionaryHeader = xsdOut.getDictionary() for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair(): strKey = str(xsDataKeyValuePair.getKey().getValue()) lstValue = xsDataKeyValuePair.getValue().getValue().split() if len(lstValue) == 2: strValue = lstValue[0] strUnit = lstValue[1] else: strValue = xsDataKeyValuePair.getValue().getValue() strUnit = None if (strKey == "_diffrn_radiation_wavelength"): xsd = EDUtilsUnit.toXSD(XSDataWavelength, strValue) self.xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(xsd) elif (strKey == "_pd_instr_dist_spec/detc"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) self.xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(xsd) elif (strKey == "_pd_meas_2theta_range_max"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(xsd) elif (strKey == "_pd_meas_2theta_range_min"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(xsd) elif (strKey == "_pd_meas_2theta_range_inc"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(xsd) elif (strKey == "_synchrotron_photon-flux"): self.xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(XSDataFlux(float(strValue))) elif (strKey == "_synchrotron_ring-intensity"): self.xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(XSDataDouble(float(strValue))) elif (strKey == "_tomo_scan_ampl"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_scan_ampl(xsd) elif (strKey == "_tomo_scan_type"): self.xsDataDiffractionCTInstrument.set_tomo_scan_type(XSDataString(strValue)) elif (strKey == "_tomo_spec_displ_rotation"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(xsd) elif (strKey == "_tomo_spec_displ_rotation_inc"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(xsd) elif (strKey == "_tomo_spec_displ_x"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(xsd) elif (strKey == "_tomo_spec_displ_x_inc"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(xsd) elif (strKey == "_tomo_spec_displ_x_max"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(xsd) elif (strKey == "_tomo_spec_displ_x_min"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(xsd) elif (strKey == "_tomo_spec_displ_z"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(xsd) elif (strKey == "_tomo_spec_displ_z_inc"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(xsd) elif (strKey == "_tomo_spec_displ_z_max"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(xsd) elif (strKey == "_tomo_spec_displ_z_min"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(xsd) elif (strKey == "_pd_instr_special_details_tilt_angle"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(xsd) elif (strKey == "_pd_instr_special_details_tilt_rotation"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(xsd) elif (strKey == "_array_element_size[1]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "m" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_array_element_size_1(xsd) elif (strKey == "_array_element_size[2]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "m" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_array_element_size_2(xsd) elif (strKey == "_diffrn_detector_element.center[1]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(xsd) elif (strKey == "_diffrn_detector_element.center[2]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(xsd) elif (strKey == "_file_correction_image_dark-current"): xsDataFileDark = XSDataFile() xsDataFileDark.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_dark_current(xsDataFileDark) elif (strKey == "_file_correction_image_flat-field"): xsDataFileFlat = XSDataFile() xsDataFileFlat.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_flat_field(xsDataFileFlat) elif (strKey == "_file_correction_image-mask"): xsDataFileMask = XSDataFile() xsDataFileMask.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_mask(xsDataFileMask) elif (strKey == "_file_correction_spline_spatial-distortion"): xsDataFileSpatialDist = XSDataFile() xsDataFileSpatialDist.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(xsDataFileSpatialDist) if self.xsdForceImageParam is not None: self.forceImageParam(self.xsdForceImageParam) if self.xsdForceScanParam is not None: self.forceScanParam(self.xsdForceScanParam) xsDataInputPowderIntegration.setImageParameters(self.xsDataDiffractionCTImage) xsDataInputPowderIntegration.setInstrumentParameters(self.xsDataDiffractionCTInstrument) xsDataInputPowderIntegration.setImageFile(self.xsDataFileInputImage) # Set the destination directory for output XRPD file strDestinationDirectory = os.path.join(self.getDataInput().getDestinationDirectory().getPath().getValue(), \ self.getDataInput().getPowderDiffractionSubdirectory().getValue()) if self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() in ["flat", "spiral"]: pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation_inc().getValue()) elif self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() == "mapping": #I agree mappings are not sinograms but the really looks like, no ? pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z().getValue() - self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_min().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_inc().getValue()) else: pyintLineNumber = None try: strDestinationDirectory = "%s%04i" % (strDestinationDirectory, pyintLineNumber) except TypeError: pass #if pyintLineNumber is none: do not add suffix xsDataInputPowderIntegration.setDestinationDir(XSDataFile(XSDataString(strDestinationDirectory))) self.edPluginPowderIntegration.setDataInput(xsDataInputPowderIntegration)
def getInputParameter(self, _edObject=None): """ Read all the input parameters and store them in instance variables called self.dictGeometry and self.pathToInputFile """ self.DEBUG("EDPluginSPDCorrectv10.getInputParameter") self.xsDataInputSPD = self.getDataInput() self.pathToInputFile = self.xsDataInputSPD.getInputFile().getPath( ).getValue() if not os.path.isfile(self.pathToInputFile): edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", self.pathToInputFile) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getDarkCurrentImageFile() is not None: pathToDarkCurrentImageFile = self.xsDataInputSPD.getDarkCurrentImageFile( ).getPath().getValue() if os.path.isfile(pathToDarkCurrentImageFile): self.dictGeometry[ "DarkCurrentImageFile"] = pathToDarkCurrentImageFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDarkCurrentImageFile) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getFlatFieldImageFile() is not None: pathToFlatFieldImageFile = self.xsDataInputSPD.getFlatFieldImageFile( ).getPath().getValue() if os.path.isfile(pathToFlatFieldImageFile): self.dictGeometry[ "FlatFieldImageFile"] = pathToFlatFieldImageFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToFlatFieldImageFile) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getSpatialDistortionFile() is not None: pathToSpatialDistortionFile = self.xsDataInputSPD.getSpatialDistortionFile( ).getPath().getValue() if os.path.isfile(pathToSpatialDistortionFile): self.dictGeometry[ "SpatialDistortionFile"] = pathToSpatialDistortionFile else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToSpatialDistortionFile) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getAngleOfTilt() is not None: if self.xsDataInputSPD.getAngleOfTilt().getUnit() is not None: self.dictGeometry["AngleOfTilt"] = EDUtilsUnit.getValue( self.xsDataInputSPD.getAngleOfTilt(), "deg") else: #Fall-back by default to deg self.WARNING( "You did not specify the AngleOfTilt unit ... I Guess it is deg" ) self.dictGeometry[ "AngleOfTilt"] = self.xsDataInputSPD.getAngleOfTilt( ).getValue() else: self.dictGeometry["AngleOfTilt"] = 0 if self.xsDataInputSPD.getTiltRotation() is not None: if self.xsDataInputSPD.getTiltRotation().getUnit() is not None: self.dictGeometry["TiltRotation"] = EDUtilsUnit.getValue( self.xsDataInputSPD.getTiltRotation(), "deg") else: #Fall-back by default to deg self.WARNING( "You did not specify the TiltRotation unit ... I Guess it is deg" ) self.dictGeometry[ "TiltRotation"] = self.xsDataInputSPD.getTiltRotation( ).getValue() else: self.dictGeometry["TiltRotation"] = 0 if self.xsDataInputSPD.getBeamCentreInPixelsX() is not None: self.dictGeometry[ "BeamCenterX"] = self.xsDataInputSPD.getBeamCentreInPixelsX( ).getValue() if self.xsDataInputSPD.getBeamCentreInPixelsY() is not None: self.dictGeometry[ "BeamCenterY"] = self.xsDataInputSPD.getBeamCentreInPixelsY( ).getValue() if self.xsDataInputSPD.getBufferSizeX() is not None: self.dictGeometry[ "BufferSizeX"] = self.xsDataInputSPD.getBufferSizeX().getValue( ) if self.xsDataInputSPD.getBufferSizeY() is not None: self.dictGeometry[ "BufferSizeY"] = self.xsDataInputSPD.getBufferSizeY().getValue( ) if self.xsDataInputSPD.getDistortionFileX() is not None: pathToDistortionFileX = self.xsDataInputSPD.getDistortionFileX( ).getPath().getValue() if os.path.isfile(pathToDistortionFileX): self.dictGeometry["DistortionFileX"] = pathToDistortionFileX else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDistortionFileX) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getDistortionFileY() is not None: pathToDistortionFileY = self.xsDataInputSPD.getDistortionFileY( ).getPath().getValue() if os.path.isfile(pathToDistortionFileY): self.dictGeometry["DistortionFileY"] = pathToDistortionFileY else: edStringErrorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ( self.getPluginName() + ".preProcess", pathToDistortionFileY) self.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage if self.xsDataInputSPD.getPixelSizeX() is not None: self.dictGeometry["PixelSizeX"] = EDUtilsUnit.getSIValue( self.xsDataInputSPD.getPixelSizeX()) if self.xsDataInputSPD.getPixelSizeY() is not None: self.dictGeometry["PixelSizeY"] = EDUtilsUnit.getSIValue( self.xsDataInputSPD.getPixelSizeY()) if self.xsDataInputSPD.getSampleToDetectorDistance() is not None: self.dictGeometry[ "SampleToDetectorDistance"] = EDUtilsUnit.getSIValue( self.xsDataInputSPD.getSampleToDetectorDistance()) if self.xsDataInputSPD.getWavelength() is not None: if self.xsDataInputSPD.getWavelength().getUnit() is not None: self.dictGeometry["Wavelength"] = EDUtilsUnit.getSIValue( self.xsDataInputSPD.getWavelength()) else: #Fall-back to Angsrom self.WARNING( "You did not specify the wavelength unit ... I Guess it is Angstrom" ) self.dictGeometry[ "Wavelength"] = self.xsDataInputSPD.getWavelength( ).getValue() * 1e-10 if self.xsDataInputSPD.getOutputFileType() is not None: self.dictGeometry[ "OutputFileType"] = self.xsDataInputSPD.getOutputFileType( ).getValue() if not self.dictGeometry["OutputFileType"].startswith("."): self.dictGeometry["OutputFileType"] = "." + self.dictGeometry[ "OutputFileType"] else: self.dictGeometry["OutputFileType"] = ".edf" if self.xsDataInputSPD.getOutputDir() is not None: tmpdir = self.xsDataInputSPD.getOutputDir().getPath().getValue() if os.path.isdir(tmpdir): self.dictGeometry["OutputDir"] = tmpdir if tmpdir != os.path.dirname(self.pathToInputFile): self._bFireAndForget = True else: self.WARNING( "The destination directory %s does not exist, using working directory instead %s" % (tmpdir, self.getWorkingDirectory())) self.dictGeometry["OutputDir"] = self.getWorkingDirectory() else: self.dictGeometry["OutputDir"] = os.path.dirname( self.pathToInputFile) if self.dictGeometry["OutputDir"] == os.path.dirname(self.pathToInputFile) and \ not (self.pathToInputFile.endswith(self.dictGeometry["OutputFileType"])) and \ not (self.dictGeometry["OutputFileType"].lower() in [".h5", ".chi", ".nx", ".nexus", ".cif"]) : self.bFireAndForget = True
def preProcess(self, _edObject=None): """ Preprocess: check the input parameters and unpack them """ EDPluginExec.preProcess(self) EDVerbose.DEBUG("EDPluginExportAsciiPowderv1_0.preProcess") if self.getDataInput().getEdfFile() is not None: self.inputFilename = self.getDataInput().getEdfFile().getPath().getValue() if not os.path.isfile(self.inputFilename): EDVerbose.ERROR("The input file provided is not a valid file: %s" % self.inputFilename) raise RuntimeError("Not a valid file %s" % self.inputFilename) else: self.readArrayFromFile(self.inputFilename) elif self.getDataInput().getIntensities() is not None: self.inputArray = EDUtilsArray.xsDataToArray(self.getDataInput().getIntensities()) else: strErrorMessage = "EDPluginExportAsciiPowderv1_0.preProcess: neither an input image, neither a data array given in input !" EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if self.getDataInput().getDistance() is not None: self.fDistance = EDUtilsUnit.getSIValue(self.getDataInput().getDistance()) if self.getDataInput().getPixelSize() is not None: self.fPixelSize = EDUtilsUnit.getSIValue(self.getDataInput().getPixelSize()) if self.getDataInput().getOffset() is not None: self.fRadOffset = self.getDataInput().getOffset().getValue() if self.getDataInput().getOutputFormat() is not None: self.strFormat = self.getDataInput().getOutputFormat().getValue().lower() if self.getDataInput().getNumberOfBins() is not None: self.iNbBins = self.getDataInput().getNumberOfBins().getValue() if self.strFormat == "array": self.outputFilename = None else: if self.getDataInput().getOutputFile() is None: if "chi" in self.strFormat: ext = ".chi" elif "cif" in self.strFormat: ext = ".cif" elif "spr" in self.strFormat: ext = ".spr" else: ext = ".powder" self.outputFilename = os.path.join(self.getWorkingDirectory(), "output" + ext) else: self.outputFilename = self.getDataInput().getOutputFile().getPath().getValue() if os.path.isdir(self.outputFilename): if "chi" in self.strFormat: ext = ".chi" elif "cif" in self.strFormat: ext = ".cif" elif "spr" in self.strFormat: ext = ".spr" else: ext = ".powder" self.outputFilename = os.path.join(self.outputFilename, os.path.splitext(os.path.basename(self.inputFilename))[0] + ext) if (self.fPixelSize is None) or (self.fDistance is None): strErrorMessage = "EDPluginExportAsciiPowderv1_0.preProcess: pixel size: %s; distance: %s Cannot be identified in %s !!!!" % (self.fPixelSize, self.fDistance, self.inputFilename) EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage
def readArrayFromFile(self, _filename): """ Populate self.inputArray for a given filename and extracts as well self.fPixelSize self.fDistance self.fRadOffset self.wavelength ... """ image = openimage(_filename) self.inputArray = image.data self.dHeader = image.header if "Offset_1" in self.dHeader: offset, unit = self.dHeader["Offset_1"].split(None, 1) if unit.lower() != "pixel": EDVerbose.WARNING("I got a strange unit for offset: %s, I expected pixel." % self.dHeader["Offset_1"]) try: self.fRadOffset = float(offset) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize this offset and convert it to float: %s" % self.dHeader["Offset_1"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if "Offset_2" in self.dHeader: offset, unit = self.dHeader["Offset_2"].split(None, 1) if unit.lower() != "pixel": EDVerbose.WARNING("I got a strange unit for offset: %s, I expected pixel." % self.dHeader["Offset_2"]) try: self.fAzimOffset = float(offset) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize this offset and convert it to float: %s" % self.dHeader["Offset_2"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage if "PSize_1" in self.dHeader: psize, unit = self.dHeader["PSize_1"].split(None, 1) try: fPixelSize = float(psize) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the radial pixel size and convert it to float: %s" % self.dHeader["PSize_1"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: self.fPixelSize = EDUtilsUnit.getValueLength(fPixelSize, unit) if "PSize_2" in self.dHeader: psize, unit = self.dHeader["PSize_2"].split(None, 1) try: fPixelSize = float(psize) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the azimuthal pixel size and convert it to float: %s" % self.dHeader["PSize_2"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: self.fAzimSize = EDUtilsUnit.getValueAngle(fPixelSize, unit) if ("SampleDistance" in self.dHeader): distance, unit = self.dHeader["SampleDistance"].split(None, 1) try: fDistance = float(distance) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the Sample Distance is and convert it to float: %s" % self.dHeader["SampleDistance"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage self.fDistance = EDUtilsUnit.getValueLength(fDistance, unit) if ("WaveLength" in self.dHeader): wavelenth, unit = self.dHeader["WaveLength"].split(None, 1) try: fWavelength = float(wavelenth) except ValueError: strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize the wavelength is and convert it to float: %s" % self.dHeader["WaveLength"] EDVerbose.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() raise ValueError, strErrorMessage self.fWavelength = EDUtilsUnit.getValueLength(fWavelength, unit) if ("Dummy" in self.dHeader): self.fDummy = float(self.dHeader.get("Dummy", 0)) if ("DDummy" in self.dHeader): self.fDeltaDummy = float(self.dHeader.get("DDummy", 0.1))
def getInputParameter(self): """ Read all the input parameters and store them in instance variables called self.dictGeometry and self.pathToInputFile """ self.DEBUG("EDPluginSPDCakev1_5.getInputParameter") EDPluginSPDCorrectv10.getInputParameter(self) if self.xsDataInputSPD.getStartAzimuth() is not None: if self.xsDataInputSPD.getStartAzimuth().getUnit() is not None: self.dictGeometry["StartAzimuth"] = EDUtilsUnit.getValue( self.xsDataInputSPD.getStartAzimuth(), "deg") else: self.WARNING( "You did not specify the StartAzimuth Unit, Falling back to Deg (not Rad)" ) self.dictGeometry[ "StartAzimuth"] = self.xsDataInputSPD.getStartAzimuth( ).getValue() if self.xsDataInputSPD.getStopAzimuth() is not None: if self.xsDataInputSPD.getStopAzimuth().getUnit() is not None: self.dictGeometry["StopAzimuth"] = EDUtilsUnit.getValue( self.xsDataInputSPD.getStopAzimuth(), "deg") else: self.WARNING( "You did not specify the StopAzimuth Unit, Falling back to Deg (not Rad)" ) self.dictGeometry[ "StopAzimuth"] = self.xsDataInputSPD.getStopAzimuth( ).getValue() if self.xsDataInputSPD.getStepAzimuth() is not None: if self.xsDataInputSPD.getStepAzimuth().getUnit() is not None: self.dictGeometry["StepAzimuth"] = EDUtilsUnit.getValue( self.xsDataInputSPD.getStepAzimuth(), "deg") else: self.WARNING( "You did not specify the StepAzimuth Unit, Falling back to Deg (not Rad)" ) self.dictGeometry[ "StepAzimuth"] = self.xsDataInputSPD.getStepAzimuth( ).getValue() if self.xsDataInputSPD.getInnerRadius() is not None: self.dictGeometry[ "InnerRadius"] = self.xsDataInputSPD.getInnerRadius().getValue( ) if self.xsDataInputSPD.getOuterRadius() is not None: self.dictGeometry[ "OuterRadius"] = self.xsDataInputSPD.getOuterRadius().getValue( ) if self.xsDataInputSPD.getOutputDirCake() is not None: self.dictGeometry[ "OutputDirCake"] = self.xsDataInputSPD.getOutputDirCake( ).getPath().getValue() EDUtilsPath.createFolder(self.dictGeometry["OutputDirCake"]) if self.dictGeometry["OutputDirCake"] != self.dictGeometry[ "OutputDir"]: self.setFireAndForget(False) else: self.dictGeometry["OutputDirCake"] = self.dictGeometry["OutputDir"] if self.xsDataInputSPD.getMaskFile() is not None: self.dictGeometry["MaskFile"] = self.xsDataInputSPD.getMaskFile( ).getPath().getValue() if not os.path.isfile(self.dictGeometry["MaskFile"]): self.ERROR("Mask file %s does not exist " % self.dictGeometry["MaskFile"]) self.dictGeometry.pop("MaskFile") if self.xsDataInputSPD.getIntensityScaleFactor() is not None: self.dictGeometry[ "IntensityScaleFactor"] = self.xsDataInputSPD.getIntensityScaleFactor( ).getValue() if self.xsDataInputSPD.getDeleteCorImg() is not None: self.bDeleteCorImg = ( self.xsDataInputSPD.getDeleteCorImg().getValue() in ["1", 1, "true", "True", True]) if self.bDeleteCorImg: self.setFireAndForget(False) if self.xsDataInputSPD.getCorrectTiltMask() is not None: self.bCorrectTiltMask = bool( self.xsDataInputSPD.getCorrectTiltMask().getValue())
def unitTestGetValueTime(self): """ Test conversion in Time """ EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetValueTime") EDAssert.equal(60.0, EDUtilsUnit.getValue(EDUtilsUnit.toXSD(XSDataTime, "1 h"), "mn"), "Length Conversion h -> mn ")
def preProcess(self, _edObject=None): EDPluginExec.preProcess(self) self.DEBUG("EDPluginExecNormalizeImagev1_1.preProcess") sdi = self.getDataInput() if sdi.getData() == []: strError = "You should either provide at least ONE input filename or an array, you provided: %s" % sdi.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) else: for inputData in sdi.getData(): if inputData.exposureTime is None: self.WARNING("You did not provide an exposure time for DATA... using default: 1") self.listDataExposure.append(1.0) else: self.listDataExposure.append(EDUtilsUnit.getSIValue(inputData.exposureTime)) if inputData.path is not None: strPath = inputData.path.value if os.path.isfile(strPath): self.listDataArray.append(fabio.open(strPath).data) else: strError = "The input file provided for DATA is not a valid file: %s" % strPath self.ERROR(strError) self.setFailure() raise RuntimeError(strError) elif inputData.array is not None: self.listDataArray.append(EDUtilsArray.xsDataToArray(inputData.array)) else: strError = "You should either provide an input filename or an array for DATA, you provided: %s" % inputData.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) for inputFlat in sdi.getFlat(): if inputFlat.exposureTime is None: self.WARNING("You did not provide an exposure time for FLAT... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputFlat.exposureTime) self.listFlatExposure.append(expTime) if inputFlat.path is not None: strPath = inputFlat.path.value if os.path.isfile(strPath): self.listFlatArray.append(fabio.open(strPath).data) else: strError = "The input file provided for FLAT is not a valid file: %s" % strPath self.ERROR(strError) self.setFailure() raise RuntimeError(strError) elif inputFlat.array is not None: self.listFlatArray.append(EDUtilsArray.xsDataToArray(inputFlat.array)) else: strError = "You should either provide an input filename or an array for FLAT, you provided: %s" % inputFlat.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) with EDPluginExecNormalizeImagev1_1.semaphore: for inputDark in sdi.getDark(): if inputDark.exposureTime is None: self.WARNING("You did not provide an exposure time for Dark... using default: 1") expTime = 1.0 else: expTime = EDUtilsUnit.getSIValue(inputDark.exposureTime) strMeanDarkKey = "/".join((self.getClassName(), "MeanDark%6.3f" % expTime)) if strMeanDarkKey not in EDShare: self.listDarkExposure.append(expTime) if inputDark.path is not None: strPath = inputDark.path.value if os.path.isfile(strPath): self.listDarkArray.append(fabio.open(strPath).data) else: strError = "The input file provided for Dark is not a valid file: %s" % strPath self.ERROR(strError) self.setFailure() raise RuntimeError(strError) elif inputDark.array is not None: self.listDarkArray.append(EDUtilsArray.xsDataToArray(inputDark.array)) elif inputDark.shared is not None: self.listDarkArray.append(EDShare[inputDark.shared.value]) else: strError = "You should either provide an input filename or an array for Dark, you provided: %s" % inputDark.marshal() self.ERROR(strError) self.setFailure() raise RuntimeError(strError) if sdi.output is not None: if (sdi.output.path is not None): self.strOutputFilename = sdi.output.path.value elif (sdi.output.shared is not None): self.strOutputShared = sdi.output.shared.value # else export as array. EDAssert.equal(len(self.listDataArray), len(self.listDataExposure), _strComment="number of data images / exposure times ") EDAssert.equal(len(self.listFlatArray), len(self.listFlatExposure), _strComment="number of flat images / exposure times ") EDAssert.equal(len(self.listDarkArray), len(self.listDarkExposure), _strComment="number of dark images / exposure times ")
def doSuccessReadHeader(self, _edPlugin=None): EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_1.doSuccessReadHeader") self.retrieveSuccessMessages(_edPlugin, "EDPluginControlDiffractionCTv1_1.doSuccessReadHeader") # Translate dictionary to image and instrument objects xsDataInputPowderIntegration = XSDataInputPowderIntegration() self.xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument() self.xsDataDiffractionCTImage = XSDataDiffractionCTImage() xsDataDictionaryHeader = self.edPluginReadHeader.getDataOutput().getDictionary() for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair(): strKey = str(xsDataKeyValuePair.getKey().getValue()) lstValue = xsDataKeyValuePair.getValue().getValue().split() if len(lstValue) == 2: strValue = lstValue[0] strUnit = lstValue[1] else: strValue = xsDataKeyValuePair.getValue().getValue() strUnit = None if (strKey == "_diffrn_radiation_wavelength"): xsd = EDUtilsUnit.toXSD(XSDataWavelength, strValue) # if strUnit is None: strUnit = "A" # xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(xsd) elif (strKey == "_pd_instr_dist_spec/detc"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) # if strUnit is None: strUnit = "mm" # xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(xsd) elif (strKey == "_pd_meas_2theta_range_max"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(xsd) elif (strKey == "_pd_meas_2theta_range_min"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(xsd) elif (strKey == "_pd_meas_2theta_range_inc"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(xsd) elif (strKey == "_synchrotron_photon-flux"): self.xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(XSDataFlux(float(strValue))) elif (strKey == "_synchrotron_ring-intensity"): self.xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(XSDataDouble(float(strValue))) elif (strKey == "_tomo_scan_ampl"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_scan_ampl(xsd) elif (strKey == "_tomo_scan_type"): self.xsDataDiffractionCTInstrument.set_tomo_scan_type(XSDataString(strValue)) elif (strKey == "_tomo_spec_displ_rotation"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(xsd) elif (strKey == "_tomo_spec_displ_rotation_inc"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(xsd) elif (strKey == "_tomo_spec_displ_x"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) # if strUnit is None: strUnit = "mm" # xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(xsd) elif (strKey == "_tomo_spec_displ_x_inc"): xsd = EDUtilsUnit.toXSD(XSDataLength, strValue) # if strUnit is None: strUnit = "mm" # xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(xsd) elif (strKey == "_tomo_spec_displ_x_max"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(xsd) elif (strKey == "_tomo_spec_displ_x_min"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(xsd) elif (strKey == "_tomo_spec_displ_z"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(xsd) elif (strKey == "_tomo_spec_displ_z_inc"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(xsd) elif (strKey == "_tomo_spec_displ_z_max"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(xsd) elif (strKey == "_tomo_spec_displ_z_min"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(xsd) elif (strKey == "_pd_instr_special_details_tilt_angle"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(xsd) elif (strKey == "_pd_instr_special_details_tilt_rotation"): xsd = XSDataAngle(float(strValue)) if strUnit is None: strUnit = "deg" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(xsd) elif (strKey == "_array_element_size[1]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "m" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_array_element_size_1(xsd) elif (strKey == "_array_element_size[2]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "m" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_array_element_size_2(xsd) elif (strKey == "_diffrn_detector_element.center[1]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(xsd) elif (strKey == "_diffrn_detector_element.center[2]"): xsd = XSDataLength(float(strValue)) if strUnit is None: strUnit = "mm" xsd.setUnit(XSDataString(strUnit)) self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(xsd) # elif strKey.startswith("_pd_sum_2theta_range_max"): # if strKey.find("[") > 0: # pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between [] # else: # pyintIndex = 0 # while len(self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()) < pyintIndex + 1: # self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max().append(None) # xsd = XSDataAngle(float(strValue)) # if strUnit is None: strUnit = "deg" # xsd.setUnit(XSDataString(strUnit)) # self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()[pyintIndex] = xsd # elif strKey.startswith("_pd_sum_2theta_range_min"): # if strKey.find("[") > 0: # pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between [] # else: # pyintIndex = 0 # while len(self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()) < pyintIndex + 1: # self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min().append(None) # xsd = XSDataAngle(float(strValue)) # if strUnit is None: strUnit = "deg" # xsd.setUnit(XSDataString(strUnit)) # self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()[pyintIndex] = xsd elif (strKey == "_file_correction_image_dark-current"): xsDataFileDark = XSDataFile() xsDataFileDark.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_dark_current(xsDataFileDark) elif (strKey == "_file_correction_image_flat-field"): xsDataFileFlat = XSDataFile() xsDataFileFlat.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_flat_field(xsDataFileFlat) elif (strKey == "_file_correction_image-mask"): xsDataFileMask = XSDataFile() xsDataFileMask.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_image_mask(xsDataFileMask) elif (strKey == "_file_correction_spline_spatial-distortion"): xsDataFileSpatialDist = XSDataFile() xsDataFileSpatialDist.setPath(XSDataString(strValue)) self.xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(xsDataFileSpatialDist) if self.xsdForceImageParam is not None: self.forceImageParam(self.xsdForceImageParam) if self.xsdForceScanParam is not None: self.forceScanParam(self.xsdForceScanParam) xsDataInputPowderIntegration.setImageParameters(self.xsDataDiffractionCTImage) xsDataInputPowderIntegration.setInstrumentParameters(self.xsDataDiffractionCTInstrument) xsDataInputPowderIntegration.setImageFile(self.xsDataFileInputImage) # Set the destination directory for output XRPD file strDestinationDirectory = os.path.join(self.getDataInput().getDestinationDirectory().getPath().getValue(), \ self.getDataInput().getPowderDiffractionSubdirectory().getValue()) if self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() in ["flat", "spiral"]: pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation_inc().getValue()) elif self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() == "mapping": #I agree mappings are not sinograms but the really looks like, no ? pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z().getValue() - self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_min().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_inc().getValue()) else: pyintLineNumber = None try: strDestinationDirectory = "%s%04i" % (strDestinationDirectory, pyintLineNumber) except TypeError: pass #if pyintLineNumber is none: do not add suffix xsDataInputPowderIntegration.setDestinationDir(XSDataFile(XSDataString(strDestinationDirectory))) self.edPluginPowderIntegration.setDataInput(xsDataInputPowderIntegration) self.edPluginPowderIntegration.executeSynchronous()