本文整理汇总了Python中EDUtilsUnit.EDUtilsUnit类的典型用法代码示例。如果您正苦于以下问题:Python EDUtilsUnit类的具体用法?Python EDUtilsUnit怎么用?Python EDUtilsUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EDUtilsUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preProcess
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
示例2: preProcess
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 ")
示例3: unitTestGetSIValue
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")
示例4: getDetector
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
示例5: getInputParameter
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())
示例6: preProcess
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
示例7: integrate
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
示例8: unitTestToXSD
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")
示例9: unitTestGetValueLength
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 ")
示例10: unitTestGetValueSITime
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 ")
示例11: unitTestGetValueSIAngle
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 ")
示例12: unitTestGetValueSILength
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 ")
示例13: preProcess
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
示例14: unitTestGetValueTime
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 ")
示例15: unitTestGetValueAngle
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 ")