예제 #1
0
 def preProcess(self, _edObject=None):
     """
     Preprocess methods for the EDPluginSPDCakev1_5 :
     - tilts the mask if needed 
     """
     EDPluginSPDCorrectv10.preProcess(self, _edObject)
     self.DEBUG("EDPluginSPDCakev1_5.preProcess")
     if ("MaskFile" in self.dictGeometry) and  (self.dictGeometry["MaskFile"] not in EDPluginSPDCakev1_5.__dictMask):
         self.correctMask()
예제 #2
0
 def __init__(self):
     """
     Constructor of the plugin: just do some simple initialization 
     """
     self.bDeleteCorImg = False
     EDPluginSPDCorrectv10.__init__(self)
     if self.getClassName() == "EDPluginSPDCakev1_5":
         self.setXSDataInputClass(XSDataInputSPDCake)
     self.bCorrectTiltMask = False
예제 #3
0
 def __init__(self):
     """
     Constructor of the plugin: just do some simple initialization 
     """
     self.bDeleteCorImg = False
     EDPluginSPDCorrectv10.__init__(self)
     if self.getClassName() == "EDPluginSPDCakev1_5":
         self.setXSDataInputClass(XSDataInputSPDCake)
     self.bCorrectTiltMask = False
예제 #4
0
 def preProcess(self, _edObject=None):
     """
     Preprocess methods for the EDPluginSPDCakev1_5 :
     - tilts the mask if needed 
     """
     EDPluginSPDCorrectv10.preProcess(self, _edObject)
     self.DEBUG("EDPluginSPDCakev1_5.preProcess")
     if ("MaskFile" in self.dictGeometry) and (
             self.dictGeometry["MaskFile"]
             not in EDPluginSPDCakev1_5.__dictMask):
         self.correctMask()
예제 #5
0
    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
0
    def generateSPDCommand(self):
        """
        This method creates the SPD command line for image correction.
        """
        EDPluginSPDCorrectv10.generateSPDCommand(self)
        self.DEBUG("EDPluginSPDCackev1_5.generateSPDCommand")
        lstCmdLineOption = [self.getSPDConfig()]
        lstCmdLineOption.append("cor_ext=.cor azim_int=1 azim_pass=0")
        if self.dictGeometry.has_key("OutputFileType") and (self.getClassName() == "EDPluginSPDCakev1_5"):
            if self.dictGeometry["OutputFileType"].startswith("."):
                lstCmdLineOption.append("azim_ext=%s" % self.dictGeometry["OutputFileType"])
            else:
                lstCmdLineOption.append("azim_ext=.%s" % self.dictGeometry["OutputFileType"])
        pixelSize = min(self.dictGeometry["PixelSizeX"], self.dictGeometry["PixelSizeY"])
        if "InnerRadius" in self.dictGeometry:
            lstCmdLineOption.append("azim_r0=%s" % (self.dictGeometry["InnerRadius"] * pixelSize))
        if "OuterRadius" in self.dictGeometry:
            lstCmdLineOption.append("azim_r_num=%s" % ((self.dictGeometry["OuterRadius"] - self.dictGeometry["InnerRadius"])))
        else:
            if ("BeamCenterX" in self.dictGeometry) and\
               ("BeamCenterY" in self.dictGeometry) and\
               ("BufferSizeX" in self.dictGeometry) and\
               ("BufferSizeY" in self.dictGeometry) and\
               ("PixelSizeX" in self.dictGeometry) and\
               ("PixelSizeY" in self.dictGeometry):
                maxXdist = max(abs(self.dictGeometry["BeamCenterX"]), abs(self.dictGeometry["BufferSizeX"] - self.dictGeometry["BeamCenterX"])) * self.dictGeometry["PixelSizeX"]
                maxYdist = max(abs(self.dictGeometry["BeamCenterY"]), abs(self.dictGeometry["BufferSizeY"] - self.dictGeometry["BeamCenterY"])) * self.dictGeometry["PixelSizeY"]
                MaxRadius = int(math.sqrt(maxXdist ** 2 + maxYdist ** 2) / min(self.dictGeometry["PixelSizeX"], self.dictGeometry["PixelSizeY"]))
                lstCmdLineOption.append("azim_r_num=%s" % MaxRadius)

        if "StartAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_a0=%s" % self.dictGeometry["StartAzimuth"])
        if "StepAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_da=%s" % self.dictGeometry["StepAzimuth"])
        if "StopAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_a_num=%s" % int(round((self.dictGeometry["StopAzimuth"] - self.dictGeometry["StartAzimuth"]) / self.dictGeometry["StepAzimuth"])))
        if "MaskFile" in self.dictGeometry:
            if self.dictGeometry["MaskFile"] in EDPluginSPDCakev1_5.__dictMask:
                lstCmdLineOption.append('mask_file=%s' % os.path.abspath(EDPluginSPDCakev1_5.__dictMask[self.dictGeometry["MaskFile"]]))
            else:
                lstCmdLineOption.append('mask_file=%s' % os.path.abspath(self.dictGeometry["MaskFile"]))
        if "IntensityScaleFactor" in self.dictGeometry:
            lstCmdLineOption.append("ave_scf=%s" % self.dictGeometry["IntensityScaleFactor"])
        strCmdLineOption = " ".join(lstCmdLineOption)
        self.DEBUG("SPD Command line:\n" + strCmdLineOption)
        self.setSPDConfig(strCmdLineOption)
