예제 #1
0
 def testCheckParameters(self):
     edPluginSPD = self.createPlugin()
     edStringXMLInput = EDUtilsTest.readAndParseFile(
         self.m_edStringReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(edStringXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.checkParameters()
    def testSpatialDistortion(self):
        strRefX = "spline-3-18x.edf"
        strRefY = "spline-3-18y.edf"
        self.loadTestImage([strRefX, strRefY])
        edPluginSPD = self.createPlugin()
        strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName)
        xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
        edPluginSPD.setDataInput(xsDataInputSPDCake)
        edPluginSPD.configure()
        edPluginSPD.getInputParameter()
        ########################################################################
        # Enforce some values
        ########################################################################
        edPluginSPD.dictGeometry["SpatialDistortionFile"] = os.path.join(self.getTestsDataImagesHome(), "frelon_spline_file_to_correct_SPD.spline")
        edPluginSPD.dictGeometry["TiltRotation"] = 18
        edPluginSPD.dictGeometry["AngleOfTilt"] = 3
        spline = Spline()
        spline.read(edPluginSPD.dictGeometry["SpatialDistortionFile"])
        edPluginSPD.dictGeometry["PixelSizeX"], edPluginSPD.dictGeometry["PixelSizeY"] = spline.getPixelSize()
        edPluginSPD.createDisplacementMatrix(spline)
        edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())

        refX = fabio.openimage.openimage(os.path.join(self.getTestsDataImagesHome(), strRefX)).data
        obtX = fabio.openimage.openimage(os.path.join(edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-x.edf")).data
        refY = fabio.openimage.openimage(os.path.join(self.getTestsDataImagesHome(), strRefY)).data
        obtY = fabio.openimage.openimage(os.path.join(edPluginSPD.getWorkingDirectory(), "frelon_spline_file_to_correct_SPD-tilted-y.edf")).data

#        print edPluginSPD.dictGeometry
        EDAssert.arraySimilar(obtX, refX , _fAbsMaxDelta=0.1, _strComment="X displacement Matrix is the same")
        EDAssert.arraySimilar(obtY, refY , _fAbsMaxDelta=0.1, _strComment="Y displacement Matrix is the same")
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
          edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
 def testPopulateXSDataInputSPDCake(self):
     edPluginControlID11 = self.createPlugin()
     xsDataInputSPDCake = edPluginControlID11.populateXSDataInputSPDCake(self.dictID11Reference)
     strDataPath = self.getPluginTestsDataHome()
     strReferenceFile = "XSDataInputSPDCake_fromDict.xml"
     strPath = os.path.join(strDataPath, strReferenceFile)
     xsDataInputSPDCakeReference = XSDataInputSPDCake.parseString(self.readAndParseFile(strPath))
     xsDataInputSPDCakeReference.setDeleteCorImg(XSDataBoolean(not (EDVerbose.isVerboseDebug())))
     EDAssert.equal(xsDataInputSPDCakeReference.marshal(), xsDataInputSPDCake.marshal())
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsTest.readAndParseFile(self.strReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
          edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
예제 #6
0
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(
         self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     if EDVerbose.isVerboseDebug():
         edPluginSPD.cleanDispMat(edPluginSPD.getWorkingDirectory())
     else:
         edPluginSPD.cleanDispMat()
 def testPopulateXSDataInputSPDCake(self):
     edPluginControlID11 = self.createPlugin()
     xsDataInputSPDCake = edPluginControlID11.populateXSDataInputSPDCake(
         self.dictID11Reference)
     strDataPath = self.getPluginTestsDataHome()
     strReferenceFile = "XSDataInputSPDCake_fromDict.xml"
     strPath = os.path.join(strDataPath, strReferenceFile)
     xsDataInputSPDCakeReference = XSDataInputSPDCake.parseString(
         self.readAndParseFile(strPath))
     xsDataInputSPDCakeReference.setDeleteCorImg(
         XSDataBoolean(not (EDVerbose.isVerboseDebug())))
     EDAssert.equal(xsDataInputSPDCakeReference.marshal(),
                    xsDataInputSPDCake.marshal())
예제 #8
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(
                self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile(
        ).getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(
                    strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile] = (
                        self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(
                self.__strControlledPluginWait)
            self.synchronizeOff()
            #            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int
            self.__xsDataInputWaitMultipleFile.setExpectedSize(
                XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) *
                              int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(
                self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" %
                       strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()
 def testGenerateSPDCommand(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.configure()
     edPluginSPD.getInputParameter()
     #edPluginSPD.preProcess()
     edPluginSPD.generateSPDCommand()
     EDVerbose.screen("SPD configuration:\n%s" % edPluginSPD.getSPDConfig())
     if EDVerbose.isVerboseDebug():
         expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #"do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     else:
         expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
예제 #10
0
 def testGenerateSPDCommand(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(
         self.strReferenceInputFileName, EDUtilsPath.getDictOfPaths())
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.configure()
     edPluginSPD.getInputParameter()
     #edPluginSPD.preProcess()
     edPluginSPD.generateSPDCommand()
     EDVerbose.screen("SPD configuration:\n%s" % edPluginSPD.getSPDConfig())
     if EDVerbose.isVerboseDebug():
         expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #"do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     else:
         expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0"""
         #do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf cor_ext=.cor wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0"
     EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
    def testGenerateSPDCommand(self):
        edPluginSPD = self.createPlugin()
        edStringXMLInput = EDUtilsTest.readAndParseFile(self.m_edStringReferenceInputFileName)
        xsDataInputSPDCake = XSDataInputSPDCake.parseString(edStringXMLInput)
        edPluginSPD.setDataInput(xsDataInputSPDCake)
        edPluginSPD.configure()
        edPluginSPD.getInputParameter()
        #edPluginSPD.preProcess()
        edPluginSPD.generateSPDCommand()
        EDVerbose.screen("SPD configuration:\n %s" % edPluginSPD.getSPDConfig())
        if EDVerbose.isVerboseDebug():
            expected = """off_1=0 off_2=0 verbose=2 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
#            """do_distortion=2 off_1=0 off_2=0  verbose=2 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
        else:
            expected = """off_1=0 off_2=0 verbose=0 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_distortion=0 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""
#            """do_distortion=2 off_1=0 off_2=0  verbose=0 src_ext=.edf wvl=1.000000e-10 cen_1=1.050000e+03 cen_2=1.000000e+03 dis=1.000000e-01 pix_1=4.722440e-05 pix_2=4.683150e-05 do_dark=0 cor_ext=.cor azim_int=1 azim_pass=0 azim_ext=.cor azim_r_num=1489"""

        EDAssert.equal(edPluginSPD.getSPDConfig(), expected)
예제 #12
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile().getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile] = (self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(self.__strControlledPluginWait)
            self.synchronizeOff()
#            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int 
            self.__xsDataInputWaitMultipleFile.setExpectedSize(XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) * int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" % strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()
예제 #13
0
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 testKillAllWorkers(self):
     edPluginSPD = self.createPlugin()
     edStringXMLInput = EDUtilsTest.readAndParseFile(self.m_edStringReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(edStringXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.killAllWorkers()
 def testCleanDispMat(self):
     edPluginSPD = self.createPlugin()
     edStringXMLInput = EDUtilsTest.readAndParseFile(self.m_edStringReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(edStringXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.cleanDispMat()
 def testKillAllWorkers(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.killAllWorkers()
예제 #17
0
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 testCheckParameters(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsFile.readFileAndParseVariables(self.strReferenceInputFileName, {"${EDNA_TESTIMAGES}":"toto"})
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.checkParameters()
 def testCheckParameters(self):
     edPluginSPD = self.createPlugin()
     strXMLInput = EDUtilsTest.readAndParseFile(self.strReferenceInputFileName)
     xsDataInputSPDCake = XSDataInputSPDCake.parseString(strXMLInput)
     edPluginSPD.setDataInput(xsDataInputSPDCake)
     edPluginSPD.checkParameters()
예제 #20
0
    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
예제 #21
0
    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
예제 #22
0
    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