예제 #7
0
    def generateSPDCommand(self):
        """
        This method creates the SPD command line for image correction.
        """
        EDPluginSPDCorrectv10.generateSPDCommand(self)
        self.DEBUG("EDPluginSPDCackev1_5.generateSPDCommand")
        lstCmdLineOption = [self.getSPDConfig()]
        lstCmdLineOption.append("cor_ext=.cor azim_int=1 azim_pass=0")
        if self.dictGeometry.has_key("OutputFileType") and (
                self.getClassName() == "EDPluginSPDCakev1_5"):
            if self.dictGeometry["OutputFileType"].startswith("."):
                lstCmdLineOption.append("azim_ext=%s" %
                                        self.dictGeometry["OutputFileType"])
            else:
                lstCmdLineOption.append("azim_ext=.%s" %
                                        self.dictGeometry["OutputFileType"])
        pixelSize = min(self.dictGeometry["PixelSizeX"],
                        self.dictGeometry["PixelSizeY"])
        if "InnerRadius" in self.dictGeometry:
            lstCmdLineOption.append(
                "azim_r0=%s" % (self.dictGeometry["InnerRadius"] * pixelSize))
        if "OuterRadius" in self.dictGeometry:
            lstCmdLineOption.append("azim_r_num=%s" %
                                    ((self.dictGeometry["OuterRadius"] -
                                      self.dictGeometry["InnerRadius"])))
        else:
            if ("BeamCenterX" in self.dictGeometry) and\
               ("BeamCenterY" in self.dictGeometry) and\
               ("BufferSizeX" in self.dictGeometry) and\
               ("BufferSizeY" in self.dictGeometry) and\
               ("PixelSizeX" in self.dictGeometry) and\
               ("PixelSizeY" in self.dictGeometry):
                maxXdist = max(
                    abs(self.dictGeometry["BeamCenterX"]),
                    abs(self.dictGeometry["BufferSizeX"] -
                        self.dictGeometry["BeamCenterX"])
                ) * self.dictGeometry["PixelSizeX"]
                maxYdist = max(
                    abs(self.dictGeometry["BeamCenterY"]),
                    abs(self.dictGeometry["BufferSizeY"] -
                        self.dictGeometry["BeamCenterY"])
                ) * self.dictGeometry["PixelSizeY"]
                MaxRadius = int(
                    math.sqrt(maxXdist**2 + maxYdist**2) /
                    min(self.dictGeometry["PixelSizeX"],
                        self.dictGeometry["PixelSizeY"]))
                lstCmdLineOption.append("azim_r_num=%s" % MaxRadius)

        if "StartAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_a0=%s" %
                                    self.dictGeometry["StartAzimuth"])
        if "StepAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_da=%s" %
                                    self.dictGeometry["StepAzimuth"])
        if "StopAzimuth" in self.dictGeometry:
            lstCmdLineOption.append("azim_a_num=%s" % int(
                round((self.dictGeometry["StopAzimuth"] -
                       self.dictGeometry["StartAzimuth"]) /
                      self.dictGeometry["StepAzimuth"])))
        if "MaskFile" in self.dictGeometry:
            if self.dictGeometry["MaskFile"] in EDPluginSPDCakev1_5.__dictMask:
                lstCmdLineOption.append(
                    'mask_file=%s' %
                    os.path.abspath(EDPluginSPDCakev1_5.__dictMask[
                        self.dictGeometry["MaskFile"]]))
            else:
                lstCmdLineOption.append(
                    'mask_file=%s' %
                    os.path.abspath(self.dictGeometry["MaskFile"]))
        if "IntensityScaleFactor" in self.dictGeometry:
            lstCmdLineOption.append("ave_scf=%s" %
                                    self.dictGeometry["IntensityScaleFactor"])
        strCmdLineOption = " ".join(lstCmdLineOption)
        self.DEBUG("SPD Command line:\n" + strCmdLineOption)
        self.setSPDConfig(strCmdLineOption)
예제 #8
0
    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())
예제 #9
0
    def postProcess(self, _edObject=None):
        """
        postProcess of the plugin EDPluginSPDCakev1_5.py:
        - convert to HDF if needed (to be implemented)
        - convert to chiplot or xye or cif if needed
        - move images (if needed) or delete .cor image 
        - set result XML   
        """
        EDPluginSPDCorrectv10.postProcess(self)
        self.DEBUG("EDPluginSPDCakev1_5.postProcess")

        if not os.path.isdir(self.dictGeometry["OutputDirCake"]):
            os.makedirs(self.dictGeometry["OutputDirCake"])

        strInputImagePathNoSfx = os.path.splitext(
            os.path.basename(self.pathToInputFile))[0]
        strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry[
            "OutputFileType"]

        strOutputCakeFilePath = os.path.join(
            self.dictGeometry["OutputDirCake"], strSpdoutCake)
        xsDataResultSPD = XSDataResultSPDCake()

        if not self.getFireAndForget():
            strTempFilePath = None
            if "corrected" in self.dictRes:
                strSpdoutCor = self.dictRes["corrected"]
            if "regrouped" in self.dictRes:
                strTempFilePath = self.dictRes["regrouped"]

            if self.dictGeometry["OutputFileType"].lower() in [
                    ".hdf5", ".nexus", ".h5", ".nx"
            ]:
                self.WARNING(
                    "HDF5/Nexus output is not yet implemented in the SPD plugin."
                )

            if strTempFilePath is None:
                self.WARNING(
                    "Cannot copy output to %s as there is not input: %s " %
                    (strOutputCakeFilePath, self.dictRes))
            elif os.path.exists(strOutputCakeFilePath):
                self.WARNING(
                    "Destination file exists, I will leave result file in %s."
                    % strTempFilePath)
                strOutputCakeFilePath = strTempFilePath
            else:
                shutil.move(strTempFilePath, strOutputCakeFilePath)

            strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"],
                                                os.path.split(strSpdoutCor)[1])
            if self.bDeleteCorImg:
                if os.path.isfile(strSpdoutCor):
                    os.remove(strSpdoutCor)
                else:
                    self.WARNING("Corrected file vanished before removal %s" %
                                 strSpdoutCor)
            else:
                strTempFilePathCor = os.path.join(self.getWorkingDirectory(),
                                                  strSpdoutCor)
                if self.dictGeometry["OutputFileType"].lower() in [
                        ".hdf5", ".nexus", ".h5", ".nx"
                ]:
                    self.WARNING(
                        "HDF5/Nexus output is not yet implemented in the SPD plugin."
                    )
                elif self.dictGeometry["OutputFileType"].lower() not in [
                        ".edf", ".azim", ".cor"
                ]:
                    self.WARNING(
                        "Output file format %s is not yet implemented in the SPD plugin."
                        % self.dictGeometry["OutputFileType"])

                if os.path.exists(strOutputCorFilePath):
                    self.WARNING(
                        "Destination file exists, I will leave result file in %s."
                        % strTempFilePathCor)
                    strOutputCorFilePath = os.path.abspath(strTempFilePathCor)
                else:

                    shutil.move(strTempFilePath, strOutputCorFilePath)
                xsDataFileCorr = XSDataFile()
                xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath))
                xsDataResultSPD.setcorrectedFile(xsDataFileCorr)
#        # Create the output data
        xsDataFileCake = XSDataFile()
        xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath))
        xsDataResultSPD.setCakedFile(xsDataFileCake)

        self.setDataOutput(xsDataResultSPD)
예제 #10
0
    def postProcess(self, _edObject=None):
        """
        postProcess of the plugin EDPluginSPDCakev1_5.py:
        - convert to HDF if needed (to be implemented)
        - convert to chiplot or xye or cif if needed
        - move images (if needed) or delete .cor image 
        - set result XML   
        """
        EDPluginSPDCorrectv10.postProcess(self)
        self.DEBUG("EDPluginSPDCakev1_5.postProcess")

        if not os.path.isdir(self.dictGeometry["OutputDirCake"]):
            os.makedirs(self.dictGeometry["OutputDirCake"])



        strInputImagePathNoSfx = os.path.splitext(os.path.basename(self.pathToInputFile))[0]
        strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry["OutputFileType"]

        strOutputCakeFilePath = os.path.join(self.dictGeometry["OutputDirCake"], strSpdoutCake)
        xsDataResultSPD = XSDataResultSPDCake()


        if not self.getFireAndForget():
            strTempFilePath = None
            if "corrected" in self.dictRes:
                strSpdoutCor = self.dictRes["corrected"]
            if "regrouped" in self.dictRes:
                strTempFilePath = self.dictRes["regrouped"]

            if self.dictGeometry["OutputFileType"].lower() in [".hdf5", ".nexus", ".h5", ".nx"]:
                self.WARNING("HDF5/Nexus output is not yet implemented in the SPD plugin.")

            if strTempFilePath is None:
                self.WARNING("Cannot copy output to %s as there is not input: %s " % (strOutputCakeFilePath, self.dictRes))
            elif os.path.exists(strOutputCakeFilePath):
                self.WARNING("Destination file exists, I will leave result file in %s." % strTempFilePath)
                strOutputCakeFilePath = strTempFilePath
            else:
                shutil.move(strTempFilePath, strOutputCakeFilePath)

            strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"], os.path.split(strSpdoutCor)[1])
            if self.bDeleteCorImg:
                if os.path.isfile(strSpdoutCor):
                    os.remove(strSpdoutCor)
                else:
                    self.WARNING("Corrected file vanished before removal %s" % strSpdoutCor)
            else:
                strTempFilePathCor = os.path.join(self.getWorkingDirectory(), strSpdoutCor)
                if self.dictGeometry["OutputFileType"].lower() in [".hdf5", ".nexus", ".h5", ".nx"]:
                    self.WARNING("HDF5/Nexus output is not yet implemented in the SPD plugin.")
                elif self.dictGeometry["OutputFileType"].lower() not in [".edf", ".azim", ".cor"] :
                    self.WARNING("Output file format %s is not yet implemented in the SPD plugin." % self.dictGeometry["OutputFileType"])

                if os.path.exists(strOutputCorFilePath):
                    self.WARNING("Destination file exists, I will leave result file in %s." % strTempFilePathCor)
                    strOutputCorFilePath = os.path.abspath(strTempFilePathCor)
                else:

                    shutil.move(strTempFilePath, strOutputCorFilePath)
                xsDataFileCorr = XSDataFile()
                xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath))
                xsDataResultSPD.setcorrectedFile(xsDataFileCorr)
#        # Create the output data
        xsDataFileCake = XSDataFile()
        xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath))
        xsDataResultSPD.setCakedFile(xsDataFileCake)

        self.setDataOutput(xsDataResultSPD)